Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. (a) Use MATLAB to fit a polynomial of degree 12 to the Runge function 1 f(x) = 1 + x interpolating the function
4. (a) Use MATLAB to fit a polynomial of degree 12 to the Runge function 1 f(x) = 1 + x interpolating the function at 13 equally-spaced points between -5 and 5. (You can set the points with the command x = [-5:5/6:5];-) You may use the MATLAB routine polyfit to do this computation or you may use your own routine. (To find out how to use polyfit type help polyfit in MATLAB.) Plot the function and your 12th-degree interpolant on the same graph. You can evaluate the polynomial at points throughout the interval [-5, 5] using MATLAB's polyval routine, or you may write your own routine. Turn in your plot and a listing of your code. (b) Repeat part (a) with a polynomial of degree 12 that interpolates f at 13 scaled Chebyshev points, x = 5 cos j 12 j= 0,..., 12. Again you may use MATLAB's polyfit and polyval routines to fit the poly- nomial to the function at these points and evaluate the result at points throughout the interval, or you may use the barycentric interpolation for- mula (8.6) with weights defined by (8.5) or (8.16) to evaluate the interpo- lation polynomial at points other than the interpolation points in the inter- val [-5, 5]. Turn in your plot and a listing of your code. (c) If one attempts to fit a much higher-degree interpolation polynomial to the Runge function using MATLAB's polyfit routine, MATLAB will issue a warning that the problem is ill conditioned and answers may not be accu- rate. Still, the barycentric interpolation formula (8.6) with the special weights (8.16) for the values of a polynomial that interpolates f at the Chebyshev points may be used. Use this formula with 21 scaled Cheby- shev interpolation points, x = 5 cos ,j=0,..., 20, to compute a more accurate approximation to this function. Turn in a plot of the interpolation polynomial P20 (x) and the errors f (x)- P20 (x) over the interval [-5, 5]- (d) Download the chebfun package from the website http:// www2.maths.ox.ac.uk/chebfun/ and follow the directions there to install the package. Enter the Runge function into chebfun as in example 8.5.2: f=chebfun (1/(1+x.^2).[-5.5]) and then plot the result by typing plot (f). Also plot the actual Runge func- tion on the same graph. The two should be indistinguishable.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started