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.

The following command does what I want:

TrigExpand[ Cos[a + b]^2]

(* 1/2 + 1/2 Cos[a]^2 Cos[b]^2 - 1/2 Cos[b]^2 Sin[a]^2 - 
   2 Cos[a] Cos[b] Sin[a] Sin[b] - 1/2 Cos[a]^2 Sin[b]^2 + 
   1/2 Sin[a]^2 Sin[b]^2 *)

Unfortunately, it does not apply the distributive property of the product in another case, that is the one I am interested in:

TrigExpand[ Cos[c*(a + b)]^2]

(*  Cos[c*(a + b)]^2  *)

How can I tell Mathematica to do that initial step?

share|improve this question
    
Try TrigReduce[Cos[c*(a + b)]^2], it yields 1/2 (1 + Cos[2 (a + b) c]) –  Artes Jul 16 '13 at 18:11
    
Sure, but that's not the result I want, which must be in terms of Cos[a*c] and Sin[b*c], like the first one above. –  flebool Jul 16 '13 at 18:24

2 Answers 2

up vote 3 down vote accepted

With some clarification in the comments you expect the result in terms of Sin[a c] and Cos[a c]. For this purpose one can use MapAll (a shorthand //@). It is not so common as Map (/@) but sometimes it can be very handy:

TrigExpand //@ ( Cos[c (a + b)]^2)
1/2 + 1/2 Cos[a c]^2 Cos[b c]^2 - 1/2 Cos[b c]^2 Sin[a c]^2 
 - 2 Cos[a c] Cos[b c] Sin[a c] Sin[b c] - 1/2 Cos[a c]^2 Sin[b c]^2 
 + 1/2 Sin[a c]^2 Sin[b c]^2
share|improve this answer
    
you get the endresult if you use MapAll in its non-shorthand form...MapAll[TrigExpand, Cos[c (a + b)]^2] –  Stefan Jul 16 '13 at 19:55
    
Thanks, both of you, Map and MapAll will be useful in many situations. For curiosity, do you know why the non-shorthand form behaves differently? –  flebool Jul 16 '13 at 21:00
1  
@Stefan It hasn't been the reason, just only overlooked braces (). Thanks for pointing it out. –  Artes Jul 16 '13 at 22:17
    
@flebool Look at the edit, the shorthand form works correctly. –  Artes Jul 16 '13 at 22:18
    
@Artes ah. ok :) i've overseen it as well...was already confused about the different results. –  Stefan Jul 16 '13 at 22:24

Artes' method is pleasingly concise, because it uses TrigExpand to expand c*(a + b) to a c + b c by mapping it to that specific part. Another approach is to use ExpandAll:

ExpandAll[expr] expands out all products and integer powers in any part of expr.

Cos[c*(a + b)]^2 // ExpandAll // TrigExpand
1/2 + 1/2 Cos[a c]^2 Cos[b c]^2 - 1/2 Cos[b c]^2 Sin[a c]^2 - 
 2 Cos[a c] Cos[b c] Sin[a c] Sin[b c] - 1/2 Cos[a c]^2 Sin[b c]^2 + 
 1/2 Sin[a c]^2 Sin[b c]^2

This may be somewhat faster on large expressions.

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.