MATLAB Answers

associated legendre functions matlab

2 views (last 30 days)
In the function legendre(1,-0.7071), the value corresponding to P11(-0.7071) is coming wrong when checked with standard solutions. Matlab is giving the solution as -0.7071. whereas, the actual solution is +0.7071. Please have a look at it. Or please suggest me how to correct it.
One can verify using online calculator in the link. https://keisan.casio.com/exec/system/1287453184

  4 Comments

Show 1 older comment
chaitanya  acharya
chaitanya acharya on 7 Dec 2019
Yes. Analytical solution for P11(cos(theta))=-sin(theta). But, the solution in matlab is different.
Rik
Rik on 7 Dec 2019
Since the documentation states the first degree returns the input as output, that obviously doesn't match your analysis. If you show your analytical solution we might to see if there is a flaw in your reasoning, or if there is a flaw in the analysis by Mathworks engineers.
chaitanya  acharya
chaitanya acharya on 7 Dec 2019
For the condition when degree=1 order=0, P10(x)=x as can be seen in wikipedia. For this case, the matlab code works fine. The problem starts when order is Odd.
For example,
Lets consider the order=1 degree=1 associated legendre polynomial.
In that case, the solutions is given as P11(x)=-sqrt(1-x^2); as can be seen in wikipedia.
if x= cos(theta), P11(x)=-sin(theta).
But, matlab gives wrong solution in third and fourth quadrant i.e., when theta is varied between pi to 2*pi.
I tried the same with mathematica. There i found the same problem.

Sign in to comment.

Accepted Answer

David Goodmanson
David Goodmanson on 7 Dec 2019
Hi chaitanya,
It's apples and oranges. When the domain of the argument is -1 <= x <= 1, the function is -sqrt(1-x^2). That's what Matlab is doing, and that's what it says it is doing. When the domain is opened up, 0 <= theta < 2pi with x = cos(theta), then the function can become -sin(theta). Both results are in Wikipedia.

  1 Comment

chaitanya  acharya
chaitanya acharya on 9 Dec 2019
Run this code: you will understand where the problem is occuring.
theta=linspace(0,2*pi,9);
phi=0;
n=1; m=1;
% legendre calculated from matlab
leg1=legendre(1,cos(theta));
leg_matlab=leg1(m+1,:);
% legendre analytical solution for cos(theta) at n=1 and m=1 is -sin(theta)
leg_analytical=-sin(theta);
figure(1)
plot(leg_matlab)
hold on
plot(leg_analytical)

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by