How to work out trigonometric identities symbolically?

12 ビュー (過去 30 日間)
Thomas Maletz
Thomas Maletz 2025 年 7 月 24 日
編集済み: Thomas Maletz 2025 年 7 月 25 日
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 件のコメント
Torsten
Torsten 2025 年 7 月 24 日
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 2025 年 7 月 24 日
編集済み: Thomas Maletz 2025 年 7 月 25 日
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.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2025 年 7 月 24 日
編集済み: John D'Errico 2025 年 7 月 24 日
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 件のコメント
Thomas Maletz
Thomas Maletz 2025 年 7 月 25 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2025 年 7 月 24 日
編集済み: Matt J 2025 年 7 月 24 日
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 件のコメント
Thomas Maletz
Thomas Maletz 2025 年 7 月 24 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by