In: Advanced Math
On the interval [-1,1], consider interpolating Runge’s function f(x) = 1/ (1 + 25x^2) By Pn(x), use computer to graph:
(c) Take 11 equally spaced nodes in [-1,1], starting at –1, ending at 1, and obtain the interpolating polynomial P10(x). Also, use 11 Chebyshev nodes in [-1,1] and obtain Pc(x), the corresponding interpolating polynomial. In the same graph, plot the three functions f(x), P10(x) and Pc(x) over the interval [-1,1] . Use different line-styles, so that f(x), P10(x) and Pc(x) look distinct.
b)Comment on the error formula for the nth degree interpolating polynomial by only computing the first three derivatives of f(x). Explain how accuracy will be lost (or gained) by interpolating f(x) at more points (by increasing n)
please give thumsup
We have developed a MATLAB code for the given problem. Here, input of the function is the degree of the polynomial.
---------------------MATLAB code---------------------
function Runge_function(n)
% n=degree of the polynomial;
% Therefore, number of data popints is n+1;
fx=@(x) 1./(1+25*x.^2);
a=-1;
b=1;
x_exact=a:0.01:b;
y_exact=fx(x_exact);
x=(a:(b-a)/n:b)';
y=fx(x);
A=x.^(0:n);
coeff=(A'*A)\(A'*y);
fprintf('\nRequired %g th degree polynomial is: \n\n',n)
fprintf(' y= %g + (%g) x',coeff(1),coeff(2))
for i=3:n+1
fprintf(' + (%g) x^%g',coeff(i),i-1);
end
fprintf('\n\n')
xx=a:0.01:b;
yy=0*xx;
y2=0*x;
for j=0:n
yy=yy+coeff(j+1)*xx.^j;
y2=y2+coeff(j+1)*x.^j;
end
VarNames = {'x','exact_y','approx_y','Absolute_error'};
TT=table(x,y,y2,abs(y-y2), 'VariableNames',VarNames);
disp(TT);
figure(1)
plot(xx,yy,'-',x_exact,y_exact,'--',x,y,'*k','LineWidth',1.25);
xlabel('x','fontsize',14)
ylabel('y(x)','fontsize',14)
legend('Polynomial','Actual curve','Node points')
title('Regression line vs Actual data','fontsize',14);
end
(a)
(b)
(c)