#
#octave_functions_SphericalHarmonic_ReY.m
#
#https://octave-online.blogspot.com/search/label/functions_SphericalHarmonic_ReY
#
#P00(x)=1
#P10(x)=x
#P11(x)=(1-x^2)^1/2
#P20(x)=2/3x^2-1/2
#P21(x)=3x(1-x^2)^1/2
#P22(x)=3(1-x^2)
#P30(x)=5/2x^3-3/2x
#P31(x)=(3/2)(5x^2-1)(1-x^2)^1/2
#P32(x)=15x(1-x^2) 
#P33(x)=15(1-x^2)3/2
#
function out = octave_functions_SphericalHarmonic_ReY( l, m )

 seg=64;

 theta=linspace(0,pi,seg);
 phi=linspace(0,2*pi,seg);

 Theta=theta'*ones(1,seg);
 Phi=ones(seg,1)*phi;

 x=sin(Theta).*cos(Phi);
 y=sin(Theta).*sin(Phi);
 z=cos(Theta);

 L=legendre(l,cos(theta));
 am=abs(m);
 LL=L(abs(m)+1,:);
 c=(-1)^((m+am)/2)*sqrt((2*l+1)/(4*pi)*factorial(l-am)/factorial(l+am))*LL'*exp(1i*m*phi);

 cc=real(c);
 r=abs(cc);

 plot3(r.*x,r.*y,r.*z);

 out = l

endfunction
