Integrate[2 - Sec[x], {x, 5 Pi/3, 7 Pi/3}]
returns Plus[Times[Complex[Rational[4, 3], 1], Pi], Times[-1, Log[Plus[7, Times[4, Power[3, Rational[1, 2]]]]]]]
, but the value of the integral is real.
-
$\begingroup$ I believe that the Mathematica has transformed the integral, so that the contour of integration encircles a pole of the function. I can't see a good reason why it should do so, but in general (I think) Mathematica feels free to take any path (in the complex plane) between the specified end points. $\endgroup$– mikadoCommented Dec 7 at 18:16
-
$\begingroup$ Is it possible to avoid this? $\endgroup$– Paul RCommented Dec 7 at 18:19
-
2$\begingroup$ Screenshot on v 12.2.0. $\endgroup$– SyedCommented Dec 7 at 18:33
-
$\begingroup$ I use the latest v 14.1. $\endgroup$– Paul RCommented Dec 7 at 18:34
-
2$\begingroup$ Reported as a bug $\endgroup$– Daniel LichtblauCommented Dec 9 at 17:08
4 Answers
Sometimes adding a waypoint to the path of integration keeps things real:
Integrate[2 - Sec[x], {x, 5 Pi/3, 2 Pi, 7 Pi/3}]
(* 1/3 (4 \[Pi] - 3 Log[7 + 4 Sqrt[3]]) *)
Update
Some simple affine transformations yield the correct answer, too:
Integrate[(2 - Sec[x]) Dt[x, t] /. x -> 5 Pi/3 + 2 Pi/3 t, {t, 0, 1}]
% // N
(*
(4 \[Pi])/3 - 2 ArcTanh[Sqrt[3]/2]
1.55487
*)
However, some others, like x -> 2 Pi + t
, fail, even though the similar one x -> 5 Pi/3 + t
succeeds. Often x -> p Pi/ q +t
works for integers p
, q
with q > 1
when in least terms; often (always?) x -> p/q + t
fails. Perhaps in the successful cases, a trig identity leads Mathematica to avoid the troublesome antiderivative pointed out by @mikado.
-
$\begingroup$ Another path that gives the right answer:
Integrate[(2 - Sec[x]) Dt[x, t] /. x -> 2 Pi - Pi/3 Exp[-Pi I t], {t, 0, 1}]
$\endgroup$ Commented Dec 9 at 11:28 -
$\begingroup$ Another success:
Integrate[(2 - Sec[x]) Dt[x, t] /. x -> 5 Pi/3 + 2 Pi/3 t^2, {t, 0, 1}]
-- I would have thought in this case that Mma would substitute back to the original integral. $\endgroup$ Commented Dec 9 at 11:36 -
$Version
(* "14.1.0 for Mac OS X ARM (64-bit) (July 16, 2024)" *)
ClearAll["Global`*"]
int1 = Integrate[2 - Sec[x], {x, 5 Pi/3, 7 Pi/3}]
(* (4/3 + I) \[Pi] - Log[7 + 4 Sqrt[3]] *)
The same problem occurs with Area
int2 = Area[ImplicitRegion[0 < y < 2 - Sec[x] && 5 Pi/3 < x < 7 Pi/3, {x, y}]]
(* 1/6 ((8 + 6 I) \[Pi] - 3 Log[97 + 56 Sqrt[3]]) *)
int1 == int2 // FullSimplify
(* True *)
The workaround is to use TrigToExp
int3 = Integrate[2 - Sec[x] // TrigToExp, {x, 5 Pi/3, 7 Pi/3}]
(* (4 \[Pi])/3 - 2 Log[2 + Sqrt[3]] *)
int3 == Re[int1] // FullSimplify
(* True *)
EDIT: Reported to Wolfram Tech Support (CASE:5205937)
-
$\begingroup$ Without
TrgiToExp
Integrate[2 - Sec[x], {x, 0, Pi/3}]
works fine. WithTrigToExp
the result is complex. $\endgroup$– Paul RCommented Dec 7 at 19:02 -
1$\begingroup$ While it may appear complex, it is real. Look at
Integrate[2 - Sec[x] // TrigToExp, {x, 0, Pi/3}] // ComplexExpand // FullSimplify
$\endgroup$ Commented Dec 7 at 19:06
EDIT: I understand that other versions may give different results, so mentioning the version used
$Version
(* "14.1.0 for Linux x86 (64-bit) (July 16, 2024)"*)
Digging into this, the problem comes down to the expression returned by Mathematica for
Integrate[Sec[x], x]
(* ArcCoth[Sin[x]] *)
Differentiating this does indeed give the expected result
D[%, x] // Simplify
(* Sec[x] *)
Substituting limits into the integral gives the results obtained for definite integrals.
Integrate[Sec[x], {x, 5 Pi/3, 7 Pi/3}] ==
(ArcCoth[Sin[x]] /. x -> 7 Pi/3) - (ArcCoth[Sin[x]] /. x -> 5 Pi/3)
// FullSimplify
(* True *)
However, this expression has the perverse effect that for real values of x
, sin(x)
always lies on the branch cut of ArcCoth
. Consequently, when the sign of sin(x)
changes, it induces a 2 Pi I
discontinuity.
I don't know if an alternative expression for the integral would avoid this problem.
-
1$\begingroup$ Version 13 returns
Integrate[Sec[x], x] == -Log[Cos[x/2] - Sin[x/2]] + Log[Cos[x/2] + Sin[x/2]]
which does not suffer the same problem in this case. $\endgroup$ Commented Dec 8 at 17:44
No problem in my version:
In[9]:= $Version
Out[9]= "11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)"
In[7]:= Integrate[2 - Sec[x], {x, (5 \[Pi])/3, 2 \[Pi], (7 \[Pi])/3}]
% // N
Out[7]= (4 \[Pi])/3 + 2 Log[2 - Sqrt[3]]
Out[8]= 1.55487