フィルターのクリア

How to get the coefficients of an equation

2 ビュー (過去 30 日間)
Geovane Gomes
Geovane Gomes 2023 年 11 月 8 日
回答済み: Sulaymon Eshkabilov 2023 年 11 月 8 日
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.
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 8 日
What is the expected output?
[1 2] or [2 1]? or something else?
Geovane Gomes
Geovane Gomes 2023 年 11 月 8 日
[2 1]

サインインしてコメントする。

採用された回答

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
Sulaymon Eshkabilov 2023 年 11 月 8 日
Maybe it is appropriate to work in a reverse order, e.g.:
syms x1 x2
Coeff = [2;1];
eq = [x1, x2]*Coeff<=0
eq = 

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by