# How to transform the result of this integral into powers of $\sin\,x$?

I want to calculate the integral $I = \displaystyle\int{\cos ^5 x\, \mathrm dx}$. Using the variable $t = \sin x$, I get $$I = \sin x - \frac{2}{3}\sin^3 x + \frac{1}{5}\sin^5 x + C.$$ With Mathematica, when I input

 Integrate[Cos[x]^5, x]


I get

(5 Sin[x])/8 + 5/48 Sin[3 x] + 1/80 Sin[5 x]


How to format the result in the form? $$I = \sin x - \frac{2}{3}\sin^3 x + \frac{1}{5}\sin^5 x.$$

Similar questions with integral $I =\displaystyle \int{\dfrac{\mathrm{d}x}{1 + \sin x + \cos x}}$ by setting $t = \tan\dfrac{x}{2}$, we have $I = \ln \left|1 + \tan\dfrac{x}{2}\right|$. I tried

(Integrate[1/(1 + Sin[x] - Cos[x]), x] // TrigExpand) /. {Sin[x] ->
2*Tan[x/2]/(1 + Tan[x/2]^2),
Cos[x] -> (1 - Tan[x/2]^2)/(1 + Tan[x/2]^2)} //


and get the result log(sin(x/2)+cos(x/2))-log(cos(x/2)). How to format the result in the form?
$$I = \ln \left|1 + \tan\dfrac{x}{2}\right|$$.

-
I am sorry when I ask the question. –  minthao_2011 Oct 17 '12 at 15:42
using Integrate[Cos[x]^5, x] // TrigExpand // convert[#, Sin[x]] & using the convert function defined in mathematica.stackexchange.com/questions/434/… –  chris Oct 17 '12 at 15:46
@chris TrigExpand is becoming one of my most favorite functions even though I am yet to utilize it! –  drN Oct 17 '12 at 19:01

If you expand your expression in terms of elementary trig functions

Integrate[Cos[x]^5, x] // TrigExpand

(5 Sin[x])/8 + 5/16 Cos[x]^2 Sin[x] + 1/16 Cos[x]^4 Sin[x] - (
5 Sin[x]^3)/48 - 1/8 Cos[x]^2 Sin[x]^3 + Sin[x]^5/80


you will see only even powers of Cos - so it's straightforward to replace it like this:

