A continuous function over $\Bbb R$ has a primitive that is also continuous over $\Bbb R$.

However, it often happens with Mathematica and other CAS that the result is not continuous, especially with trigonometric integrals computed with the Weierstrass substitution. The result can't be correct because from a periodic integrand this substitution leads to a periodic primitive, while the primitive over $\Bbb R$ is not periodic in general.

For instance:

In[1]:= Integrate[3/(5 - 4 Cos[x]), x]
Out[1]= 2 ArcTan[3 Tan[x/2]]

My question: Is there a way in Mathematica (an option, a package...) to obtain a continuous primitive in this case?

A correct one could be:

$$x + 2 \arctan\left(\frac{\sin x}{2 - \cos x}\right)$$

There are publications about this:

See also this related question on Math.SE.

I wonder if Mathematica has implementations of the methods mentioned in those articles.


Yes, it is possible. First compute in a standard way

Integrate[3/(5-4 Cos[x]),x]
(*2 ArcTan[3 Tan[x/2]]*)
Plot[2 ArcTan[3 Tan[x/2]],{x,-10π,10π}]

enter image description here

Now try the Rubi package

Int[3/(5-4 Cos[x]),x]
(*x+2 ArcTan[Sin[x]/(2-Cos[x])]*)
Plot[x+2 ArcTan[Sin[x]/(2-Cos[x])],{x,-10π,10π}]

enter image description here

  • 2
    $\begingroup$ Also Integrate[3/(5 - 4 Cos[t]), {t, 0, x}, Assumptions -> x \ [Element] Reals] does the job, producing 2 \ [Pi] IntegerPart[x/(2 \ [Pi])]+3 ([Piecewise] -(2/3) (\ [Pi]-ArcTan[3 Tan[x/2]]) FractionalPart[x/(2 \ [Pi])]<=-(1/2) 2/3 ArcTan[3 Tan[x/2]] -(1/2)<FractionalPart[x/(2 \ [Pi])]<1/2 2/3 (\ [ Pi]+ArcTan[3 Tan[x/2]]) True $\endgroup$ – user64494 Feb 14 '20 at 17:31
  • $\begingroup$ Exactly what I was looking for! Thank you. $\endgroup$ – user69708 Feb 14 '20 at 18:10
  • 1
    $\begingroup$ @user64494 Not as simple, but indeed it works. It's the natural way to make the standard solution continuous by hand, by adding a constant on each subinterval. I thought I tried, but I probably forgot the assumption. $\endgroup$ – user69708 Feb 14 '20 at 18:14
  • 2
    $\begingroup$ Rubi works also on the algebraic case of Risch algorithm, which is quite impressive: Int[x/Sqrt[x^4 + 10 x^2 - 96 x - 71], x] (example from Wikipedia). $\endgroup$ – user69708 Feb 14 '20 at 18:17

Integrate[f[x], x] gives an antiderivative whose derivative is generically equal to f[x]. From the docs:

For indefinite integrals, Integrate tries to find results that are correct for almost all values of parameters.

A primitive function of a continuous function $f$ such as the OP seeks is given by $$F(x) = \int_a^x f(t) \; dt \,.$$

prim = Integrate[3/(5 - 4 Cos[t]), {t, 0, x}, 
  Assumptions -> -Infinity < x < Infinity]

Mathematica graphics

Plot[prim, {x, -30, 30}]

Mathematica graphics

  • $\begingroup$ It's enough Assumptions -> -Infinity < x or Assumptions -> x < Infinity in the above. This is the same as x \ [Element] Reals $\endgroup$ – user64494 Feb 16 '20 at 7:18

Your Answer

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