gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:46:15 24 4
gpt4 key购买 nike

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

>>> 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 值的图形,与

enter image description here

最佳答案

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

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))

这将为您提供以下输出:

enter image description here

关于python - 在 Python SymPy 中设置函数的域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32161608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com