Extracting coefficients of 'sinwt', 'coswt', sin2wt etc from a symbiolic expression.
이전 댓글 표시
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 ?
,
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
Walter Roberson
2021년 8월 8일
What would be the desired output in that example? What would be the desired output for the example of
Yugal Gupta
2021년 8월 8일
The origin of your cos(3*omega*t) and the division by 2 is not obvious to me. I do find that,
syms k [1 3]
syms omega t
y = k(1)*sin(omega*t) * k(2)*sin(2*omega*t) + k(3) * sin(omega*t)
yexp = rewrite(y, 'exp')
yexps = simplify(yexp)
ysincos = rewrite(yexps, 'sincos')
ysincoss = simplify(ysincos)
Yugal Gupta
2021년 8월 9일
Walter Roberson
2021년 8월 9일
Ah... you can get there in a single step with
combine(y, 'sincos')
답변 (1개)
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)])
댓글 수: 1
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
카테고리
도움말 센터 및 File Exchange에서 Space-Time Adaptive Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


