Skip to main content

calculus and analysis - Simplification of integrals depending on a parameter



Assuming[Element[n, Integers], Integrate[Sin[x]*Sin[n*x],{x,0,Pi}]]

returns 0, which is obviously wrong for n=1.


Assuming[n==1, Integrate[Sin[x]*Sin[n*x],{x,0,Pi}]]

does return Pi/2 (so in particular not 0).


Just evaluating the integral yields



-Sin[n*Pi]/(-1+n^2)

which is indetermined for n=1.


Can someone explain to me what Mathematica is doing and how to obtain a correct result?



Answer



If you look in the help file for Integrate under the section on "Possible Issues", there is an explanation. The docs comment: "Parameters like n are assumed to be generic inside indefinite integrals:" and the example is given of Integrate[x^n, x] which returns x^(1 + n)/(1 + n). As with the OPs integral, the answer is true for generic n, but not for a specific value n=-1 (or n=1 for the OPs integrand).


I had not seen it before, but rcollyer's explanation of this issue is very detailed and has some good pointers on how to handle this kind of situation. His post begins: "Sometimes, it pays to understand the integrand better before you integrate..." In the particular integral here, the integral of Sin[x]*Sin[n x], it is clear that n=1 is very special -- it is also clear from the indefinite integral answer -Sin[n*Pi]/(-1+n^2) that n=1 is special. But I know of no way to automatically tell what the generic/specific conditions are in all cases.


Comments