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

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

I am requesting a code in Wolfram Mathematica so as to write the non negativity restrictions of $$a$$ and $$b$$ and to find an answer for the above integral in terms of Hypergeometric functions or other functions.

Sorry, I am new to Wolfram Mathematica.

Any help would be appreciated.

• Did you try the Integrate command? V 13.2 can do it. Here is the command ClearAll[a, b, x]; Integrate[Cos[x]^a*Sin[b*x], {x, 0, Pi/2}, Assumptions -> {a >= 0, b >= 0}] It gives !Mathematica graphics Mar 11 at 13:03
• FullSimplify gives same thing. Hypergeometric2F1[1, (1/2)*(2 + a - b), (1/2)*(2 - a - b), -1]/(a + b) + Hypergeometric2F1[1, (1/2)*(2 + a + b), (1/2)*(2 - a + b), -1]/(-a + b) + (2^(-1 - a)*Pi*Gamma[1 + a]*Sin[b*Pi])/((-Cos[a*Pi] + Cos[b*Pi])*Gamma[(1/2)*(2 + a - b)]*Gamma[(1/2)*(2 + a + b)]) screen shot !Mathematica graphics Mar 11 at 13:15
• @Nasser Thank you so much. But then when $a=0$ and $b=0$, we have by direct computation by hand, $I(a,b)=\pi/2$ but in the answer given by mathematica it has $(a+b)$ and $(a-b)$ in the denominator, which makes $I(a,b)$ not defined for $a=0,b=0$. Please see if I am missing something trivial.
– Max
Mar 11 at 13:19
• Re ÷ 0: Have you heard of Limit? -- "Please do 'full simplify'": Sheesh! Look it up. Mar 11 at 13:24
• @MichaelE2 Sorry, but what do you mean by "Re" in Re÷0?
– Max
Mar 11 at 13:33

For $$0\le x \le {\pi\over2}$$, $$a\ge0$$, $$b\ge0$$, we have $$0 \le \cos x \le 1$$ and $$0 \le \sin bx \le bx$$, and therefore the integrand is bounded by $$0 \le \cos^a x \sin bx \le bx$$ and the integral by $$0 \le I(a,b) \le {\pi ^2 \over 8}\,b$$, which is also the asymptotic value as $$a\rightarrow0, b\rightarrow0$$.

• Thanks a lot for your valuable inputs.
– Max
Mar 11 at 15:53

This is getting too long to keep using comments. You need to use Limits for the special cases, then it works

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


Limit[sol, {a -> 0, b -> 0}]


i.e. do not do

 sol /. {a -> 0, b -> 0}


Tried Maple 2023 and it can't solve it. Maxima 5.46 can't do it, giac can't do it. Sympy can't do it. Tried Fricas 1.3.8 and it also can't solve it, it says:

(1) -> integrate(cos(x)^a*sin(b*x),x=0..%pi/2)
(1)  "potentialPole"


So far only Mathematica can integrate it and says the answer is zero when a->0,b->0. Rubi is not meant to be used on definite integration.

see if we can get the answer of that limit as π/2

I do not know why you think the limit should be Pi/2 as a->0,b->0

Just plotting the integrand as a->0,b->0 shows clearly that area under the curve is shrinking more and more to zero. Since integration is the area under the curve, then zero seems like the correct result.

Manipulate[
Plot[Cos[x]^a*Sin[b*x], {x, 0, Pi/2},
PlotRange -> {Automatic, {0, 1}}],
{{a, 2, "a"}, 2, 0.01, -0.01, Appearance -> "Labeled",
ContinuousAction -> False},
{{b, 2, "b"}, 2, 0.01, -0.01, Appearance -> "Labeled",
ContinuousAction -> False},
TrackedSymbols :> {a, b}

]

• See(wolframalpha.com/…) I am getting limit does not exists
– Max
Mar 11 at 13:40
• @Max I can't answer why Mathematica does not give $\frac{\pi}{2}$ and if its answer is correct or not. I assume that zero is correct answer since that is what it gives. If you think this is the wrong answer, it could be a bug. I do not know myself now. I tried Maple to compare, but Maple can not solve it. Mar 11 at 13:47
• So the limit of I(a,b) as a→0,b→0 is indeterminate? No. The limit is zero. It is when you plugin in $a=0,b=0$ that you get indeterminate. You need to use the Limit command instead. Mar 11 at 13:52
• Ok then please see if we can get the answer of that limit as $\pi/2$.
– Max
Mar 11 at 14:14
• Ok. My bad. I got it now. Thanks a lot.:)
– Max
Mar 11 at 15:36
Clear["Global*"]


When b == a the integral simplifies to

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

(* -2^(-1 - a) (E^(I a π) Beta[-1, -a, 1 + a] + π Cot[a π]) *)

Plot[int[a], {a, 0, 20}]


Near a == 0

Plot[int[a], {a, 0, 1/100}, WorkingPrecision -> 25]


This is consistent with the other answers that show the limit is zero.

EDIT: To find the maximum

argMax = FindRoot[int'[a] == 0, {a, 3/2}, WorkingPrecision -> 20] // N

(* {a -> 1.4304} *)

max = int[a] /. argMax // Chop

(* 0.522152 *)

• Thank you. Your answer is awesome. I have a question. In the answer we have complex numbers involved, but the integral was real. How to get a real answer? Do we have to take the real part of the answer?
– Max
Mar 11 at 17:50
• The presence of the complex constant I does not mean that the expression is complex. If it were complex, the plot would not show. However, when evaluating--for the cancellation of the imaginary parts to occur precisely enough--precision control is generally required. In the second plot, a WorkingPrecision was specified to switch from machine precision to arbitrary-precision. If instead you use Plot[int[a], {a, 0, 1/100}] there are gaps in the plot were the lack of precision results in complex artifacts. In that case, Re could be used to remove the artifacts. Mar 11 at 18:30
• Thanks. Then how do we get a real answer from the result? Do we have to take real parts?
– Max
Mar 11 at 18:54
• int[a] is real for a >= 0; it merely appears complex. You can, for example, use int[0.1] // Real or int[0.1] // Chop` to remove the negligible artifacts. Mar 11 at 19:14