How do I specify m for orthpoly::legendre ?

3 次查看(过去 30 天)
I want to get the associated Legendre polynomials in mupad, but only the Legendre (not assoc.) are avail.
Is there a way to get this or can I call the MATLAB legendre func from Mupad?

采纳的回答

Billy
Billy 2011-6-14
Using http://mathworld.wolfram.com/AssociatedLegendrePolynomial.html, you can express the associated legendre polynomials in terms of the unassoc ones:
use(orthpoly,legendre)
P := (l,m) -> piecewise(
[m>0, (-1)^m * (1-x^2)^(m/2) * diff( legendre( l, x ), x $ m ) ],
[m=0, legendre( l, x )],
[m<0, (-1)^(-m) * (l+m)!/(l-m)! * P( l,-m )] )

更多回答(1 个)

Billy
Billy 2012-5-17
In fact a better way to do this:
Define Legendre polynomials:
P := (n) -> 1/(2^n * n!) * diff( (x^2-1)^n, x $ n )
// and the associated legendre polynomials:
Plm := (l,m) -> ( 1 - x^2 )^(m/2) * diff( P(l), x $ m )
// The normalizing factor:
Klm := (l,m) -> sqrt( ( (2*l+1)/(4*PI) ) * ( ( (l-m)!) / ((l+m)!) ) )
// Finally, the spherical harmonics
Ylm := (l,m,t,p) -> piecewise(
[m>0, sqrt(2)*Klm(l,m) * (Plm(l,m)|x=cos(t)) * cos(m*p) ],
[m=0, Klm(l,m) * (Plm(l,m)|x=cos(t)) ],
[m<0, sqrt(2)*Klm(l,-m) * (Plm(l,-m)|x=cos(t)) *sin(-m*p) ]
)
// Generate a plot:
plot( plot::Spherical( [ abs( Ylm(4,0,t,p) ), p, t], p=0..2*PI, t=0..PI,
UMesh=60, VMesh=60, FillColorType=Flat, Color=[.8,.5,.2] ), Scaling=Constrained )
// truncate values greater than 0
lt0 := (v) -> (1-heaviside(v)) * v
// truncate values less than 0
gt0 := (v) -> heaviside(v)*v
// plot
plot(
plot::Spherical( [ abs(gt0(Ylm(5,4,t,p))), p, t], p=0..2*PI, t=0..PI,
UMesh=60, VMesh=60, FillColorType=Flat, Color=[0,.6,0] ),
plot::Spherical( [ abs(lt0(Ylm(5,4,t,p))), p, t], p=0..2*PI, t=0..PI,
UMesh=60, VMesh=60, FillColorType=Flat, Color=[.4,0,.0] ),
Scaling=Constrained
)
  1 个评论
Walter Roberson
Walter Roberson 2012-5-17
(Note: the above is MuPAD code and must be run from within a MuPad notepad, or coded carefully into an evalin(symengine) call, or written to a file and the file called upon within MuPAD)

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by