Let f(x) = ex for -1 le x le 1. Write a Matlab program that interpolates f at n
ID: 2979619 • Letter: L
Question
Let f(x) = ex for -1 le x le 1. Write a Matlab program that interpolates f at n + 1 points with a polynomial p of degree n or less, for each of the following cases. n + 1 evenly spaced points in the interval [-1, 1]. These interpolation points include the endpoints -1 and 1. The n + 1 Chebyshev points, which are the roots of the Chebyshev polynomial Tn+1 of degree n + 1. For each case, and for a given value of n, plot your results as follows. Use the subplot command in Matlab to create a 2 times 1 array of plots. In the upper frame, plot the function f as a solid curve, plot the interpolating polynomial p as a dashed curve, and also plot a small circle at each point on the graph of f where p interpolates f. In the lower frame, plot the error f - p. Execute your code for the values n = 1, n = 2, and n = 10. (You then produce six pages of plots, two for each value of n.) For each value of n, discuss which choice of interpolation points yields an error which comes closest to the "equioscillation property" that was discussed in class. Your discussion of this property should include a count of the number of extrema of f - p in the interval [-1, 1]. Remarks on Matlab usage Use the function polyfit to produce the interpolation polynomial. More precisely, if vectors x and y each have n+1 components, then the command coeffs = polyf it (x, y, n) produces the coefficients of the polynomial of degree n or less that interpolates the points having horizontal coordinates in vector x and vertical coordinates in vector y. The function polyval can then be used to compute values of that polynomial. More precisely, the command polyplot = polyval(coeffs, xplot); produces values of the polynomial at the horizontal coordinates specified in vector xplot. Use the results to plot the polynomial. When you construct the vector xplot, choose a spacing that is fine enough that the curve appears smooth. For information on how to plot solid curves, dashed curves, and circles at specified points, see the help item for Matlab's plot function. Now let f(x) = 1 / 1+25x2 for -1 le x le 1, and modify your code from Problem 1 so as to apply it to this function. Run the code for the case n = 10, and print the plots. (Note the difference in performance between evenly-spaced interpolation points and the Chebyshev points.) Feel free to experiment with other values of n. What to turn in Turn in hardcopy of your Matlab code and plots and your written discussion for Problem 1. Organize your papers so that everything for Problem 1 comes first, followed by everything for Problem 1. Staple.Explanation / Answer
Polynomial Interpolation
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.