# integration on real domain only!

i am trying to integrate a real valued function. For some reason, Mathematica gives an answer in the complex domain. I'd be grateful for your answers.

Here is the integral:

Integrate[(-(Cos[b*s] - (2*Sin[b*s]*(a*D - b*C))/(a^2 + b^2))/E^(a*s))^2, {s, 1, ∞},
Assumptions -> Element[s, Reals]]


Mathematica produces the following:

ConditionalExpression[1/4
(1/a + 1/(2 a - 2 I b) + 1/(2 a + 2 I b) + (-1 + E^(-2 a))/a +
(-1 + E^(-2 (a + I b)))/(2 (a + I b)) +
(-1 + E^(-2 a + 2 I b))/(2 a - 2 I b) -
(2 (b C - a D)^2 E^(-2 (a + I b)) (-2 b^2 E^(2 I b) +
a^2 (-1 + E^(2 I b))^2 + I a b (-1 + E^(4 I b))))/(a (a^2 + b^2)^3) +
(4 (b C - a D) E^(-2 a) (b Cos[2 b] + a Sin[2 b]))/(a^2 + b^2)^2),
Abs[Im[b]] < Re[a] && Re[a] > 0]

-
You've only told Mathematica that s is real. What about a, b, c? Also you should refrain from using capitalized letters as variables, as D is an internal function. –  RunnyKine Mar 14 '13 at 19:47
Also, what happens if $b \in \mathbb{R}$, what do the conditions then say? (I don't mean programmatically, which can be done using Reduce, but by hand.) –  rcollyer Mar 14 '13 at 19:50
Thank you very much for your response. –  No Leaf Clover Mar 14 '13 at 20:22
nothing changes though! –  No Leaf Clover Mar 14 '13 at 20:22

Your s lives on the ray [1,infinity). Integrate can kinda figure out s is real. Tell it about the other variables and then we'll proceed from there.

i1 =
Integrate[(-(Cos[b*s] - (2*Sin[b*s]*(a*d - b*c))/(a^2 + b^2))/
E^(a*s))^2, {s, 1, \[Infinity]},
Assumptions -> {Element[{b, c, d}, Reals], a > 0}]

(* Out[152]= 1/4 (1/a + 1/(2 a - 2 I b) + 1/(
2 a + 2 I b) + (-1 + E^(-2 a))/a + (-1 + E^(-2 (a + I b)))/(
2 (a + I b)) + (-1 + E^(-2 a + 2 I b))/(2 a - 2 I b) - (1/(
a (a^2 + b^2)^3))
2 (b c - a d)^2 E^(-2 (a + I b)) (-2 b^2 E^(2 I b) +
a^2 (-1 + E^(2 I b))^2 + I a b (-1 + E^(4 I b))) + (
4 (b c - a d) E^(-2 a) (b Cos[2 b] + a Sin[2 b]))/(a^2 + b^2)^2) *)


ComplexExpand is good about separating real and imaginary parts under the assumption that variables are real-valued. It is not good at conciseness, so follow up with Simplify and hope for the best. Or trust that I checked this first.

Simplify[ComplexExpand[i1]]

(* Out[155]= (1/(4 a (a^2 +
b^2)^3))E^(-2 a) ((a^2 + b^2) (a^4 + b^4 + 4 b^2 c^2 - 8 a b c d +
2 a^2 (b^2 + 2 d^2)) +
a (a^5 + 4 b^4 c + 4 a^2 b c (b + 2 d) +
a b^2 (b^2 - 4 c^2 - 4 b d) + 2 a^3 (b^2 - 2 b d - 2 d^2)) Cos[
2 b] - a (b^5 - 4 a^3 b c - 4 b^3 c^2 - 4 a b^2 c (b - 2 d) +
a^4 (b + 4 d) + 2 a^2 b (b^2 + 2 b d - 2 d^2)) Sin[2 b]) *)

-
{Element[{b, c, d}, Reals], a > 0} why dont we just write Element{a,b,c,d}, Reals ? –  No Leaf Clover Mar 14 '13 at 20:24
That extra was just to get rid of the Conditional result: the positivity is to get convergence. –  Daniel Lichtblau Mar 14 '13 at 20:35
thank you so much, I've just started using mathematica, I greatly appreciate your help. –  No Leaf Clover Mar 14 '13 at 20:46