% Plot the Langrage basis polynomials l_0(x), ..., l_5(x) % for [a,b] = [0,1] with x_j = j/5. figure(1), clf xx = linspace(0,1,300)'; % fine grid for plotting N = 5; % number of grid points x = linspace(0,1,N+1)'; % grid points, x(j+1) = j/N = x_j for j=0:N lj = ones(size(xx)); % construct l_j on the fine grid, xx for k=0:N if k~=j, lj = lj.*(xx-x(k+1))/(x(j+1)-x(k+1)); end end plot(xx, lj, 'k-','linewidth',2), hold on plot(x,zeros(size(x)), 'k.','markersize',20) axis([0 1 -2 2]) set(gca,'fontsize',16) xlabel('x'), ylabel('l_j(x)'), title('Lagrange basis polynomials') input(' press ') end