Associated Legendre polynomials are not orthogonal
22 views (last 30 days)
Show older comments
Hi:
I am seeking an orthogonal set of polynomials, so I was excited to see the matlab had the legendre function to generate the polynomials. However, they look nothing like the polynomials plotted in wikipedia nor do they obey the rules of orthogonality that make these polynomials attractive.
Here is my code:
x = linspace(-1, 1, 1000);
y = legendre(5, x);
y*y'
One would expect the off-diagonal elements to be zero or close to zero but this does not occur. I am curious if there is an analytical fix that would make the polynomials orthogonal.
Also does anyone have some code to generate these polynomials correctly (I mean disassociated ;).
Thanks in advance,
Pete
0 Comments
Answers (3)
Roger Stafford
on 7 Sep 2014
As cyclist has noted, the factor 1/(1-x^2) is essential in performing an orthogonality test. The Associated Legendre "polynomials" for differing m values are only orthogonal when each function is divided by sqrt(1-x^2).
Also note that when you make this change, your y*y' approximation to an integral would then yield NaNs at the two endpoints because of a zero-divided-by-zero occurrence. In the case of m1 = 0 and m2 = 1, you will get actual square root singularities in the integrand at the two ends even though the integral is still finite. To get accurate results for the orthogonality test I would advise you to use for-loops to compute with matlab's numerical quadrature function, 'integral', which can handle singularities, rather than your crude y*y' method. Either that or make an appropriate change of variable so that points are packed closely together at the two endpoints.
0 Comments
the cyclist
on 7 Sep 2014
I hand-coded a few of the polynomials, for L = 3. I don't know what plots you are looking at on Wikipedia -- this page for Associated Legendre polynomials doesn't have any plot -- but these look good to me.
L = 3;
s = 10000;
x = linspace(-1, 1, s);
y = legendre(L, x);
P_3_0 = (5*x.^3 - 3*x);
P_3_1 = (3/2)*(1-5*x.^2).*sqrt(1-x.^2);
P_3_2 = 15*x.*(1-x.^2);
P_3_3 = -15*(1-x.^2).^(3/2);
figure
subplot(2,1,1), plot(x,y)
set(gca,'XLim',[-1 1])
set(gca,'YLim',[min(y(:)) max(y(:))])
subplot(2,1,2), plot(x,[P_3_0; P_3_1; P_3_2; P_3_3])
set(gca,'XLim',[-1 1])
set(gca,'YLim',[min(P_3_3) max(P_3_2)])
As to your comment about orthogonality, you seem to have coded the condition for fixed M, but the output from MATLAB you are using is fixed L, for different M. If you look at the Wikipedia page I referenced, in the orthogonality section, you'll see what I mean. To do the orthogonality check on
legendre(L,x)
as you are doing, looks like you need the
1./(1-x^2)
term.
0 Comments
Peter Harrington
on 7 Sep 2014
3 Comments
Roger Stafford
on 7 Sep 2014
I agree with what John has said, but I will expand upon his remarks a little. Peter, you have stated, "For the Legendre polynomials orthogonality requires the weighting function x = 1." That is a true statement but only as applied to Associated Legendre polynomials of the same order, m, and different degrees, L1 ~= L2. With different orders m1 ~= m2 and the same degree, L, which is what you were testing in your original question, these polynomials need a weighting function of 1/sqrt(1-x^2) to achieve orthogonality. That is also a true statement.
That is where your tests with y*y' went wrong. You were comparing these polynomials, all with degree 5, and differing orders 0 through 5. That is what matlab's call
y = legendre(5, x);
gives you. y will have six rows corresponding to orders 0 to 5, and each row an Associated Legendre polynomial of degree 5. The only one that is a Legendre polynomial of the kind referred to in
http://en.wikipedia.org/wiki/Legendre_polynomials
is that in the first row with order zero.
To test for orthogonality with a weighting factor of 1, you need to call on 'legendre' a number of times with different degrees and compare rows having the same order - that is, equal row numbers.
x = linspace(-1,1,1000);
y5 = legendre(5,x); % Choose degrees 5 & 6
y6 = legendre(6,x);
y6(7,:) = []; % Discard order 6 since y5 doesn't have that order
sum(y5.*y6,2)
You should get a 6-element column vector of "zeros" to the accuracy of your approximation of the six definite integrals. At least they should be very small compared with, say, sqrt(sum(y5.*y5,2).*sum(y6.*y6,2)).
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!