# Correct way to integrate a certain function

I want to integrate $$\int_{0}^{2\pi} dt_1 \frac{a + b\cos(t_1 - t_2)}{c + d\cos(t_1 - t_2)}$$ where $a, b, c, d, t_2$ are real numbers and $c + d > 0$ & $0 \leq t_2 \leq 2\pi$.
I used a straightforward command in Mathematica (9.0.1.0),

Integrate[(a + b*Cos[t1 - t2])/(c + d*Cos[t1 - t2]), {t1, 0, 2 π},
Assumptions -> {a ∈ Reals, b ∈ Reals, c >= 0, d <= 0, c + d >= 0, 0 <= t2 <= 2π}]


to get an obviously incorrect answer: $$2\pi \frac{b}{d},$$ because clearly the integral should be $\propto c^{-1}$ for $|c| \gg |d|$.

My question is what am I doing wrong here? Is there a general lesson to be learnt here about how Mathematica handles this kind of integrations and the correct way to ask it to perform such integrations?

-
@Kuba: Sorry. In my code I had the $A, \ldots, D$ in terms of four Greek alphabets. While writing here I mistakenly used $A, \ldots, D$. I corrected the question. Thanks for pointing this out. – vik May 23 '14 at 23:13
@belisarius maybe, I've not checked :) only a note. – Kuba May 23 '14 at 23:15

This question provides another example of a bug in Integrate (see e.g. this post).
Rewriting the integrand, we can get an idea why the result is incorrect:

Apart[(a + b Cos[t1 - t2])/(c + d Cos[t1 - t2])]

 b/d + (-b c + a d)/(d (c + d Cos[t1 - t2]))


the first term contributes to the result while the integral of the second term vanishes (incorrectly!):

Integrate[(-b c + a d)/(d (c + d Cos[t1 - t2])), {t1, 0, 2 π},
Assumptions -> (a | b) ∈ Reals && c >= 0 && d <= 0 &&
c + d >= 0 && 0 <= t2 <= 2 π]

0


Putting appropriate values into Integrate instead of symbolic constants we get reliable results, we can compare them with NIntegrate. Assuming another relations between symbolic constants we can conclude that the source of this bug is the assumption on the phase t2. Therefore if we remove the symbolic phase t2 (we can put a numeric value e.g. π/2) we'll find the correct result:

Integrate[(a + b Cos[t1 - π/2])/(c + d Cos[t1 - π/2]), {t1, 0, 2 π},
Assumptions -> (a | b) ∈ Reals && c >= 0 && d <= 0 && c + d >= 0]

ConditionalExpression[
(2 (a d + b (-c + Sqrt[c^2 - d^2])) π)/(d Sqrt[(c - d) (c + d)]),
d < 0 && c + d > 0]


We can verify that when $|c| \gg |d|$ this conditional expression behaves well:

Simplify[ Series[ %, {d, 0, 0}], c > 0]

ConditionalExpression[ (2 a π)/c + O[d]^1, d < 0 && c + d > 0]


Moreover the result does not depend on the phase t2 since we calculate the integrad depending on Cos[t1 - t2] over its total period 2 π.

-
Thanks for your comment in my (now deleted) answer – Dr. belisarius May 24 '14 at 13:04

This seems related to Bug in mathematica analytic integration?

Using the standard substitution

