% simple code to compute and plot the interpolant of the Runge Function

k=10 % degree of the interpolant, change it...


x=linspace(-pi,pi,k+1);
g=1./(x.^2+1);
xfine=linspace(-pi,pi,1000);
gfine=1./(xfine.^2+1);
A=zeros(k+1,k+1);
for i = 1:(k+1)
    for j = 1:(k+1)
        A(i,j)= x(i)^(k-j+1);
    end
end
alpha = A\g';
clf
plot(x,g,'r*',xfine,gfine,'-b')
hold on

pol = zeros(1,1000);
for i=k:-1:0
    pol = pol + alpha(k-i+1)*xfine.^(i);
end
plot(xfine,pol, 'm-')