4
$\begingroup$
Plot[Cos[x]/(1 - Cos[x] + 0.25), {x, 0, 2*Pi}]

The graph is easily seen to be symmetric about $\pi$.

But

Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, 0, Pi}]

gives the correct answer of 2.0944 but

Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, Pi, 2*Pi}]

outputs -8.37758

It turns out that

Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, 0, 2*Pi}]

does work giving double the previous answer: 4.18879

Why??? This is driving me insane.

$\endgroup$
3
  • $\begingroup$ I'm not sure why it gives bad result, but it is generally considered a bad idea to use inexact numbers with symbolic computation. Use 1/4, not 0.25. $\endgroup$
    – Szabolcs
    Feb 10, 2018 at 12:11
  • $\begingroup$ @Szabolcs That fixes it... thank you. Very strange! $\endgroup$
    – user85798
    Feb 10, 2018 at 12:11
  • $\begingroup$ Be aware that your integrand changes sign in the integration range. With Mathematica v11 the two integrals evaluate to 2.0944 which seems to be true Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, 0, Pi}] == Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, Pi, 2 *Pi}] (* True*). $\endgroup$ Feb 10, 2018 at 12:14

2 Answers 2

4
$\begingroup$

When you look at your integral, you find the following:

expr = Integrate[Cos[x]/(1 - Cos[x] + 1/4), x];
Plot[expr, {x, 0, 2 Pi}]

Mathematica graphics

The value at Pi is Indeterminate and with this knowledge, it is clear that you need to look at the limit from the right side to calculate your integral correctly:

(expr /. x -> 2 Pi) - Limit[expr, x -> Pi, Direction -> "FromAbove"]
(* (2 π)/3 *)

What Mathematica does instead is that it uses the limit from the wrong side when you use 0.25 instead of exact values

(expr /. x -> 2 Pi) - Limit[expr, x -> Pi, Direction -> "FromBelow"]
N[%]
(* -((8 π)/3) *)
(* -8.37758 *)

That being said, you have to be careful and it is one of those cases where you cannot assume that using Mathematica is an excuse to not think about your problem.

$\endgroup$
2
  • $\begingroup$ Oh boy. Thank you for the insight. $\endgroup$
    – user85798
    Feb 10, 2018 at 12:43
  • $\begingroup$ @bwv869 Btw, my last paragraph should by no means sound accusing. It is serious advice that you look into simple examples like this carefully because they are small enough to see the whole picture. Once you face a difficult problem, you need many of such training sessions to know how to tackle them. For instance, now you should know, why this gives such a vastly different result Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, Pi - .001, 2 Pi}] $\endgroup$
    – halirutan
    Feb 10, 2018 at 13:06
1
$\begingroup$

I can't reproduce the results of the question:

Looking at the integrand

Plot[Cos[x]/(1 - Cos[x] + 1/4), {x, -2 Pi, 2 Pi},GridLines -> {{-2 Pi, -Pi, Pi, 2 Pi}, None}]

enter image description here

I see this function. The "areas" in the ranges [0,Pi] and [Pi,2 Pi] are equal!

Mathematica v11.0.1 confirms

Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, 0, Pi}] ==Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, Pi, 2 *Pi}]
(* True *)

and evaluates both integrals

Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, 0, Pi}](*2.0944*)
Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, Pi, 2 *Pi}](*2.0944*)

The sum of both gives

Integrate[Cos[x]/(1 - Cos[x] + 0.25), {x, 0, 2 *Pi}](*4.18879==2*2.0944*)
$\endgroup$
4
  • 1
    $\begingroup$ I can reproduce it in M11.2. The second number in the version is just as relevant as the first. There's as much difference between M11.0 and M11.1 as there was between M10.4 and M11.0. It's best to state at least the first two part of the version every time. $\endgroup$
    – Szabolcs
    Feb 10, 2018 at 13:41
  • $\begingroup$ Thanks. My version is 11.0.1. Perhaps I should wait with the update ;-) $\endgroup$ Feb 10, 2018 at 13:49
  • $\begingroup$ halirutan showed that the problem is that with the inexact number the limit is taken from the wrong side. I think M11.1 introduced big changes (and many improvements) for limits. $\endgroup$
    – Szabolcs
    Feb 10, 2018 at 13:53
  • $\begingroup$ Looking at the integrand the jump-effect is surprising for me. Checking numerically Table[NIntegrate[ Cos[x]/(1 - Cos[x] + 1/4), {x, 0, Pi + \[CurlyEpsilon]}] , {\[CurlyEpsilon], -.001, .001 , .001} ](*{2.09484, 2.0944, 2.09395}*) seems to confirm my expectation. $\endgroup$ Feb 10, 2018 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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