How to work out trigonometric identities symbolically?

12 visualizzazioni (ultimi 30 giorni)
Hi.
My input would be
syms w v t
f1 = cos(w*t)
f2 = cos(v*t)
or simliar.
Now I would like to use MATLAB to come to an expression like
f1 * f2 = 0.5 * (cos(w*t - v*t) + cos(w*t + v*t))
But whatever I tried, like
expand(f1*f2)
just gives me again cos(w*t)*cos(v*t), not applying other identities.
  2 Commenti
Torsten
Torsten il 24 Lug 2025
I don't see how you could get what you want. How should MATLAB know which specific "expansion" for the expression you mean ?
Thomas Maletz
Thomas Maletz il 24 Lug 2025
Modificato: Thomas Maletz il 25 Lug 2025
Hi Torsten, thanks, yes, I am aware of that, but this is also true for other situations that are not unique, but where you can guide MATLAB with parameters to a certain direction or asking give me back all you find or similar, that is what I was hoping for.

Accedi per commentare.

Risposta accettata

John D'Errico
John D'Errico il 24 Lug 2025
Modificato: John D'Errico il 24 Lug 2025
There are literally an infinite number of possible results you MIGHT expect for even that simple product. But simplify is able to give you a few choices.
syms w v t
f1 = cos(w*t);
f2 = cos(v*t);
f12 = simplify(f1*f2,steps = 10,all = true)
f12 = 
I stopped at 10 steps. Had I asked it to go more deeply, to say 100 or 1000 steps, I would have gotten all sorts of crap. But somewhere in that mess will usually be what you want. After all, how is simplify to know what you personally think is what you want to see?
But now you can choose the result you want, as
f12(3)
ans = 
Note that you cannot always guide simplify to specific results. In some cases, you can get lucky, and use rewrite to provide the answer you want, but even that is not always easy to get a specific result.
  1 Commento
Thomas Maletz
Thomas Maletz il 25 Lug 2025
Hi John, excellent, that is what I was looking for, I should have played with the simplify a bit more ;-) . Thanks for the quick, nice and detailed support, very helpful.

Accedi per commentare.

Più risposte (1)

Matt J
Matt J il 24 Lug 2025
Modificato: Matt J il 24 Lug 2025
There is no unique expansion of such an expression. You would have to go the other way.
syms w v t
simplify( 0.5 * (cos(w*t - v*t) + cos(w*t + v*t)) )
ans = 
  1 Commento
Thomas Maletz
Thomas Maletz il 24 Lug 2025
Hi Matt, yes, this I know, but unfortunately I need the other direction. I was hoping MATLAB shows me some solutions or I can guide it with parameters or similar but might not work this way. But thanks for the hint and answer.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by