int = Simplify[(a + b*Cos[t1 - t2])/(c + d*Cos[t1 - t2]) Dt[t1] /.
t1 -> t2 + 2 ArcTan[u] // TrigExpand] /. {Dt[t2] -> 0,  Dt[u] -> 1}
(*
(2 (a + b + a u^2 - b u^2))/((1 + u^2) (c + d + c u^2 - d u^2))
*)


we obtain

Integrate[int, {u, -Infinity, Infinity},
Assumptions -> {c >= 0, d <= 0, c + d > 0}]
(*
(2 (a d + b (-c + Sqrt[c^2 - d^2])) π)/(d Sqrt[c^2 - d^2])
*)


It seems annoying, imo, that a standard class of integrals is not handled properly.

-

It appears Mathematica is using the fundamental theorem of calculus even though it's not valid in this case. Observe:

Simplify[Subtract @@ (Integrate[(a + b*Cos[t1 - t2])/(c + d*Cos[t1 - t2]), t1] /.
{{t1 -> 2 Pi}, {t1 -> 0}})]
(* 2*b*Pi/d *)


It's a tough problem to know when you can use FToC. See here for further explanation with an example similar to yours.

-
In the link that you've provided, it is said that the fundamental theorem of calculus requires that the antiderivative that is going to be subtracted be continuous throughout the interval. but in fact fundamental theorem of calculus says that the integrand should be continuous. So I guess the theorem should be applicable here since $f(x)=\frac{1}{5+4\sin x}$ is continuous on $[0,2\pi]$ interval – sepideh Oct 14 '15 at 19:32
I think that MathWorld link is implicitly assuming the antiderivative has been arranged so as to be continuous. Can be done in theory at least for paths of finite length, but is not so easy in practice. If you do Plot[Evaluate[Integrate[1/(5 + 4*Sin[x]), x]], {x, 0, 2 Pi}] you will see jumps from crossing branch cuts. – Daniel Lichtblau Oct 15 '15 at 14:46

Version 10.1 gives integral result

Integrate[(a + b*Cos[t1 - t2])/(c + d*Cos[t1 - t2]), {t1, 0, 2 \[Pi]},Assumptions -> {a \[Element] Reals, b \[Element] Reals, c >= 0, d <= 0, c + d >= 0, 0 <= t2 <= 2 \[Pi]}]


-
Do you know if it is correct? – Michael E2 Apr 16 '15 at 11:14
It seems to be consistent over a small sample of random a,b,c,d,t2 – Peter Lindsay Apr 16 '15 at 12:15

Consider the following (complicated!) function:

tr[a_, b_, c_, d_][x_] := (b x)/d + (a/Sqrt[c^2 - d^2])
((x - 2 ArcTan[(d Sin[x])/(c + Sqrt[c^2 - d^2] + d Cos[x])])) -
(b c/(d Sqrt[c^2 - d^2])) (x - 2 ArcTan[((c + d - Sqrt[c^2 - d^2])
(1 + Cos[x]) Sin[x])/(c + d + (c + d) Cos[x]*(2 + Cos[x]) +
Sqrt[c^2 - d^2] Sin[x]^2)])


with the following property:

D[tr[a, b, c, d][x], x] // Simplify
(a + b Cos[x])/(c + d Cos[x])


It can be shown that tr[a, b, c, d][x] is the antiderivative that is continuous over the real line. As already noted by Artes, since the integral considered in the OP runs over the entire period of the function, the phase shift is in fact immaterial; thus, evaluating the integral goes like this:

tr[a, b, c, d][2 π] - tr[a, b, c, d][0] // Simplify
(2 (a d + b (-c + Sqrt[c^2 - d^2])) π)/(d Sqrt[c^2 - d^2])

-

I'm using the version 10.2.0 and I get the result as:

Integrate[(a + b*Cos[t1 - t2])/(c + d*Cos[t1 - t2]), {t1, 0, 2 \[Pi]},
Assumptions -> {a \[Element] Reals, b \[Element] Reals, c >= 0,
d <= 0, c + d >= 0, 0 <= t2 <= 2 \[Pi]}] // AbsoluteTiming
(*
{75.4442,
ConditionalExpression[(
2 (I a d + b (-I c + Sqrt[-c^2 + d^2])) \[Pi])/(d Sqrt[-c^2 + d^2]),
t2 >= \[Pi] && c > 0]}
*)


if we write the denominator as $d\sqrt{c^2-d^2}$ instead of $d\sqrt{d^2-c^2}$, we can omit $i$ in the nominator and so we get the same result as the correct solution of the @Artes's answer, except that the conditions are different

Integrate[(a + b Cos[t1 - \[Pi]/2])/(c + d Cos[t1 - \[Pi]/2]), {t1, 0,
2 \[Pi]},
Assumptions -> (a | b) \[Element] Reals && c >= 0 && d <= 0 &&
c + d >= 0]
(*
ConditionalExpression[(2 (a d + b (-c + Sqrt[c^2 - d^2])) \[Pi])/(
d Sqrt[(c - d) (c + d)]), d < 0 && c + d > 0]
*)


$\text{ConditionalExpression}\left[\frac{2 \pi \left(i a d+b \left(\sqrt{d^2-c^2}-i c\right)\right)}{d \sqrt{d^2-c^2}},\text{t2}\geq \pi \land c>0\right]$
$\text{ConditionalExpression}\left[\frac{2 \pi \left(a d+b \left(\sqrt{c^2-d^2}-c\right)\right)}{d \sqrt{(c-d) (c+d)}},d<0\land c+d>0\right]$