Originally Posted by

**shadow85** Hi, I am having trouble getting this legendre function to work in Matlab now. I am suppose to create a for-loop containing the recursion equation to create a vector called P, containing simplified symbolic formulae for the legendre polynomials from degree 1 up to degree 10. firstly I included the first two degree

here is my matlab code of I tried to do:

syms x k

x=linspace(-1,1,5);

P(1)=x;

P(2)=0.5*(3*x^2-1);

for k=1:9

P(k+1)=(1/k+1)*((2*k+1)*x*P(k)-k*P(k-1));

end

I keep getting this error from Matlab:

??? In an assignment A(I) = B, the number of elements in B and

I must be the same.

Error in ==> legendrepoly at 4

P(1)=x;