Question: ( 5 ) You will write a Python code that generates and evaluates Newton's Divided Differences polynomials. This code should have two functions, with names

(5) You will write a Python code that generates and evaluates Newton's Divided Differences
polynomials. This code should have two functions, with names and inputs as shown
below. The first function calculates the coefficients and the second define and evaluates
the polynomial. Upload your code to a file named HW4_Question5.py
def divided_differences(node_x: np.ndarray, node_y: np.ndarray)
np.ndarray:
t
Calculates the coefficients of a Newton's Divided Difference
polynomial using
divided differences via the recurrence relation
:param node_x: x values for the nodes
:param node_y: y values for the nodes
:return: array of coefficients
def newtons polynomial (x data: np.ndarray, node x : np.ndarray, coeffs:
np.ndarray) np.ndarray:
"n"
Defines and evaluates the Newton's Divided Difference Polynomial
:param x data: x values of the data on which we will evaluate the
polynomial
:param node_x: x values for the nodes
:param coeffs: array of coefficients
return: polynomial evaluated on x data
"n"
(a) Generate a set of x and y values using the code below. These will be the nodes. Use
the code you wrote to generate a Newton's Divided Difference polynomial that fits to
these nodes, and evaluate that polynomial for 1000 values of x between 0 and 3.
Plot this polynomial evaluation and also plot the node points (using a scatter plot).
Upload this plot to a file named "HW4_Question5a_plot.png".
import numpy asnp
x=np*linspace(0,3**np*,10)
y=np*sin(x)
(b) Evaluate this polynomial for the value of x=3.2. What is the result and what is the
absolute error in this result?
 (5) You will write a Python code that generates and evaluates

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!