function pn=Legendre(k,x)
pnm1=0;
pn=1;
for n=1:k
    pnp1=((2*n-1)*x*pn-(n-1)*pnm1)/n;
    pnm1=pn;
    pn=pnp1;
end;
return;
