ans =
How can I calculate the integral of Legendre function P(n,theta) ?
조회 수: 16 (최근 30일)
이전 댓글 표시
How can I calculate the integral of Legendre function P(n,theta) ?
say:
int(cos(theta)*P(n,theta),theta=0..pi) ;
채택된 답변
Torsten
2024년 5월 5일
편집: Torsten
2024년 5월 5일
The Legendre function is a numerical, not a symbolic function in MATLAB.
Further, it's define for -1 < x < 1. So integration from 0 to pi does not work.
format long
n = 10;
integral(@(x)cos(x).*legendre(n,x),0,0.5,'ArrayValued',1)
Or do you mean the Legendre polynomials:
?
syms x
n = 10;
int(cos(x)*legendreP(n,x),x,0,sym(pi))
댓글 수: 7
Torsten
2024년 5월 6일
As a MATLAB function, I can only find this one for ssociated Legendre functions, and it does not accept symbolic input aguments:
Thus you have to use the numerical integration method that I gave you at first.
추가 답변 (1개)
John D'Errico
2024년 5월 6일
편집: John D'Errico
2024년 5월 6일
I think you do not understand that a Legendre polynomial is meaningless over some other interval. It has no special properties when applied over a different interval. For example, we know that on the interval [-1,1], they form an orthogonal family.
syms x
P2 = legendreP(2,x);
P3 = legendreP(3,x);
int(P2*P3,-1,1)
However, over some other interval, you get:
int(P2*P3,0,pi)
Yes. Random garbage. You need to understand that fact. On some other interval, they have no useful value or meaning. And that means you need to transform them, IF you will try to use thm on some other interval.
Now first, I will point out that LegendreP returns a polynomial with the property that the integral over [-1,1] the integral of P_n*P_n is 1/(n+1/2). (This is stated in the help docs for legendreP.) So personally, I would tend to make them an orthonormal family, by rescaling by the sqrt of that value.
mylegendreP = @(n,x) legendreP(n,x)*sqrt(sym(n)+1/2);
Testing that, we would have
int(mylegendreP(2,x)*mylegendreP(3,x),-1,1)
int(mylegendreP(3,x)*mylegendreP(3,x),-1,1)
And as you see, they now form an orthonormal family.
Next, in order to use them over a different interval, you need to transform them. Over the interval [a,b], we could do that like this:
mytranslegendreP = @(n,x,a,b) mylegendreP(n,(x-(a+b)/2)/((b-a)/2))/sqrt((b-a)/2)
I need to use pi in a symbolic form to make sure there are no numerical problems.
mytranslegendreP(2,x,0,sym(pi))
It looks a little messy, but test it out.
int(mytranslegendreP(2,x,0,sym(pi))*mytranslegendreP(3,x,0,sym(pi)),0,sym(pi))
int(mytranslegendreP(5,x,0,sym(pi))*mytranslegendreP(5,x,0,sym(pi)),0,sym(pi))
You can see the transformed family is now orthonormal on the interval [0,pi].
In your problem, now we can use it properly.
n = 10;
int(cos(x).^2*mytranslegendreP(n,x,0,sym(pi)),0,sym(pi))
vpa(ans)
As I said though, just using the default legendre polynomials on some other interval will yield meaningless garbage. Of course, it is entirely your choice to do as you want. But someone needs to tell you that what you want to do is patently silly and useless. Maybe this is homework. Your choice, anyway.
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!