function y = legendre0(x) y = ones(x); endfunction; function y = legendre1(x) y = x; endfunction; function y = legendre2(x) y = (3*x.^2-1)./2; endfunction; function y = legendre3(x) y = (5*x.^3-3*x)./2; endfunction; function y = legendre4(x) y = (35*x.^4-30*x^2+3)./8; endfunction; function y = legendre5(x) y = (63*x.^5-70*x^3+15*x)./8; endfunction; scf(0); clf(); t=-1:0.01:1; plot(t,legendre0(t),'k:'); plot(t,legendre1(t),'k-'); plot(t,legendre2(t),'b:'); plot(t,legendre3(t),'b-'); plot(t,legendre4(t),'r:'); plot(t,legendre5(t),'r-'); xtitle('Legendre Polynominals 0 to 5','x','P_n(x)'); scf(1); clf() phi=0:0.01:%pi; t=cos(phi); plot(phi,legendre0(t),'k:'); plot(phi,legendre1(t),'k-'); plot(phi,legendre2(t),'b:'); plot(phi,legendre3(t),'b-'); plot(phi,legendre4(t),'r:'); plot(phi,legendre5(t),'r-'); xtitle('Legendre Polynominals 0 to 5','phi','P_n(cos(phi))');