0
$\begingroup$

I'm working with Legendre polynomials (& associated ones). When I do the following calculation:

Table[Integrate[LegendreP[k, 0, Cos[η]] * Sin[η], {η, 0, Pi}], {k, 0, 10}]

I tried out one particular value of k to see the calculation time:

Timing[Integrate[LegendreP[k, 0, Cos[η]] * Sin[η], {η, 0, Pi}] /. k -> 0]

That is when I found this different result /. causes: results

I do have a way to get around this issue, but I really want to know why the Replace[] can cause this indeterminate result and all the warning messages.

Thank you!

$\endgroup$
8
  • 1
    $\begingroup$ Ponder on the result of Integrate[LegendreP[k, 0, Cos[η]] Sin[η], {η, 0, π}], and then consider Limit[Integrate[LegendreP[k, 0, Cos[η]] Sin[η], {η, 0, π}], k -> 0]. $\endgroup$
    – J. M.'s torpor
    Apr 19 '20 at 14:22
  • $\begingroup$ Or Timing[Integrate[LegendreP[k, 0, Cos[η]]*Sin[η] /. k -> 0, {η, 0, Pi}]] $\endgroup$
    – Bob Hanlon
    Apr 19 '20 at 14:25
  • $\begingroup$ @J.M. I think you are right on the point. Thanks. $\endgroup$
    – Ying Zhang
    Apr 19 '20 at 14:31
  • $\begingroup$ @BobHanlon Thanks. $\endgroup$
    – Ying Zhang
    Apr 19 '20 at 14:31
  • $\begingroup$ If you figured out my hint, please consider writing an answer to your own question. ;) $\endgroup$
    – J. M.'s torpor
    Apr 19 '20 at 14:33
3
$\begingroup$

I was given a hint by @J.M. (Thank you!)

The reason that I got Indeterminate and all the warning messages is because the order of calculation in this expression:

Integrate[LegendreP[k, 0, Cos[η]] * Sin[η], {η, 0, Pi}] /. k -> 0

This expression calculates the Integral of LegendreP[k, 0, x] from -1 to 1 before replace the k with 0.

So, in Mathematica, if we calculate the integral, this is the result: enter image description here

And when replace k by 0 clearly will cause problem.

Lessons learned!

$\endgroup$
1
  • 2
    $\begingroup$ Nicely done. $\phantom{}$ $\endgroup$
    – J. M.'s torpor
    Apr 19 '20 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.