The legendre polynomials are recursively defined as follows
$L_{k+1}(x)=\frac{2k-1}{k}xL_k(x)-\frac{k-1}{k}L_{k-1}(x)$
I want to calculate the value of $L_k(x)$ for any given value $x$. I used the above recursion to come up with the following matlab code:
function [out] = ausWert(k,x)
if(k==0)
out =1;
else if(k==1)
out=x;
else
out =ausWert(k-1,x)*x*(2*k-1)/(k)-((k-1)/k)*ausWert(k-2,x);
end
end
end
Whats the best/fastest way to calculate $L_k(x)$ ? My recursive code is terrible slow...
Would appreciate any help