Re: SphericalHarmonics strange behavior
- To: mathgroup at smc.vnet.net
- Subject: [mg100983] Re: [mg100961] SphericalHarmonics strange behavior
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 19 Jun 2009 20:45:57 -0400 (EDT)
- Reply-to: hanlonr at cox.net
It's a precision issue
diffY[l_, m_, t_, p_] :=
Module[{val1, val2},
val1 = SphericalHarmonicY[l, m, t, p];
val2 = Sqrt[(2*l + 1) (l - m)!/(4*Pi (l + m)!)]*
LegendreP[l, m, Cos[t]]*E^(I*m*p);
Abs[val1 - val2]];
th1 = 1.324;
ph1 = 5.231;
{diffY[1, 1, th1, ph1], diffY[1, -1, th1, ph1]} //
Chop
{0,0.670051}
th1 = 1.324`20;
ph1 = 5.231`20;
{diffY[1, 1, th1, ph1], diffY[1, -1, th1, ph1]} //
Chop
{0,0}
Your definition would need to include an option for setting the working precision.
Bob Hanlon
---- "lbloy at seas.upenn.edu" <lbloy at seas.upenn.edu> wrote:
=============
Hi all,
working with some spherical harmonics and have some questions about the code as implemented in mathematica.
based on http://mathworld.wolfram.com/SphericalHarmonic.html
I put together the following code to see what is implemented
th1 = 1.324;
ph1 = 5.231;
diffY[l_, m_, t_, p_] :=
Module[{val1, val2}, val1 = SphericalHarmonicY[l, m, t, p];
val2 =
Sqrt[((2*l + 1)*(l - m)!)/((4*Pi)*(l + m)!)]*
LegendreP[l, m, Cos[t]]*E^(I*m*p);
Print[{val1, val2, Abs[val1 - val2]}];
Return[Abs[val1 - val2]]; ];
diffY[1, 1, th1, ph1]
diffY[1, -1, th1, ph1]
Clearly there is some sign error somewhere I was wondering if anyone had any suggestions.
thanks
Luke