eqn = 
Comparing coefficients and solving equation
Show older comments
Hello everyone,
I would like to find the values of variables comparing coefficients in equation. Let's have a look at an easy example.
x^2 + 2*x + 5 = (b+4*a)*x^2 + (5*a+b)*x + (-b+2*a)
May someone help me with finding 'a' and 'b' value?
Thanks
Answers (1)
syms x a b
eqn = x^2 + 2*x + 5 == (b+4*a)*x^2 + (5*a+b)*x + (-b+2*a)
cleft = coeffs(lhs(eqn),x,'all')
cright = coeffs(rhs(eqn),x,'all')
sol = solve(cleft == cright,[a b])
Verify
isAlways(subs(eqn,sol))
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!