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$ Commented Apr 19, 2020 at 14:22
  • $\begingroup$ Or Timing[Integrate[LegendreP[k, 0, Cos[η]]*Sin[η] /. k -> 0, {η, 0, Pi}]] $\endgroup$ Commented Apr 19, 2020 at 14:25
  • $\begingroup$ @J.M. I think you are right on the point. Thanks. $\endgroup$ Commented Apr 19, 2020 at 14:31
  • $\begingroup$ @BobHanlon Thanks. $\endgroup$ Commented Apr 19, 2020 at 14:31
  • $\begingroup$ If you figured out my hint, please consider writing an answer to your own question. ;) $\endgroup$ Commented Apr 19, 2020 at 14:33

1 Answer 1

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$ Commented Apr 19, 2020 at 14:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.