필터 지우기
필터 지우기

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion 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