Skip to main content
 首页 » 编程设计

python之在 Python SymPy 中设置函数的域

2025年05月04日16mate10pro

我想知道是否可以通过某种方式设置数学域。功能。例如,当我定义如下表达式时

>>> import sympy as syp 
>>> x = syp.Symbol('x') 
>>> miles_to_km = x * 1.609344 
>>> miles_to_km.evalf() 
1.609344*x 

是否可以限制域使 x 在 [0, inf) 范围内?所以我的目标是我可以使用 sympy.plot 函数生成一个从 0 开始并且只包含正 x 值的图形,与

请您参考如下方法:

如果我们通过以下方式检查手册:

help(syp.plot) 

您将获得:

...

expr : Expression representing the function of single variable

range: (x, 0, 5), A 3-tuple denoting the range of the free variable.

...

所以,你可以:

>>> import sympy as syp 
>>> x = syp.Symbol('x') 
>>> miles_to_km = x * 1.609344 
>>> syp.plot(miles_to_km, (x,0,10)) 

这将为您提供以下输出: