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

조회 수: 9 (최근 30일)
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 = 

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by