How to get the coefficients of an equation

4 次查看(过去 30 天)
Dear all,
Is it possible to extract the coefficients of an equantion defined as below:
syms x1 x2
eq = 2*x1 + x2 <= 0
eq = 
By using coeffs and sym2poly did not work when it has the relational operator "<=".
c = coeffs(eq)
c = 
1
c = sym2poly(eq)
Error using sym/sym2poly
Not a polynomial.

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-11-8
How about -
syms x1 x2
eq = 2*x1 + x2 <= 0
eq = 
out = flip(coeffs(lhs(eq)))
out = 
  1 个评论
Geovane Gomes
Geovane Gomes 2023-11-8
Good solution!
This way I can also have the term in the right side
syms x1 x2
eq = 2*x1 + x2 <= 5
eq = 
out = flip(coeffs(rhs(eq)))
out = 
5
Thanks!

请先登录,再进行评论。

更多回答(1 个)

Sulaymon Eshkabilov
Maybe it is appropriate to work in a reverse order, e.g.:
syms x1 x2
Coeff = [2;1];
eq = [x1, x2]*Coeff<=0
eq = 

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by