Using int and floating gives different value of LegendreP

34 Views Asked by At

I should post this in mathematica forum, sorry for the inconvenience. When I use LegendreP at mathematica 10.0, I found weird a thing happening.

In[693]:= N[LegendreP[300, Cos[50/360 2 Pi]]]

Out[693]= -1.04451*10^61

If

In[692]:= N[LegendreP[300, Cos[50.0/360 2 Pi]]]

Out[692]= -0.0402969

Obviously, $-0.0403$ is the right answer. Why has such big difference?

I also tried like

In[694]:= N[LegendreP[300.0, Cos[50/360 2 Pi]]]

Out[694]= -0.0402969

And also

In[695]:= N[LegendreP[30, Cos[50/360 2 Pi]]]

Out[695]= 0.126799

Looks if $n$ is smaller than $50$, also give a right value.

I totally confused....

1

There are 1 best solutions below

0
On

Catastrophic cancellation is happening here. The largest coefficient of $P_{300}(x)$ has magnitude larger than $10^{112}$; that's enormous! Even after plugging in the value of $x$, the largest term still has magnitude greater than $10^{76}$. You either need lots of precision or clever symbolic manipulation in order to get anything vaguely resembling the correct answer.

In particular, this cannot be computed in the naive way using machine precision arithmetic.

If you ask mathematica to specifically give you some number of digits of precision, it knows how to achieve it:

In[1]:= N[LegendreP[300, Cos[50/360 2 Pi]], 3]

Out[1]= -0.0403