Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to expand the following expression into powers of $\cos(u)$ only:

a1 + a2 Cos[2 u] + a3 Cos[4 u] + a4 Cos[6 u]

The answer that I want (and which I found by hand) is :

(a1 + a3 - a2 - a4) + (2 a2 - 8 a3 + 18 a4) Cos[u]^2 + (8 a3 - 48 a4) Cos[u]^4 + (32 a4) Cos[u]^6

As you see it contains only powers of $\cos (u)$. But when I use the TrigExpand, which is supposed to simplify the expression into powers of trigonometric functions, it gives this:

1 + a2 Cos[u]^2 + a3 Cos[u]^4 + a4 Cos[u]^6 - a2 Sin[u]^2 - 6 a3 Cos[u]^2 Sin[u]^2 
- 15 a4 Cos[u]^4 Sin[u]^2 + a3 Sin[u]^4 + 15 a4 Cos[u]^2 Sin[u]^4 - a4 Sin[u]^6

Is it possible to make TrigExpand to simplify only in terms of $\cos (u)$ or $\sin (u)$? (or maybe using another command instead of TrigExpand)

By the way, It is my first work done in Mathematica.

share|improve this question
1  
Could use post-process the TrigExpand with PolynomialReduce in order to exchange one trig in favor of the other. In[8]:= PolynomialReduce[TrigExpand[expr], Sin[u]^2 + Cos[u]^2 - 1, Cos[u]][[2]] Out[8]= a1 + a2 + a3 + a4 - 2 a2 Sin[u]^2 - 8 a3 Sin[u]^2 - 18 a4 Sin[u]^2 + 8 a3 Sin[u]^4 + 48 a4 Sin[u]^4 - 32 a4 Sin[u]^6 –  Daniel Lichtblau Jun 6 at 14:14

2 Answers 2

up vote 4 down vote accepted
expr = a1 + a2 Cos[2 u] + a3 Cos[4 u] + a4 Cos[6 u];

(expr // TrigExpand) /. Sin[x_] -> (1 - Cos[x]^2)^(1/2) // Collect[#, Cos[_]] &

a1 - a2 + a3 - a4 + (2 a2 - 8 a3 + 18 a4) Cos[ u]^2 + (8 a3 - 48 a4) Cos[u]^4 + 32 a4 Cos[u]^6

(expr // TrigExpand) /. Cos[x_] -> (1 - Sin[x]^2)^(1/2) // Collect[#, Sin[_]] &

a1 + a2 + a3 + a4 + (-2 a2 - 8 a3 - 18 a4) Sin[ u]^2 + (8 a3 + 48 a4) Sin[u]^4 - 32 a4 Sin[u]^6

share|improve this answer
    
Thanks. Can you explain a little what the code does? –  user215721 Jun 6 at 13:32
1  
After TrigExpand, ReplaceAll is used with a trig identity to remove undesired trig functions, then like terms are collected. In Mathematica, highlight a function or operator then press F1 for additional information. –  Bob Hanlon Jun 6 at 13:45

Some alternative approaches can be found in How to expand tan(x+y) as normal form. Here is my answer from that link, applied to your expression:

expr = a1 + a2 Cos[2 u] + a3 Cos[4 u] + a4 Cos[6 u];

Simplify[TrigExpand[expr /. u -> ArcSin[a]]] /. a -> Sin[u]

(*
==> a1 + a2 + a3 + a4 - 2 a2 Sin[u]^2 - 8 a3 Sin[u]^2 - 
 18 a4 Sin[u]^2 + 8 a3 Sin[u]^4 + 48 a4 Sin[u]^4 - 32 a4 Sin[u]^6
*)

You can also add

Collect[%, Sin[u]]
(*
==> a1 + a2 + a3 + a4 + (-2 a2 - 8 a3 - 18 a4) Sin[
   u]^2 + (8 a3 + 48 a4) Sin[u]^4 - 32 a4 Sin[u]^6
*)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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