5

This is a big problem if you do anything with a Fourier Series. This statement:

Assuming[Element[{m, n}, Integers], Integrate[Cos[m*x]*Cos[n*x], {x, 0, 2 Pi}]]

returns 0. But the right answer is non-zero whenever $|m|=|n|$.

This other arrangement:

Integrate[Cos[m*x]*Cos[n*x], {x, 0, 2 Pi},  Assumptions -> Element[{m, n}, Integers]]

gives an answer that goes $0/0$ when $|m|=|n|$.

I know there are generic and non-generic answers, but this is pretty dang simple. And Fourier series work is pretty common!

What I need is a solution that will work when I didn't know there was a Cos[n x] in it:

Integrate[Integrate[Cos[m*x]*f[x], {x, 0, 2 Pi},  Assumptions -> Element[{m}, Integers]]

If my f[x] happens to have a Cos[] in it, Mathematica will give me wrong answers, unless I anticipate the situation and code around it. How could I do that?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Jerry Guern
  • 4,602
  • 18
  • 47
  • 1
    Mathematica returns generic results. You are trying to get a non-generic result. You will likely need to change your assumptions to force Mathematica to consider the non-generic case. – KAI Nov 17 '14 at 22:24
  • 3
  • 3
    No, it's not simple. Not at all. I suspect it would require a considerable amount of special case pattern matching to implement any subset of integrals of this type. Seen next comment for why current method cannot do these. – Daniel Lichtblau Nov 17 '14 at 23:45
  • 2
    Currently much assumption handling is accomplished under the hood with Refine and Simplify. In a case like this, assumptions of integrality will have the predictable result. Here is a smaller variant: `Refine[Sin[m*Pi]/m, Assumptions->Element[m,Integers]]

    Out[5]= 0. If this does not return 0, thenRefineis effectively useless. And if it does, thenRefinecannot do better than support a generic result, when used inIntegrate`.

    – Daniel Lichtblau Nov 17 '14 at 23:46
  • 1
    @DanielLichtblau Okay, not that I understand why the bug exists, how do I work around it? How do I make my integrals of products of sums of trigonometric functions not come out wrong? – Jerry Guern Nov 30 '14 at 20:38

2 Answers2

6

At least with Mathematica version 10.0.1, using option Assumptions does provide a correct answer:

Integrate[Cos[m*x]*Cos[n*x], {x, 0, 2 Pi}, 
   Assumptions -> Element[{m, n}, Integers]] 

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

I don't know why this form of the input leads to a different result than the form using Assuming.

murray
  • 11,888
  • 2
  • 26
  • 50
1

Very helpful discussion in progress about work-arounds HERE:

How to code around known MMa special-case failures?

Jerry Guern
  • 4,602
  • 18
  • 47