In: Computer Science
PLEASE USE PYTHON CODE
7. Use Newton's method to find the polynomial that fits the following points:
x = -3, 2, -1, 3, 1
y = 0, 5, -4, 12, 0
NEWTON'S METHOD
GRAPHICAL INTERPRETATION :Let the given equation be f(x) = 0 and the initial approximation for the root is x0. Draw a tangent to the curve y = f(x) at x0 and extend the tangent until x-axis. Then the point of intersection of the tangent and the x-axis is the next approximation for the root of f(x) = 0. Repeat the procedure with x0 = x1until it converges. If m is the slope of the Tangent at the point x 0 and b is the angle between the tangent and x-axis then
|
||||||||||||
This can be generalized to the iterative process as
xi+1= xi - |
f(xi) |
i = 0, 1, 2, . . . |
f '(xi) |
||
Use Newton's method to find the polynomial that fits the following points:
x = -3, 2, -1, 3, 1
y = 0, 5, -4, 12, 0
y=ax4+bx3+cx2+dx+e
y=a(-3)4+b(-3)3+c(-3)2+d(-3)+e
y=-81a-27b+9c-3d+e=0 (first equation)
y= y=ax4+bx3+cx2+dx+e
y=a(2)4+b(2)3+c(2)2+d(2)+e
y=16a+8b+4c+2d+e=5 (second equation)
y=ax4+bx3+cx2+dx+e
y=a(-1)4+b(-1)3+c(-1)2+d(-1)+e
y=a+b+c+d+e =-4 (third equation)
y=ax4+bx3+cx2+dx+e
y=a(3)4+b(3)3+c(3)2+d(3)+e
y=81a+27b+9c+3d+e=12 (fourth equation)
y=ax4+bx3+cx2+dx+e
y=a(1)4+b(1)3+c(1)2+d(1)+e
y=a+b+c+d+e=0 (fifth equation)
Python program to implement Newton’s method:
from scipy import misc
def NewtonsMethod(f, x, tolerance=0.000001):
while True:
x1 = x - f(x) / misc.derivative(f, x)
t = abs(x1 - x)
if t < tolerance:
break
x = x1
return x
def f(x):
return (1.0/4.0)*x**3+(3.0/4.0)*x**2-(3.0/2.0)*x-2
x = 4
x0 = NewtonsMethod(f, x)
print('x: ', x)
print('x0: ', x0)
print("f(x0) = ", ((1.0/4.0)*x0**3+(3.0/4.0)*x0**2-(3.0/2.0)*x0-2 ))