% a script to measure the sup l_k(x) for lagrange basis functions for
% equally spaced nodes on [-1,1]
% Brad Nelson 1/22/12

xs=-1:0.001:1;%xs to plot
nmax=40; %highest n to test
sups=zeros(nmax);%blank matrix for holding sups

%for loop runs over number of nodes to use
for n=1:nmax;

ys=zeros(numel(xs),n); %blank y matrix
xj=-1:2/(n-1):1; %xj=set of equally spaced points on [-1,1]

%evaluates lagrange polynomials at each x
for i=1:numel(xs);
    ys(i,:)=lagrange(xs(i),xj);
end

%finds supremum of all basis functions on interval
sups(n)=max(max(abs(ys)));

end
figure;
semilogy(1:nmax,sups,'-');
title('sup of n lagrange basis functions on [-1,1]')

print -depsc lbasis_sup.eps;