% Runge's Example with Equidistant Nodes
% Computation using the Vandermode Matrix
%
% Lab Session 5 Problem 2

x = [-5:1:5];
n = length(x);

function y=f(x)
  y=1./(1.+x.^2);
end

y = f(x);

% Preallocate for speed:
A = zeros(n);

for j=1:n
  A(:,j) = (x.^(n-j))';
end

c = A\y';

norm(A*c-y')
cond(A)

xx = [-5:0.05:5];
ff = f(xx);
gg = polyval(c,xx);



plot(xx,ff,';f;',xx,gg,';interpolation;',x,y,'*;nodes;')

% gset term postscript eps monochrome;
% gset output "/tmp/test.eps"
% replot
% gset term x11