n = 40;
n_interp = 200;
lin_vec = linspace(0, n-1, n);
x = cos(-pi*lin_vec/(n-1));
x_interp = linspace(-1,1,n_interp);

% set up the corfficient matrix
C = zeros(n,n);
for i = 1:n
    C(:,i) = x.^(i-1);
end

% linear polynomial
%y = x;
%y_true = x_interp;

% trig function
%y = sin(pi*x);
%y_true = sin(pi*x_interp);

% runge function
y = (1.0+25.0*x.*x).^(-1.0);
y_true =(1.0+25.0*x_interp.*x_interp).^(-1.0);

y = y';
a = C\y;

y_interp = polynomial(a,x_interp);
plot(x_interp,y_interp, x_interp, y_true);