clear all; close all; % Get data: x=-1:0.2:1; y=1./(1.+25*x.*x); n=length(x); % Evaluate y = sqrt(x) between 0 and 10 using the Lagrange polynomial with % step size 0.2 x1=-1:0.05:1; N2=length(x1); for i=1:N2, yp(i) = lagrange1(n,x,y,x1(i)); true(i) = 1/(1 + 25*x1(i)^2); end plot(x1,true,x1,yp,'o') title('Exact and interpolated results') figure(2); plot(x1,yp-true); title('Error plot') hold; y2=0*y; plot(x,y2,':')