フィルターのクリア

How to extract coefficient of a certain term in Matlab?

4 ビュー (過去 30 日間)
DmArcher
DmArcher 2017 年 4 月 28 日
コメント済み: Star Strider 2017 年 4 月 28 日
For example,
syms f1 f2 a
pexpansion = f1 - f2 - a*(f1 - f2) + f2/a + a^2*(f1 - f2) - a^3*(f1 - f2) + a^4*(f1 - f2)
I want to extract the coefficient of power 1 of a, which is (f1-f2). However, there is 1/a term in the expression which makes it not a polynomial. Does anyone know how to do this?

採用された回答

Star Strider
Star Strider 2017 年 4 月 28 日
Try this:
syms f1 f2 a
pexpansion = f1 - f2 - a*(f1 - f2) + f2/a + a^2*(f1 - f2) - a^3*(f1 - f2) + a^4*(f1 - f2);
pexpansion = expand(a * pexpansion); % Eliminate ‘a’ In Denominator
[cfs,trms] = coeffs(pexpansion, a); % Coeffients & Terms
Result = cfs(trms == a) % Coefficient Of ‘a’
Result =
f1 - f2
  2 件のコメント
DmArcher
DmArcher 2017 年 4 月 28 日
Thank you so much
Star Strider
Star Strider 2017 年 4 月 28 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by