7
$\begingroup$

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

$\endgroup$
  • 3
    $\begingroup$ Did you already try Assuming[Element[n, Integers], 2/Pi Integrate[Cosh[a x] Cos[n x], {x, 0, Pi}]]? $\endgroup$ – J. M. will be back soon Jun 22 '13 at 9:34
  • $\begingroup$ 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 $\endgroup$ – Cydonia7 Jun 22 '13 at 9:35
  • $\begingroup$ 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? $\endgroup$ – J. M. will be back soon Jun 22 '13 at 9:39
  • $\begingroup$ I'm on it, thank you for the help ! $\endgroup$ – Cydonia7 Jun 22 '13 at 9:41
  • 2
    $\begingroup$ 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. $\endgroup$ – Artes Jun 22 '13 at 9:41
7
$\begingroup$

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 !

$\endgroup$
  • $\begingroup$ 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. mathematica.stackexchange.com/questions/19833/… $\endgroup$ – stathisk Nov 11 '13 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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