% PLOTLEGENDRE Plot five Legendre polynomials P_0(x),...,P_4(x), and
%   show the zeros of P_4(x). These points are x_1,x_2,x_3,x_4 in
%   the n=4 Gaussian quadrature ("Gauss-Legendre") rule.

x = -1:.002:1;
P2 = (1/3) * (3*x.^2 - 1);
P3 = (1/5) * (5*x.^3 - 3*x);
P4 = (1/35) * (35*x.^4 - 30*x.^2 + 3);
set(0,'defaultlinelinewidth',2.0)
plot(x,ones(size(x)),x,x,x,P2,x,P3,x,P4)
legend('P_0(x)','P_1(x)','P_2(x)','P_3(x)','P_4(x)',...
       'location','southeast')
grid on,  xlabel x, axis([-1 1 -1.2 1.2])

z4 = [0.3399810436 0.8611363116]; % from text: zeros of P_4  
z4 = [-fliplr(z4) z4]             %   ... shows them as numbers
hold on
plot(z4,zeros(1,4),'o','markersize',12,'linewidth',3.0),  hold off
