Write a program that solves fifth-degree polynomial equations using Newton\'s me
ID: 3891398 • Letter: W
Question
Write a program that solves fifth-degree polynomial equations using Newton's method. Your program should accept coefficients for co, ci c2 C3, C4 and C5 It should then accept a use Newton's method to solve the equation guess value, and then should For example, when you run the program, it may look like this: Enter x"0 coefficient: -10 Enter x"1 coefficient: -3 Enter x"2 coefficient: 0 Enter x"3 coefficient: o Enter x"4 coefficient: 2 Enter x"5 coefficient: 1 Enter guess x0: 1.1 1.4287159979621487 This is because a solution of r+2-3 -10-0 is given by r1.4287159979621487. The Newton's method algorithm which discovers this solution is described below Newton's method is a method to approximate solutions to an equation f(a)-0 very quickly. It works by starting with a using the following process: and so on and so forth, with Zn+1 -f zn /f' z ) in general. For reasons that arebest explained by a textbook (or me, in person), z1 will usually be close to a solution, and ra will be closer, and zs closer still, etc. Time for an example: Let's try to solve 2-4x + 1-0. Here, f(z)-z2-4?+1, we start with a guess of ro-. Then zo -1: f(o)-2; /'(o)-2; and so
Explanation / Answer
Find the required program in python3:
#==========================================================
from numpy.polynomial.polynomial import polyval
print('Enter the coefficients of the polynomial for the powers of variable from 0 to 5: ');
cof=[]; # Empty list initialization
for i in range(0,6):
prompt='Enter x^'+i.__str__()+' coefficient: ';
cof.append(float(input(prompt)));
x0 = float(input('Please enter the initial guess: '));
# Creating coefficeint for differntial polynomial
diff_cof = [i*cof[i] for i in range(1,6)];
# We have utlizing polyval function from numpy
# which evaluates the polynomial (given by coefficient) at a point
for i in range(1,11):
x=x0-(polyval(x0,cof)/polyval(x0,diff_cof));
x0=x;
print('The resulted value is: ',x);
#============================================================
Sample output:
Enter the coefficients of the polynomial for the powers of variable from 0 to 5:
Enter x^0 coefficient: -10
Enter x^1 coefficient: -3
Enter x^2 coefficient: 0
Enter x^3 coefficient: 0
Enter x^4 coefficient: 2
Enter x^5 coefficient: 1
Please enter the initial guess: 1.1
The resulted value is: 1.4287159979621487
Hope this helps! If it works, please thumbs up!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.