# Evaluate $\int_{0}^{\pi/2} \cos^a (x)\sin(ax) dx$ using Mathematica

Consider the integral $$I(a)=\int_{0}^{\pi/2} \cos^a (x)\sin(ax) dx$$ where $$a\geq 0$$

I am trying to evaluate the above integral using Mathematica using the following code :

int[a_] = Assuming[a >= 0,
Integrate[Cos[x]^a*Sin[a*x], {x, 0, Pi/2}] // FullSimplify]


The answer we get is -2^(-1 - a) (E^(I a π) Beta[-1, -a, 1 + a] + π Cot[a π])

Problem is that the definite integral was real for $$a\geq 0$$ but the answer contains imaginary number $$i=\sqrt{-1}$$. How do we get a real answer?

Any help would be appreciated.

answer contains imaginary number i . How do we get a real answer?

Just because the answer contains $$i$$ does not necessarily mean the overall value is also complex. it depends on what is inside the expression (what type of special functions are involved, some cancelations that can occur and so on).

You can see that by plotting the antiderivative for some range of $$a$$, that it does plot OK. It will not have plotted if the result was complex (you would get blank plot if there were complex values anywhere in the result).

 sol = Integrate[Cos[x]^a*Sin[a*x], {x, 0, Pi/2}, Assumptions -> a >= 0]


 Plot[sol, {a, 0, 10}]


In addition, you can evaluate numerically the antiderivative for some $$a$$ values. They are all real

 Table[Limit[sol, a -> a0], {a0, 0.1, 3, .1}] // Chop


You can see that also from evaluating Beta

  Limit[E^(I a Pi) Beta[-1, -a, 1 + a] , a -> 1.2]


It is real value even though there is E^(I a Pi) in there. This happens in this case because the incomplete beta function can generate complex value and this cancels the complex values coming from E^(I a Pi)

 p1= Limit[Beta[-1, -a, 1 + a], a -> 1.2]


  p2 = Limit[E^(I a Pi), a -> 1.2]


  p1*p2


So the rule of the thumb is: Just because an expression has $$i$$ this does not always implies the overall expression value will also be complex. It depends.

– Max
Mar 12, 2023 at 6:06
• What is the limit of the answer as $a\to 0$?
– Max
Mar 12, 2023 at 6:11
• @Max Mathematica can not evaluate the limit as a->0. But it can for any value greater than zero. Limit[Beta[-1, -a, 1 + a], a -> 0] returns unevaluated. It could be due to branch cut at this value. Mar 12, 2023 at 6:13
• Thanks you a lot.
– Max
Mar 12, 2023 at 6:19
• I suspect the Limit limitation arises from Series balking at having the variable of interest appear in more than one argument of Beta. Mar 12, 2023 at 15:25

Workaround: using formula:

$$\sum _{j=1}^a \frac{\binom{a}{j} \sin (2 j x)}{2^a}=\cos ^a(x) \sin (a x)$$ We have:

$$\int_0^{\frac{\pi }{2}} \cos ^a(x) \sin (a x) \, dx=2^{-1-a} \gamma +2^{-1-a} a \, _3F_2(1,1,1-a;2,2;-1)+2^{-1-a} \psi (1+a)$$

The answer not contains imaginary number.

S = Sum[Integrate[Binomial[a, j]*Sin[2 j x ]/2^a, {x, 0, Pi/2}], {j, 1, a}] // Expand

(*2^(-1 - a) EulerGamma + 2^(-1 - a) a HypergeometricPFQ[{1, 1, 1 - a}, {2, 2}, -1] +
2^(-1 - a) PolyGamma[0, 1 + a]*)

Limit[S, a -> 0]
(* 0 *)
S /. a -> 0
(* 0*)


EDITED: 15.03.2023

My formula works for $$a\in \mathbb{R}$$ ,see below:

int[a_?NumericQ] := NIntegrate[Cos[x]^a*Sin[a*x], {x, 0, Pi/2},

• Thanks for your answer. +1. But $a$ is a non negative real number, so the sum cannot run from $j=1$ to $a$. Please help me with this. Most humbly I will accept your answer.
• Thanks a lot. Please show using mathematica or otherwise that for $a\geq 0$, $$\int_0^{\frac{\pi }{2}} \cos ^a(x) \sin (a x) \, dx=2^{-1-a} \gamma +2^{-1-a} a \, _3F_2(1,1,1-a;2,2;-1)+2^{-1-a} \psi (1+a)$$ I will with utmost respect accept your answer