Reputation: 23
I want to find the interval of following two constants cons1
and cons2
I wrote the follwing code
from sympy import Poly
from sympy import Abs
from sympy.solvers.inequalities import solve_rational_inequalities
from sympy.abc import x
cons1=2*((x+2)**2)-Abs(x)-1
cons2=exp(2*x+1)-2.5
solve_rational_inequalities([[((Poly(cons1), Poly(1, x)), '<='), (Poly(cons2), Poly(1, x)), '<=')]])
but because of Abs I am getting:
PolynomialError: only univariate polynomials are allowed
Upvotes: 2
Views: 696
Reputation:
This is by design. 2*((x+2)**2) - Abs(x) - 1
is not a polynomial in x. Neither is exp(2*x+1) - 2.5
. The methods of solve_rational_inequalities
do not apply to such functions.
If you try to cheat mathematics by wrapping those expressions in Poly, all that happens is that SymPy will make them polynomials with respect to x
and Abs(x)
(or exp(2*x+1)
, etc). That's a kind of a polynomial, but not a polynomial with respect to x, which is what solve_rational_inequalities
requires. Hence the error.
Bottom line: SymPy does not currently have an algorithm for solving systems of general inequalities. There is an algorithm for rational inequalities and some other things listed on inequality solvers page, including solve_univariate_inequality
(which allows general functions, but for one variable only).
Upvotes: 2