0

I am trying to get Mathematica to evaluate integrals such as the well-known Fourier orthogonality relations

$\int_0^L \sin \frac{2 m \pi x}{L} \sin\frac{2 n \pi x}{L}\,\mathrm{d}x=\begin{cases}0& m\ne n\\\frac{L}{2} & m=n\end{cases}$

I expected the following code would return a ConditionalExpression representing the two cases:

Assuming[Element[m, Integers] && Element[n, Integers], 
         Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}]]

However, the result is zero (i.e. it assumes $m\ne n$). I have to add an additional assumption that m==n to get Mathematica to evaluate the 'interesting' case. Am I missing something? Is there a way to get both results at once, without needing to already know the conditions for each case? (My ultimate application is a more complicated integral where I'm not confident I have identified all the relevant conditions.)

I'm sure finding the answer to this would be straightforward if only I knew what to search for!

If it's relevant, I'm using Mathematica 12.1.

avid
  • 101
  • 1
    Try:Piecewise[{{FullSimplify[ Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}, Assumptions -> {L > 0, m \[Element] Integers, n \[Element] Integers, m == n}], Assumptions -> {{n, m} \[Element] Integers}], m == n}, {FullSimplify[ Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}, Assumptions -> {L > 0, m \[Element] Integers, n \[Element] Integers, m != n}], Assumptions -> {{n, m} \[Element] Integers}], m != n}}]? – Mariusz Iwaniuk Mar 30 '20 at 15:47
  • 1
    @MariuszIwaniuk - Assuming avoids some redundancy: Assuming[{L > 0, Element[m | n, Integers]}, Piecewise[{{Assuming[m == n, Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}] // FullSimplify], m == n}, {Assuming[m != n, Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}] // FullSimplify], m != n}}]] – Bob Hanlon Mar 30 '20 at 16:50
  • @BobHanlon. Oh Yes Thanks :), 1(+) for comment. – Mariusz Iwaniuk Mar 30 '20 at 16:53
  • @MariuszIwaniuk Thanks -- but doesn't this rely on already knowing the relevant conditions? (m = n and m ≠ n)? In a more complicated setting where you didn't know these, what would you do? – avid Mar 30 '20 at 22:13
  • Along the same line of thinking, @avid, how can you assume whether m or n are equal or unequal? They are different symbols, therefore they are assumed to be unequal unless otherwise specified. The other suggestions here show you how to find and display for both cases. There won’t be a third case, and you know they are either equal or not. – CA Trevillian Mar 31 '20 at 08:04
  • @CATrevillian True for this specific set of integrals. But the pattern generalises (e.g. integrals of products of three sinusoids), and enumerating all the relevant conditions by hand becomes increasingly challenging... – avid Mar 31 '20 at 08:16
  • You’d want some sort of function that parses a list of let’s say arguments and the conditions between them and produces a list of all possible tuples? – CA Trevillian Mar 31 '20 at 19:40

0 Answers0