MATLAB: How can i solve this

legendre polynomialrecursion

I am trying to solve this really simple code problems, but I wan not able:
Omega=zeros(1,800);
Y=cos(km2rad(20));
for n=1:800
Omega(n)=(1/2)*[(legendreP(n-1,Y))-(legendreP(n+1,Y))];
end
Omegazero=(1/2)*(1-Y);
OmegaT=[Omegazero Omega];
********************************************************************
The real formulation is:
Omega(n)=1/2[Pn-1(Y)-Pn+1(Y)],
OmegaZero=1/2(1-Y)
Y=cos(20km) that should be in radian.
I know the answer but I can not reach to real answer. I got something really different.
Thanks

Best Answer

I could see how
Bn=2n-1/n+1*Bn-1*cos(psi)-(n-2/n+1)*Bn-2
could translate to
B(n) = (2*n-1)/(n+1) * B(n-1) * cos(psi) - (n-2)/(n+1)*B(n-2);
but where are your "3" coming from in your line
B(n)=((((2*n)-3)/(n))*B(n-1)*cos(psi))-(((n-3)/(n))*B(n-2));
?