Question: function RungePheo(n) %% plot f(x)=1/(1+x^2) on [-5,5] ezplot('1/(1+x^2)',[-5 5]); hold on; %hold the graph. %% generate x_i=-5+(10)*i, stored in xd=[x0 x1 x2 ... xn] xd=[-5:(10):5];
![function RungePheo(n) %% plot f(x)=1/(1+x^2) on [-5,5] ezplot('1/(1+x^2)',[-5 5]); hold on;](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f5350681233_92666f535061eb7f.jpg)
function RungePheo(n)
%% plot f(x)=1/(1+x^2) on [-5,5]
ezplot('1/(1+x^2)',[-5 5]);
hold on; %hold the graph.
%% generate x_i=-5+(10)*i, stored in xd=[x0 x1 x2 ... xn]
xd=[-5:(10):5];
%% Generate y_i=f(x_i), stored in yd=[y0 y1 y2 ... yn]
yd=1./(1+xd.^2);
%% plot Pn(x), where Lagrange method is used.
%disritize [-5:5]
x=[-5:0.01:5];
%compute y=Pn(x) by LagrangePoly
for j=1:length(x)
y(j)=LagrangePoly(xd,yd,x(j));
end
% plot the (x,Pn(x)) in red
plot(x,y,'r'); %'r' indicates that the curve is red.
axis auto;
(Runge's Phenomenon) In this problem, we will see Runge's phenomenon or the function f(x) on the interval -5,5]. To be more precise, we will see that the more node points you put in [-5,5], the worse it becomes. This famous example is due to Carl Runge and the same (up to a scaling) as that demonstrated in class. Let ro ,, r1, ..., Tn be n +1 equally spaced points between -5 and 5 (with 20 =-5 and xn-5) (a) A matlab program named RungePheo.m is attached to illustrate Runge's phenomenon. Run the code to plot a figure with n 10 (your code in problem 4 is needed). Provide your figure. Explain Runge's phe- nomenon (b) As mentioned in class, the solution to Runge's phenomenon is to use polynomials of lower degree and use piecewise polynomial. In partic- ular, the natural cubic spline is a good one. In matlab, the natural cubic spline is implemented by the command spline. Write a mat- lab program to produce a similar figure by replacing the polynomial interpolation in (a) by the natural cubic spline interpolation. Provide your code, and print your figure with n = 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
