필터 지우기
필터 지우기

How to get the coefficients of an equation

조회 수: 4 (최근 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 CenterFile Exchange에서 Conversion 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