8

I was trying to calculate this integral in Mathematica 9:

2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}, Assumptions -> n ∈ Integers]

I got as a result :

$$\frac{2 (a \sinh (\pi a) \cos (\pi n)+n \cosh (\pi a) \sin (\pi n))}{\pi \left(a^2+n^2\right)}$$

That's the same result I obtained manually, but how can I force Mathematica to change $\sin(n \pi)$ into $0$ and $\cos(n \pi)$ into $(-1)^n$ ?

Artes
  • 57,212
  • 12
  • 157
  • 245
Cydonia7
  • 2,519
  • 3
  • 19
  • 18
  • 3
    Did you already try Assuming[Element[n, Integers], 2/Pi Integrate[Cosh[a x] Cos[n x], {x, 0, Pi}]]? – J. M.'s missing motivation Jun 22 '13 at 09:34
  • Thank you, it does work indeed, what's wrong with the form I used ? (Assumptions -> ...) Maybe you could post this as an answer so I can award you the points – Cydonia7 Jun 22 '13 at 09:35
  • I'm not quite sure why one works and the other doesn't, even though they are ostensibly equivalent; the reason I left a comment is because I am not at a machine with Mathematica. Might I suggest writing your own answer to your own question instead? – J. M.'s missing motivation Jun 22 '13 at 09:39
  • I'm on it, thank you for the help ! – Cydonia7 Jun 22 '13 at 09:41
  • 2
    You can do it also this way: Simplify[2/Pi Integrate[Cosh[a x] Cos[n x], {x, 0, Pi}], Element[n, Integers]], it should work in more general cases than your original problem. – Artes Jun 22 '13 at 09:41
  • If someone does know why the original one doesn't work, please post it :) – Lucas Jun 22 '13 at 14:22
  • @Lucas See this answer. Perhaps this question is a duplicate? (It's sort of the other side of the coin.) – Michael E2 Jun 22 '13 at 15:42
  • @MichaelE2 Thanks. I think they are sufficiently different, though a comment in one of the answers implies there are yet more that refer to the same behaviour (bug, IMO). – Lucas Jun 23 '13 at 09:48

1 Answers1

9

Thanks to J. M. and Artes, I figured out what the problem was.

I had to change

2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}, Assumptions -> n ∈ Integers]

into

Assuming[ n ∈ Integers, 2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}]]

or

Simplify[ 2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}], n ∈ Integers]

I don't know what's the problem with the first form but still, it works !

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Cydonia7
  • 2,519
  • 3
  • 19
  • 18
  • If you set the assumptions outside the scope of Integrate[], that is inside Assuming[] or Simplify[] then Integrate[] doesn't mess with them. That is how I understand it. Check this link also. http://mathematica.stackexchange.com/questions/19833/usage-of-assuming-for-integration/19894#19894 – stathisk Nov 11 '13 at 09:36