Transform polynomium equation into multiple coefficient equations

1 view (last 30 days)
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

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!