How to work out trigonometric identities symbolically?

9 Ansichten (letzte 30 Tage)
Thomas Maletz
Thomas Maletz am 24 Jul. 2025
Bearbeitet: Thomas Maletz am 25 Jul. 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 Kommentare
Torsten
Torsten am 24 Jul. 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 am 24 Jul. 2025
Bearbeitet: Thomas Maletz am 25 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 24 Jul. 2025
Bearbeitet: John D'Errico am 24 Jul. 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 Kommentar
Thomas Maletz
Thomas Maletz am 25 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt J
Matt J am 24 Jul. 2025
Bearbeitet: Matt J am 24 Jul. 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 Kommentar
Thomas Maletz
Thomas Maletz am 24 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by