How do I specify m for orthpoly::legendre ?

5 Ansichten (letzte 30 Tage)
Billy
Billy am 14 Jun. 2011
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?

Akzeptierte Antwort

Billy
Billy am 14 Jun. 2011
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 )] )

Weitere Antworten (1)

Billy
Billy am 17 Mai 2012
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 Kommentar
Walter Roberson
Walter Roberson am 17 Mai 2012
(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)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by