Transform polynomium equation into multiple coefficient equations

1 次查看(过去 30 天)
Hello
I want to match coefficients from 2 polynomiums:
syms x
syms a [3,1]
syms alpha beta gamma
eq = (1-alpha)*x^2 + (1-beta)*x + (1-gamma) == a1 *x^2 + 0*x + a3
Such that i get:
>>eq1 = 1-alpha == a1
>>eq2 = 1-beta == 0
>>eq3 = 1-gamma == a3
My current solution is:
cL = coeffs(lhs(eq),x,'all');
cR = coeffs(rhs(eq),x,'all');
new_eq = cL == cR
But that does not work when x is raised to a negative power:
eq = (1-alpha)*x^-2 + (1-beta)*x^-1 + (1-gamma) == a1 *x^-2 + 0*x^-1 + a3
I know that i can make a placeholder variable such that:
syms z
eq = subs(eq,x^-1,z)
cL = coeffs(lhs(eq),z,'all');
cR = coeffs(rhs(eq),z,'all');
new_eq = cL == cR
But that does not work if i have x to both positive and negative powers. And i am wondering if there is a command that can do all that for me instead

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by