restart; #Section 4.7 number 3b N:=4; #Create the Legendre Polynomials P[0]:=1; for n from 1 to N do P[n]:=1/(n!*2^n)*diff((x^2-1)^n,x$n); end; dp:=(f,g)->int(f*g,x=-1..1); nm:=f->sqrt(dp(f,f)); f:=log(1+x^2); for n from 0 to N do beta[n]:=dp(f,P[n])/dp(P[n],P[n]); end; p:=collect(sum(beta[j]*P[j],j=0..N),x); plot({p,f},x=-1..1); #plot of the errors on [-1,1] plot(f-p,x=-1..1);