3

All,

I was enjoying sum to product trig identities in Mathematica, smiling that it was going well, producing the same answers trig students get by hand.

Sin[α] + Sin[β] // TrigFactor

Answer:

2 Cos[α/2 - β/2] Sin[α/2 + β/2]

And my first example:

Sin[5 θ] - Sin[3 θ] // TrigFactor // Simplify

Answer:

2 Cos[4 θ] Sin[θ]

But then:

Cos[3 θ] + Cos[2 θ] // TrigFactor // Simplify

Answer:

2 Cos[θ/2]^2 (1 - 2 Cos[θ] + 2 Cos[2 θ])

Where the expected answer is $2\cos\frac{5\theta}{2}\cos\frac{\theta}{2}$.

Suggestions?

David
  • 14,883
  • 4
  • 44
  • 117
  • 1
    This doesn't really help but it is at least satisfying to note that 2 Cos[(5 \[Theta])/2] Cos[ \[Theta]/2] // TrigReduce results in Cos[2 \[Theta]] + Cos[3 \[Theta]] – Jack LaVigne Oct 08 '15 at 19:11

1 Answers1

10

As the TrigFactor help page says under Possible issues:

A trigonometric expression can be factored in many different ways

Looking at the Wikipedia page of trigonometric identies you can find many identities that can apply. For instance, there are double and triple angle identities that seem directly relevant in your Cos[3 θ] + Cos[2 θ] case.

If you want Mathematica to use a specific identity you could define a rule of your own:

cosSum = Cos[a_] + Cos[b_] :> 2 Cos[(a + b)/2] Cos[(a - b)/2];

Cos[3 θ] + Cos[2 θ] /. cosSum
(* 2 Cos[θ/2] Cos[(5 θ)/2] *)

In slightly more complex situations this might apply differently than you intended:

Cos[p] + Cos[3 θ] + Cos[2 θ] /. cosSum
(* Cos[3 θ] + 2 Cos[1/2 (p - 2 θ)] Cos[1/2 (p + 2 θ)] *)

Mathematica picks the first match it can find, but because p is not evidently related to 2 θ that doesn't yield a very useful result.

Let's define a rule that only applies if the two cosines have arguments that are integer multiples of a common term:

cosSumMul = Cos[a_] + Cos[b_] /; Head[a/b] == Rational :> 2 Cos[(a + b)/2] Cos[(a - b)/2];

Applying the modified rule:

Cos[p] + Cos[3 θ] + Cos[2 θ] /. cosSumMul
(* Cos[p] + 2 Cos[θ/2] Cos[(5 θ)/2] *)

Different order:

Cos[3 θ] + Cos[p] + Cos[2 θ] /. cosSumMul
(* Cos[p] + 2 Cos[θ/2] Cos[(5 θ)/2] *)
Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323