I am having a problem with program i am trying to finish. This is kind of lengthy so I apologize ahead of time. Here is what the program is supposed to do:
We are restricting ourselves to polynomials that only contain nonnegative, integral powers of x. In this program, you will find the roots of a polynomial of arbitrary, nonnegative degree (the degree is specified by the user). The degree of a polynomial is the highest power of x with a nonzero coefficient. In the example above, the degree of the polynomial is 5.
You will use the secant method to locate a zero of a given polynomial. The secant method uses the following iterative (repeating/looping) equation to identify a zero of a function:
xi + 1 = xi - [f(xi)*(xi - 1 - xi)/(f(xi - 1) - f(xi))]
Thus, you need two starting values of x, x0 and x1, in order to generate subsequent values of x that get closer and closer to a zero for the function. The iterative formula requires that you use the result of the first computation as an input for the second computation. That is, x2 is computed from x1 and x0, while x3 is computed from x2 and x1, and so forth.
but the poly structure is not needed. that is kept in a class by itself that this program feeds into.
Javadoc for Program 1
Repeat the iterative process described above until:
the user specified number of iterations have been performed you have identified a zero within the tolerance 0.00001 If a zero was found within the specified tolerance, report the x-coordinate corresponding to that zero. If no zeroes were found within the specified tolerance, report that no zeroes were found. Call your file Secant.java. It is tempting to complete this entire program in the main method. I want you to write lots of short methods to get practice in creating, passing, and using objects. I will be grading you on how well you break the problem down into separate, short, static methods. To give you an idea of what I will be looking for, here are two sample method signatures that I expect you to implement and to use:
public static double secant(Poly poly, double x0, double x1, int iter) //returns the result of the secant method public static Poly getPoly(int degree) //user inputs the coefficients of the powers of x from 0 to degree
The parameters are as follows:
poly is your polynomial, x0 and x1 are the starting function values for the root finding (that is, evaluate your polynomial at these two points to get your search started), iter is the number of iterations requested, and degree is the highest power of x with a nonzero coefficient. Of course, you should have more methods than just these two.
Compare doubles to zero and to each other using a reasonable tolerance (use 0.00001). Format numerical output with the DecimalFormat class. Obtain needed input from the user using the Keyboard class. Use at least one while loop and one for loop.
Instantiation and use of pre-defined classes Poly Keyboard String DecimalFormat Use of expressions with attention to operator precedence arithmetic relational logical Use of loops while for Use of conditional statements if/else switch Object parameters Comparison of floating point numbers using a tolerance Creation and use of helper methods to simplify problem solving Program testing and discovery Program Documentation: Follow the documentation guidelines. You do not have to worry about item 2 for this program, however.
Surely the getPoly(int degree) method has to make use of the Keyboard class. What can the Keyboard class do? Hopefully it can prompt the user and read some strings. The strings can be parsed into floating point numbers and stored in a suitable data structure representing the degree+1 coefficients of the polynomial. [ September 25, 2005: Message edited by: Barry Gaunt ]