% lagrange basis functions for interpolation
% n=5 data points: 
% t: 0.00 0.25 0.50 0.75 1.00
% lagrangeBasis.m
% Ming Leung, 12/27/02

clear all; hold off;
n=5; t=[0.00 0.25 0.50 0.75 1.00]; % 5 equally spaced pts from 0 to 1

t_plot=(0:0.025:1)'; L=ones(length(t_plot),n);
for j=1:n
    for k=1:n
        if k==j, 
            continue; 
        else,
            L(:,j)=L(:,j).*((t_plot-t(k))/(t(j)-t(k)));
        end;
    end;
end;

plot(t_plot,L);
xlabel('t'); ylabel('l_k(t)');
title('Lagrange basis functions for t=[0.00, 0.25, 0.50, 0.75, 1.00]');
