Homework 6 - Divided Differences
Due Date: November 7, 2023
Problems
Consider the following data \((x_j, y_j)\), \(j=0,1,2,3\):
\(x\) \(y\) -1 -1 0 0 3 -1 5 -3 Compute the divided-difference table associated to the given data.
Write out the interpolating polynomial \(P(x)\) of the given data in the divided-difference representation (but do not expand).
Compute \(P(2.0)\).
Now suppose that we add the new data point \((x_4, y_4) = (4, -2)\). What is the divided-difference table associated to the extended data points \((x_j, y_j)\) for \(j=0,1,2,3,4\)?
Compute \(P(2.0)\), where \(P\) is the interpolating polynomial for the extended data points.
Fill in the unknown entries in the divided-difference table given below:
0 1 2 3 \(x\) \(f[\cdot]\) \(f[\cdot,\cdot]\) \(f[\cdot, \cdot, \cdot]\) \(f[\cdot, \cdot, \cdot,\cdot]\) \(2\) \(f[x_0]\) \(\star\) \(\star\) \(\star\) \(3\) \(f[x_1]\) \(f[x_0, x_1]\) \(\star\) \(\star\) \(4\) \(-7\) \(4\) \(2\) \(\star\) \(5\) \(1\) \(f[x_2, x_3]\) \(f[x_1, x_2, x_3]\) \(f[x_0,x_1, x_2, x_3]\) Using your results, write out the interpolating polynomial in expanded form.
Write a Python function called
DividedDiff
whose inputs are Numpy arrays \(x=(x_0, x_1, \ldots, x_n)\) and \(y=(y_0, y_1, \ldots, y_n)\), and returns the divided-difference coefficients \(a=(a_0, a_1, \ldots, a_n)\) as a Numpy array. To test your function, try it with the data from Problem 1. Only include your code and not the results of your tests.Write a Python function called
DividedDiffInterp
whose inputs are Numpy arrays \(x=(x_0, x_1, \ldots, x_n)\), \(y=(y_0, y_1, \ldots, y_n)\), and \(u=(u_0, u_1, \ldots, u_N)\), and returns the array \(v=(v_0, v_1, \ldots, v_N)\), where \(v_i = P(u_i)\) and \(P\) is the interpolating polynomial for the \((x_j,y_j)\) data points. The polynomial \(P\) is to be evaluated using the divided-difference representation. Your function should first callDividedDiff
to compute the divided-difference coefficients \(a\) and then evaluate \(P\) using the divided-difference representation. To test your function, compare the results using yourLagrangeInterp
function on any given set of \(x, y\), and \(u\) data points (e.g., you could use the data from Homework 4 Problems 6 or 7, or the data from Problem 1 above). Only include your code and not the results of your tests.Consider the following data \[\begin{aligned} x &= (0, 1, 2, 3)\\ y &= (1,-1,-5,-17) \end{aligned}\] and let \(P(x)\) be the interpolating polynomial.
Compute the divided-difference representation of \(P(x)\) and then expand the polynomial in the form \[P(x) = c_3x^3 + c_2x^2 + c_1 x + c_0.\]
Compute the Lagrange form of \(P(x)\) and then expand the polynomial in the same form as in part (a).
Comment on what you obtained in parts (a) and (b).
Let \(f(x) = \cos(2\pi x)\) for \(x\in [0,1]\) and let \(x_0, x_1, \ldots, x_n\) be the Chebyshev nodes in \([0,1]\). Let \(u=(u_0, u_1, u_2, \ldots, u_N)\) be equally spaced points inside the interval \([0,1]\) where \(N=200\). Evaluate the interpolating polynomial \(P(x)\) for the data \((x_j, f(x_j))\) at the points \(u\) in two different ways:
Using your
LagrangeInterp
function.Using your newly created
DividedDiffInterp
function.
Then do the following:
Plot the error function \(|f(u) - P(u)|\) for each case (1) and (2) on the same plot. Do this for \(n=10\), \(n=40\), and \(n=90\) (or experiment with other values of \(n\)) but include only your plot for \(n=90\).
What happens to the error function for each case (1) and (2) as \(n\) increases?