Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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$ ?

share|improve this question
Did you already try Assuming[Element[n, Integers], 2/Pi Integrate[Cosh[a x] Cos[n x], {x, 0, Pi}]]? – J. M. Jun 22 '13 at 9: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 – Skydreamer Jun 22 '13 at 9: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. Jun 22 '13 at 9:39
I'm on it, thank you for the help ! – Skydreamer Jun 22 '13 at 9:41
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 9:41
up vote 7 down vote accepted

Thanks to 0x4A4D 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]


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


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 !

share|improve this answer
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.… – Zet Nov 11 '13 at 9:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.