# Substitute gives me different result

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:

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!

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

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:

And when replace k by 0 clearly will cause problem.

Lessons learned!

• Nicely done. $\phantom{}$ Apr 19 '20 at 14:57