7
$\begingroup$

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)} // 
  Simplify // TraditionalForm

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|$$.

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

4 Answers 4

8
$\begingroup$

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

enter image description here

$\endgroup$
8
$\begingroup$

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}]

Mathematica graphics

$\endgroup$
6
  • $\begingroup$ how does this differ from Simon's answer? mathematica.stackexchange.com/questions/434/… $\endgroup$
    – chris
    Oct 17, 2012 at 16:07
  • $\begingroup$ @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) $\endgroup$ Oct 17, 2012 at 16:09
  • $\begingroup$ and why does it return a list? $\endgroup$
    – chris
    Oct 17, 2012 at 16:12
  • $\begingroup$ @chris Because the signs of radicals are taken in account. Try trigSet[Sin[x] Cos[x], sin] and plot the results $\endgroup$ Oct 17, 2012 at 16:14
  • $\begingroup$ 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]) $\endgroup$ Oct 17, 2012 at 16:22
6
$\begingroup$

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.

$\endgroup$
6
$\begingroup$

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

enter image description here

$\endgroup$
6
  • $\begingroup$ Your answer does not contain absolute value. I do not understand. $\endgroup$ Oct 18, 2012 at 12:27
  • $\begingroup$ I added this assumption : t > -1, so there is not need for the absolute value. $\endgroup$
    – Artes
    Oct 18, 2012 at 12:32
  • $\begingroup$ In general, how to calculate the given integral? Please help me. $\endgroup$ Oct 18, 2012 at 12:33
  • $\begingroup$ I want the ansewr is $\ln\left|1 + \tan\dfrac{x}{2}\right| $\endgroup$ Oct 18, 2012 at 14:21
  • $\begingroup$ @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]]. $\endgroup$
    – Artes
    Oct 21, 2012 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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