function pk=Legendre(k,x)
if     (k==0) 
   pk=1;
elseif (k==1) 
   pk=x;
else 
   pnm2=1;
   pnm1=x;
   for n=2:k
       pn=((2*n-1)*x*pnm1+(1-n)*pnm2)/n;
       pnm2=pnm1;
       pnm1=pn;
   end
   pk=pn;
end
return;
