Using SymPy, is it possible to limit the possible values of a symbol/variable to a certain range? I now I can set some properties while defining symbols, like positive=True
, but I need more control, i.e. I need to set it to be in the interval [0,1]. This assumption should then be used for solving, simplifying etc.
You can specify the bounds as inequalities such as x >= lb
and x <= ub
, for example:
from sympy.solvers import solve
from sympy import Symbol
x = Symbol('x')
solve([x >= 0.5, x <= 3, x**2 - 1], x)
Here we search for a solution of equation x**2 == 1
such that x
is in the interval [0.5, 3]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With