Extracting coefficients of 'sinwt', 'coswt', sin2wt etc from a symbiolic expression.

6 ビュー (過去 30 日間)
Yugal Gupta
Yugal Gupta 2021 年 8 月 8 日
編集済み: Walter Roberson 2021 年 8 月 12 日
Hello,
I am having a mathmatical symbolic expression and want to extract the coefficient of 'sinwt', 'coswt', 'sin2wt' and so on.
For e.g. the expression is,
where, , and are symbolic variables. Now, is there anyway to get the coefficient of 'sinwt', 'coswt', 'cos3wt' etc. from this expression ? or in other words, is it possible to get the following desired output ?
  5 件のコメント
Yugal Gupta
Yugal Gupta 2021 年 8 月 9 日
In the end, I added the following code and it gives me the desired output.
combine(ysincoss,'sincos')
Walter Roberson
Walter Roberson 2021 年 8 月 9 日
Ah... you can get there in a single step with
combine(y, 'sincos')

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

回答 (1 件)

Gargi Patil
Gargi Patil 2021 年 8 月 12 日
Hi,
My understanding is that you would like to extract the coefficients of a symbolic trigonometric expression. The function "coeffs" can be used to return coefficients of an expression with respect to a specified term as follows:
syms a b c x
expr = a*sin(x)*b*sin(2*x) + c*sin(x);
[csin, tsin] = coeffs(expr, [sin(x), sin(2*x)])
csin = 
tsin = 
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 8 月 12 日
編集済み: Walter Roberson 2021 年 8 月 12 日
It turned out that they wanted the express rewritten in terms of cos(), and were not looking for coefficients such as you get with coeffs(); see https://www.mathworks.com/matlabcentral/answers/894797-extracting-coefficients-of-sinwt-coswt-sin2wt-etc-from-a-symbiolic-expression#comment_1679322

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by