Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
683 views
in Technique[技术] by (71.8m points)

range - SymPy: Limit symbol/variable to interval

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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].


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...