![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/706642/image.png)
Extracting coefficients of 'sinwt', 'coswt', sin2wt etc from a symbiolic expression.
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/706652/image.png)
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 ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/706602/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/706607/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/706662/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/706657/image.png)
5 commentaires
Walter Roberson
le 9 Août 2021
Ah... you can get there in a single step with
combine(y, 'sincos')
Réponses (1)
Gargi Patil
le 12 Août 2021
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 commentaire
Walter Roberson
le 12 Août 2021
Modifié(e) : Walter Roberson
le 12 Août 2021
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
Voir également
Catégories
En savoir plus sur Formula Manipulation and Simplification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!