# Integrating Sin[x]^k for positive integer k?

I am looking to integrate some expressions containing trigonometric functions raised to general powers (which get messy, I know). However, I am struggling to make much headway.

As a simple test case, consider

Integrate[Sin[x]^k, x]


For k = 2 the result we should obtain is

Integrate[Sin[x]^2, x]

x/2 - 1/4 Sin[2 x]

Plot[x/2 - 1/4 Sin[2 x], {x, 0, 2 π}]


Now to try for general k, then afterwards set k = 2 and hope to recover the above simple result. Note, I am only ever interested in integers k >= 1.

int = Integrate[Sin[x]^k, x]

-Cos[x] Hypergeometric2F1[1/2, (1 - k)/2, 3/2, Cos[x]^2]
Sin[x]^(1 + k) (Sin[x]^2)^(1/2 (-1 - k))

Plot[int /. k -> 2, {x, 0, 2 π}]


The result isn't the same...?

Can anyone point me in the right direction for how to correctly integrate Sin[x]^k / shed some light on whats going awry here?

• As far as I understand it, the power $\sin ^k x$ is a complex number if $\sin x <0$ and $k>0$. This causes a problem. Commented Jan 30, 2017 at 19:38
• This is well understood. I'll try to find the blog post somewhere, but that second result is an antiderivative of the function, because they can be discontinuous. You have to be careful with indefinite integrals. Commented Jan 30, 2017 at 19:48
• But anyway, do the definite integral version: Integrate[Sin[xt]^2, {xt, 0, x}]. Commented Jan 30, 2017 at 19:48
• Maybe it's this one? Commented Jan 30, 2017 at 19:50
• Perhaps I should have stressed that I am only interested in k ∈ Integers and k >= 1 - i.e. no chance of complex numbers. Commented Jan 30, 2017 at 21:26

Assuming you always want $k$ to be an integer, you could run TrigReduce on the function before integrating:

f[x_, k_Integer] := Integrate[TrigReduce[Sin[x]^k], x]

f[x, 2]
(* x/2 - 1/4 Sin[2 x] *)

f[x, 5]
(* -((5 Cos[x])/8) + 5/48 Cos[3 x] - 1/80 Cos[5 x] *)


Since these results only contain nicely behaved sine & cosine formulas, they will not have any discontinuities.

Internally, BTW, Mathematica is probably using some version of the following identities to apply TrigReduce:

$$\sin^{2n-1} A = \frac{(-1)^{n-1}}{2^{2n-2}} \left[ \sin (2n - 1)A - {2n-1 \choose 1} \sin (2n - 3) A + \cdots (-1)^{n-1} {2n-1 \choose n-1} \sin A\right]$$ $$\sin^{2n} A \\= \frac{1}{2^{2n}} {2n \choose n} + \frac{(-1)^{n}}{2^{2n-1}} \left[ \cos 2nA - {2n \choose 1} \cos (2n - 2) A + \cdots (-1)^{n-1} {2n \choose n-1} \cos 2 A\right]$$ These identities can be most easily derived by writing $\sin^k x = [(e^{ix} - e^{-ix})/2i]^k$, expanding via the binomial theorem, and pairing off terms of the form $e^{inx}$ and $e^{-inx}$. It would be easy enough to write down an exact expression for the integrals of these sums.

• The Wolfram Functions site has these formulae of course. Commented Jan 31, 2017 at 3:47

There is a substitute:

int1=Integrate[Sin[t]^k, t,Assumptions -> t >= Pi && k>0] + Integrate[Sin[t]^k, {t, 0, Pi}]


ConditionalExpression[(Sqrt[[Pi]] Gamma[(1 + k)/2])/Gamma[1 + k/2] - Cos[t]*Hypergeometric2F1[1/2, (1 - k)/2, 3/2, Cos[t]^2] Sin[t]^( 1 + k) (Sin[t]^2)^(1/2 (-1 - k)), Re[k] > -1]

p = Plot[int1 /. k -> 2, {t, Pi, 2*Pi}]


and so on, e.g.

int2=Integrate[Sin[t]^k,t,Assumptions ->t>= 2*Pi && k>0]+ Integrate[Sin[t]^k,{t, 0, 2*Pi}]


Addition. The above is a shifted plot of

x/2 - 1/4 Sin[2 x]

on $[\pi,2\pi]$.

I think the following should work:

f[n_Integer?Positive,x_]:=If[EvenQ[n],
-Cos[x] Hypergeometric2F1[1/2,1/2-n/2,3/2,Cos[x]^2] Sign[Sin[x]] +
(Sqrt[\[Pi]] Gamma[(1+n)/2] (1+2 Floor[x/\[Pi]] HeavisideTheta[x]))/(2 (n/2)!),
-Cos[x] Hypergeometric2F1[1/2,1/2-n/2,3/2,Cos[x]^2]
]


Check :

With[{k=10},Plot[Evaluate[f[k,x]- Integrate[Sin[x]^k,x]],{x,0,10Pi}]]
With[{k=11},Plot[Evaluate[f[k,x]- Integrate[Sin[x]^k,x]],{x,0,10Pi}]]