SymPy:将符号/变量限制为间隔 [英] SymPy: Limit symbol/variable to interval

查看:156
本文介绍了SymPy:将符号/变量限制为间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SymPy,是否可以将符号/变量的可能值限制在某个范围内?现在,我可以在定义符号时设置一些属性,例如positive=True,但是我需要更多的控制权,即我需要将其设置为[0,1].然后应将此假设用于求解,简化等.

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.

推荐答案

您可以将边界指定为不等式,例如x >= lbx <= ub,例如:

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)

在这里我们搜索方程式x**2 == 1的解,以使x在区间[0.5, 3]中.

Here we search for a solution of equation x**2 == 1 such that x is in the interval [0.5, 3].

这篇关于SymPy:将符号/变量限制为间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