How to work out trigonometric identities symbolically?

12 vues (au cours des 30 derniers jours)
Thomas Maletz
Thomas Maletz le 24 Juil 2025
Modifié(e) : Thomas Maletz le 25 Juil 2025
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 commentaires
Torsten
Torsten le 24 Juil 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 le 24 Juil 2025
Modifié(e) : Thomas Maletz le 25 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

John D'Errico
John D'Errico le 24 Juil 2025
Modifié(e) : John D'Errico le 24 Juil 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 commentaire
Thomas Maletz
Thomas Maletz le 25 Juil 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.

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 24 Juil 2025
Modifié(e) : Matt J le 24 Juil 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 commentaire
Thomas Maletz
Thomas Maletz le 24 Juil 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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by