Please write the following in C++ code. DO NOT USE ANYTHING OTHER THAN AND !! ONLY ALSO START THE PROGRAM WITH int main(void)! Please do not put anything before that! Thank you!
2 Polynomial Root Calculation: Problem Description (25 points) Engineers often need to calculate the roots of a given polynomial. For low-order polynomials, these computations can be done by hand. For higher-order polynomials, these calculations can be cumbersome, if not impossible, without a computer. One method of finding real roots of a polynomial is the Newton-Raphson algorithm We wish to write a C program that uses the Newton-Raphson method for calculating the roots of a polynomial Although this program will not be able to solve for complex roots, it will be able to calculate real roots; maybe later we can adjust the routine to include complex roots. Since is possible that the polynomial roots are al complex i.e. no real roots at all may be that the Newton-Raphson routine fails to converge. 2.1 Newton-Raphson Algorithm: Write a program that prompts the user to inpu the coefficients co, ci, , c5 of a 5th-order polynomial and an initial valuc r that serves as a the starting condition for the Newton-Raphson algorithm The 5th-order polynomial has the form We know that the first derivative of y with respect to r is lg dar We can use this information to find as follows: the rooks of the polynomial. The basic idea, in the Newton-Raphson method, is (a) Given an initial guess , and polynomial coefficients e, calculate y (b) Check to see if y is close enough to zero, i.e. within some small tolerance close to zero. i) If so then terminate. Algorithm has converged! (ii) If not then continue (c) Use the current value of r to calculate y (d) Create a new guess for a using the update formula - e) Increment a counter to count the number of algorithm iterations (f) Check to see if the number of iterations has exceeded a predetermined count limit (say 500) (i) If so then terminate. Algorithm has failed! ii) If not then return to step a This same information is described in the flow chart below: Prompt user for inputs Use current value of r to calculate y yes Is y close to zero? Use current value of x to calculate y Update r Report success Increment a counter of the Display x as one of the roots to keep track of the number of iterations Is count too large? no yes Report failure Stop If a solution is not found within 500 iterations then terminate your code and report failure. Failure to converge occurs if the polynomial roots are all complex; for example, if the user enters C5 = 0,C4 = 0,C3 = 0-2 = 1, q = 2, co = 3. These coefficients equate to a second order polynonial y 12 + 2r t 3, with roots z -1 iV2 The search algorithm has converged when y(x)-0. Since y is a floating point variable it wi most likely never actually equal zero. Calculate the polynomial root with a tolerance of c