(Integrate[Cos[x]^5, x] // TrigExpand) /.
Cos[x] -> Sqrt[1 - Sin[x]^2] // Simplify // TraditionalForm


-

One can use Sin[x]^2 + Cos[x]^2 == 1 and the third argument in Solve to eliminate an unwanted dependent variable (i.e. Cos[x]) :

Expand @ Solve[{L == TrigExpand @ Integrate[Cos[x]^5, x], Sin[x]^2 + Cos[x]^2 == 1},
L, {Cos[x]}]


That is useful in more general cases, but with the problem at hand we can observe, that we needn't eliminate Cos[x], e.g. :

Expand [Solve[{L= TrigExpand @ Integrate[Cos[x]^5, x], Sin[x]^2 + Cos[x]^2 == 1}, L]][[1, 1, 2]]

Sin[x] - (2 Sin[x]^3)/3 + Sin[x]^5/5


A bit more reliable variation of Vitaliy's approach :

TrigExpand[ Integrate[Cos[x]^5, x]] /. Solve[Sin[x]^2 + Cos[x]^2 == 1, Cos[x]] //
Simplify // Union


Another approach : let's substitute Cos[x]^n for an even integer n by (1 - Sin[x]^2)^(n/2), e.g.

Simplify[ TrigExpand[ Integrate[Cos[x]^5, x]] /. Cos[x]^n_?EvenQ -> (1 - Sin[x]^2)^(n/2)]


Edit

To proceed with another problem of the OP remembering that Integrate[1/(1 + Sin[x] - Cos[x]), x] and Log @ Abs[1 + Tan[x/2]] are not quite equivalent, we have to assume some restrictions of the variable x. Let x be real in the range where Cos[x/2] + Sin[x/2] > 0 and Cos[x/2] > 0, e.g. Pi > x > -Pi/2, now we have :

Simplify[ Integrate[ 1/(1 + Sin[x] + Cos[x]), x], Pi > x > -Pi/2]

Log[1 + Tan[x/2]]

% // TraditionalForm


-
Your answer does not contain absolute value. I do not understand. –  minthao_2011 Oct 18 '12 at 12:27
I added this assumption : t > -1, so there is not need for the absolute value. –  Artes Oct 18 '12 at 12:32
In general, how to calculate the given integral? Please help me. –  minthao_2011 Oct 18 '12 at 12:33
I want the ansewr is $\ln\left|1 + \tan\dfrac{x}{2}\right| – minthao_2011 Oct 18 '12 at 14:21 @minthao_2011 I hope you see now why you have no absolute value. Mathematica treats variables as complex, so only under some assumptions we can get Log[1 + Tan[x/2]]. – Artes Oct 21 '12 at 6:06 show 1 more comment I'll answer with a more general module I've done for converting trig expressions. An overkill here, but anyway: trigSet[exp_, inTerm_] := Module[{trigSyms, rels, set, setRep, setRep1, toLow, oneInTermsOf, allInTermsOf, fq, ruleAll, convert}, trigSyms = {Sin, Cos, Tan, Cot, Sec, Csc}; rels = {csc sin == 1, cos^2 + sin^2 == 1, 1 == cos sec, tan == sin/cos, cot tan == 1}; set = ToExpression /@ ToLowerCase /@ SymbolName /@ trigSyms; setRep = Thread[set -> (ToExpression /@ (StringJoin[#, "[x_]"] & /@ ToString /@ set))]; setRep1 = Thread[set -> (ToExpression /@ (StringJoin[#, "[x]"] & /@ ToString /@ set))]; toLow = Thread[trigSyms -> set]; oneInTermsOf[one_, of_] := Solve[rels, {one}, Complement[set, {one, of}]]; allInTermsOf[of_] := Flatten[oneInTermsOf[#, of] & /@ Complement[set, {of}]]; fq[x_, y_] := FreeQ[x, Alternatives @@ Complement[set, {y}]]; ruleAll[of_] := Rule @@@ Transpose[{#[[1]] /. setRep, #[[2]] /. setRep1} &@ Transpose@(List @@@ allInTermsOf[of])]; convert[expr_, inTerms_] := FullSimplify@ Union@Select[ Flatten@NestWhile[# /. (List /@ ruleAll[inTerms]) &, {TrigExpand[expr] /. toLow }, ! Or @@ (fq[#, inTerms] & /@ Flatten@#) &], fq[#, inTerms] &]; HoldForm[ Evaluate@convert[exp, inTerm]] /. (Reverse /@ toLow) ] trigSet[(5 Sin[x])/8 + 5/48 Sin[3 x] + 1/80 Sin[5 x], sin] (* -> {Sin[x]-(2 Sin[x]^3)/3+Sin[x]^5/5} *)  Test it with more difficult expressions: trigSet[Cos[3 x] - Tan[2 x] + Cot[3 x]^2, sin]  Edit Depending on your expression, because of the signs in the radicals, you could need more than one "converted" one to cover the whole domain. For example: s = Cos[x] Sin[x]; s0 = trigSet[s, sin] s1 = FullSimplify[Reduce[# == s, x, Reals] & /@ ReleaseHold[s0] /. _Equal -> False] (* {-Sin[x] Sqrt[1-Sin[x]^2],Sin[x] Sqrt[1-Sin[x]^2]} {C[1] \[Element] Integers && ((Pi + x > 2 Pi C[1] && Pi + 2 x <= 4 Pi C[1]) || Pi/2 <= x - 2 Pi C[1] < Pi), C[1] \[Element] Integers && -(Pi/2) <= x - 2 \[Pi] C[1] <= Pi/2} *)  Still working in automating this last process, but you can plot it like: f[x_] := Piecewise[{{-Sin[x] Sqrt[1 - Sin[x]^2], Resolve[Exists[C[1], Element[C[1], Integers], ((Pi + x > 2 Pi C[1] && Pi + 2 x <= 4 Pi C[1]) || Pi/2 <= x - 2 Pi C[1] < Pi)]]}, {Sin[x] Sqrt[1 - Sin[x]^2], Resolve[Exists[C[1], Element[C[1], Integers], -(Pi/2) <= x - 2 \[Pi] C[1] <= Pi/2]]}}]; Plot[{f[x], Sin[x] Cos[x]}, {x, 0, 2 Pi}, PlotStyle -> {{Thick, Dashed, Red}, Blue, Green}]  - how does this differ from Simon's answer? mathematica.stackexchange.com/questions/434/… – chris Oct 17 '12 at 16:07 @chris no idea. Probably in that this code is mine and one can get the domains of validity of each function in case you have more than one result (in different intervals) – belisarius Oct 17 '12 at 16:09 and why does it return a list? – chris Oct 17 '12 at 16:12 @chris Because the signs of radicals are taken in account. Try trigSet[Sin[x] Cos[x], sin] and plot the results – belisarius Oct 17 '12 at 16:14 With trigSet[Cos[x]^4 - Cos[x/2]^2, cos], I get \!(* TagBox[ RowBox[{"{", RowBox[{"1", "-", RowBox[{"9", " ", SuperscriptBox[ RowBox[{"Cos", "[", FractionBox["x", "2"], "]"}], "2"]}], "+", RowBox[{"24", " ", SuperscriptBox[ RowBox[{"Cos", "[", FractionBox["x", "2"], "]"}], "4"]}], "-", RowBox[{"32", " ", SuperscriptBox[ RowBox[{"Cos", "[", FractionBox["x", "2"], "]"}], "6"]}], "+", RowBox[{"16", " ", SuperscriptBox[ RowBox[{"Cos", "[", FractionBox["x", "2"], "]"}], "8"]}]}], "}"}], HoldForm]) – minthao_2011 Oct 17 '12 at 16:22 show 1 more comment It's somewhat convenient to use Chebyshev polynomials for such purposes. Here, I use the Chebyshev polynomial of the second kind, due to the convenient identity $$U_n(\cos\,x)=\frac{\sin((n+1)x)}{\sin\,x}$$ Here goes: Integrate[Cos[x]^5, x] /. Sin[n_Integer x] :> Sin[x] ChebyshevU[n - 1, Sqrt[1 - Sin[x]^2]] // Expand Sin[x] - (2 Sin[x]^3)/3 + Sin[x]^5/5  For completeness, the relation$T_n(\cos\,x)=\cos\,nx\$ can be similarly exploited. I use that in this answer.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7554886937141418, "perplexity": 5891.150315936602}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-10/segments/1394010824553/warc/CC-MAIN-20140305091344-00065-ip-10-183-142-35.ec2.internal.warc.gz"}