Question
Consider the following function as a polynomial with a real variable, f(x)= ax^3+bx^2+cx+d.You are asked to write a program that locates all the roots of
Consider the following function as a polynomial with a real variable, f(x)= ax^3+bx^2+cx+d.You are asked to write a program that locates all the roots of this function using the Newton-Raphson method. The program must ask the user to input the polynomial coefficients a, b, c and d as well as the 1st, 2nd and 3rd initial guesses for the roots. a.
a.Write a Python function for f(x) with x, a, b, c and d as input arguments.
b. (5 points) Take the analytical derivative of f(x).
Write a Python function for the analytical derivative of f(x) with x, a, b and c as input arguments. c. (10 points) Write a Python function that approximately finds the 1st root, x(0), of f(x) with a, b, c, d and an initial guess as function input parameters such that abs(f(x(0)))<10-6 using the newton-raphson method. at each iteration of a while loop, code must print number, new guess and abs(f(x)) guess. loop iterations stop if abs(f(x))<10-6 ,>=106 or the maximum number of iterations, 50, is reached. After the iterations are completed, the function must return the last guess as the 1st root, x(0), if abs(f(x(0)))<10-6 at that guess. Otherwise, it must return None, meaning that no root was located. Please note that the iterative equation to locate the 1st root is the following: X(i+1) ? Xi ? (f(x)/f'(Xi) Please also note that this equation is used to locate the 1st root only when no root has been located.
d. (10 points) Write a Python function that approximately finds the 2nd root, x(1), of f(x) with a, b, c, d and an initial guess as function input parameters such that abs(f(x(1)))<10-6 using the newton-raphson method. at each iteration of a while loop, code must print number, new guess and abs(f(x)) guess. loop iterations stop if abs(f(x))<10-6 ,>=106 or the maximum number of iterations, 50, is reached. After the iterations are completed, the function must return the last guess as the 2nd root, x(1), if abs(f(x(1)))<10-6 at that guess. otherwise, it must return none, meaning no root was located. please note the iterative equation to locate 2nd is following and includes 1st root, x(0). x(i+1) ? xi (f(x)>
Please also note that this equation is used to locate the 2nd root only when one root, x(0), has been located to avoid convergence to x(0).
e. (10 points) Write a Python function that approximately finds the 3rd root, x(2), of f(x) with a, b, c, d and an initial guess as function input parameters such that abs(f(x(2)))<10-6 using the newton-raphson method. at each iteration of a while loop, code must print number, new guess and abs(f(x)) guess. loop iterations stop if abs(f(x))<10-6 ,>=106 or the maximum number of iterations, 50, is reached. After the iterations are completed, the function must return the last guess as the 3rd root, x(2), if abs(f(x(2)))<10-6 at that guess. otherwise, it must return none, meaning no root was located. please note the iterative equation to locate 3rd is following and includes 1st root, x(0), 2nd x(1). x(i+1) ? xi (f(x)>
f. Write a Python main program that approximately locates all real roots of f(x) by calling the functions developed in parts c-e above as needed. Please note that the number of the real roots of the polynomial defined above using the coefficients, a, b, c and d, will be between 0 and 3. It may not have any real root at all such as the polynomial, f(x)=x2 +1 (a=0, b=1, c=0 and d=1). The main program should have a list, which is initially empty and stores the roots as they are located by any function developed in parts c-e. It will not store any root returned by a function as None. Then, the main program should iterate a loop three times, and use the 1st, 2nd and 3rd initial guess in the first, second and third iterations, respectively, as an initial guess for one of the functions developed in parts c-e. At each iteration, only one of the functions developed in parts c-e will be called. The function called to locate a root will be based on how many roots have been located earlier. If no root has been located earlier, the function developed in part c must be called. If one root has been located earlier, the function developed in part d must be called. If two roots have been located earlier, the function developed in part e must be called. After the three iterations, the program must print the number of roots successfully located and their values.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started