Write a program, in the language of your preference, that computes roots for polynomials. The program should take as input a file which contains description of a polynomial in the following format:
where is the degree of the polynomial, is the coefficient of the monomial of degree , and is the constant term. For example, the polynomial:
3x^3 + 5x^2 - 7
would be represented as:
3 5 0 -7
The file should have extension .pol, for example, fun1.pol would be a suitable name for a file. The program should use bisection method by default and should place the solution in a file with the same name as the input, but with extension .sol (such as fun1.sol), with format:
where is the last root approximation, is the total number of iterations performed by the algorithm, and should be one of if the algorithm reached convergence, or if the algorithm didn't converge.
For all algorithms, the error tolerance should be IEEE 754 single precision. You should implement the following algorithms:
· Bisection method.
· Newton's Method.
· Secant Method.
· Hybrid: starts with bisection for early iterations and switches to newton's.
The program should use bisection as default and operate as follows:
By default the program uses bisection, but this can be modified with -newt for Newton's or -sec for Secant. The program should attempt 10,000 iterations by default, but this can be modified with -maxIter and the number of desired iterations. The initial point is provided (or an extra point for bisection and secant). For example, to run bisection method on file fun1.pol, with initial points 0 and 1:
to run newton's with initial point 0:
and to run secant, with initial points 0 and 1, for 100,000 iterations:
Use your program to compute solutions for all polynomial functions depicted in the text of this assignment.
Get Free Quote!
308 Experts Online