Question

In: Computer Science

PLEASE USE PYTHON CODE 7. Use Newton's method to find the polynomial that fits the following...

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

Solutions

Expert Solution

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

m = tan b = f '(x0 ) =

f(x0)

x 0-x1

(x0-x1) * f '(x0) = f(x0 )


x1 = x0   -

f(x0)

f '(x0)

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 ))

Related Solutions

Use Newton's method to find a solution for the equation in the given interval. Round your...
Use Newton's method to find a solution for the equation in the given interval. Round your answer to the nearest thousandths. ? 3 ? −? = −? + 4; [2, 3] [5 marks] Answer 2.680 Q6. Use the Taylor Polynomial of degree 4 for ln(1 − 4?)to approximate the value of ln(2). Answer: −4? − 8?2 − 64 3 ? 3 − [6 marks] Q7. Consider the curve defined by the equation 2(x2 + y2 ) 2 = 25(x2 −...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: g. def big_words(text, min_length=10): """ Return a list of big words whose length is at least min_length """ return [] h. def common_words(text, min_frequency=10): """ Return words occurring at...
Use Newton's method to find all solutions of the equation correct to eight decimal places. Start...
Use Newton's method to find all solutions of the equation correct to eight decimal places. Start by drawing a graph to find initial approximations. (Enter your answers as a comma-separated list.) 6e−x2 sin(x) = x2 − x + 1
Use Newton's method to find all solutions of the equation correct to eight decimal places. Start...
Use Newton's method to find all solutions of the equation correct to eight decimal places. Start by drawing a graph to find initial approximations. (Enter your answers as a comma-separated list.) −2x7 − 4x4 + 8x3 + 6 = 0
Use Newton's method to find all solutions of the equation correct to six decimal places. (Enter...
Use Newton's method to find all solutions of the equation correct to six decimal places. (Enter your answers as a comma-separated list.) sqrt(x + 1) = x^2 − x What does x equal?
Use Newton's method to find all solutions of the equation correct to eight decimal places. Start...
Use Newton's method to find all solutions of the equation correct to eight decimal places. Start by drawing a graph to find initial approximations. (Enter your answers as a comma-separated list.) 4e-x2 sin(x) = x2 − x + 1
Use Newton's method to find all real roots of the equation correct to six decimal places....
Use Newton's method to find all real roots of the equation correct to six decimal places. (Enter your answers as a comma-separated list.) 8/x = 1 + x^3
Please based on my python code. do the following steps: thank you Develop a method build_bst...
Please based on my python code. do the following steps: thank you Develop a method build_bst which takes a list of data (example: [6, 2, 4, 22, 34, 9, 6, 67, 42, 55, 70, 120, 99, 200]) and builds a binary search tree full of Node objects appropriately arranged. Test your build_bst with different sets of inputs similar to the example provided above. Show 3 different examples. Choose 1 example data.  Develop a function to remove a node from a bst...
Write a code to find the following in a text file (Letter). language: Python (a) Find...
Write a code to find the following in a text file (Letter). language: Python (a) Find the 20 most common words (b) How many unique words are used? (c) How many words are used at least 5 times? (d) Write the 200 most common words, and their counts, to a file. text file: Look in thy glass and tell the face thou viewest, Now is the time that face should form another, Whose fresh repair if now thou not renewest,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT