I have a function defined within the domain 0<=x<=2*Pi.

f = Cos[x] * (a - 1 - r*Cos[x])^1.5 on the domain: ArcCos[(a-1)/r] < x < 2*Pi-ArcCos[(a-1)/r]

f = 0 elsewhere

'a' and 'r' are constants. I need to find the area under this curve from 0 to 2 Pi. Mathematically this is the same as saying:

Integrate[Cos[x] * (a - 1 - r*Cos[x])^1.5, {x, ArcCos[(a-1)/r], 2*Pi-ArcCos[(a-1)/r]}]

Sadly Mathematica struggles to evaluate this correctly. So I tried investigating by plotting the first part of the function f (using a=0.1, r=4) and plotting its indefinite integral (call it g). The function g looks incorrect because it has a discontinuity at Pi. Since it's the area under the curve f you'd expect g(x) < 0 and continuous within this domain.

I'm no expert at Matheamtica so I don't want to claim it's a bug, but if someone can help me find out what I'm doing wrong or help me find the area under the curve then I would be very appreciative!

function f. Notice it is real in between where it is defined

function g. Notice it is discontinuous at Pi. The curve looks incorrect!

  • 1
    $\begingroup$ Please, post always all code in copyable form (and not as images - although images of the plots are very welcome). That makes it easier for other users to help you. $\endgroup$ Feb 24 '19 at 17:58

Making use of the natural assumptions on a and r, one obtains a correct result by

j = Integrate[Cos[x]*(a - 1 - r*Cos[x])^3/2, {x, ArcCos[(a - 1)/r], 
2*Pi - ArcCos[(a - 1)/r]}, Assumptions -> -1 < (a - 1)/r < 1]

A long output is omitted. One verifies it by

j /. {a -> 0.1, r -> 4}

-15.806-4.44089*10^-16 I


a=0.1;r=4;NIntegrate[Cos[x]*(a-1-r*Cos[x])^3/2, {x,ArcCos[(a - 1)/r],2*Pi-ArcCos[(a-1)/r]}]


  • 1
    $\begingroup$ You get a simpler form using j = Assuming[-1<(a-1)/r<1, Integrate[Cos[x]*(a-1-r*Cos[x])^3/2, {x, ArcCos[(a-1)/r], 2*Pi-ArcCos[(a-1)/r]}] // ComplexExpand[#, TargetFunctions -> {Re, Im}]& // Simplify]. Then, j /. {a->1/10, r->4} // FullSimplify and % // N $\endgroup$
    – Bob Hanlon
    Feb 24 '19 at 19:29
  • $\begingroup$ @Bob Hanlon: Thank you for your valuable simplification. $\endgroup$
    – user64494
    Feb 24 '19 at 19:49
  • $\begingroup$ Matthew: user64494 and Bob Hanlon didn't mention this explicitly, but note that one of the changes they made was to replace 1.5 with 3/2. This is because, as a general rule, one gets better results with symbolic integrations in Mathematica by replacing all approximate (decimal) numbers with "exact" numbers. $\endgroup$
    – theorist
    Feb 25 '19 at 8:11

Your Answer

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

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