我正在尝试绘制一个方程,该方程是使用 sympy 求解块的结果,这是我的代码和以下错误消息:
%pylab inline
from sympy import init_printing;init_printing()
from sympy import *
d,vf,a,vi,t,x,h,g,theta=symbols('d vf a vi t x h g theta')
equations=[Eq(sin(theta),(0.5*g*t**2+h)/(vi*t)),Eq(cos(theta),x/(vi*t))]
ans=solve(equations,[h,t],dict=True)
h=ans[0][h]
vi=5
g=9.8
theta=0.707
plot(h,(x,0,5))
然后我收到以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-11-f388e50e21e7> in <module>()
----> 1 plot(h,(x,0,5))
C:\Anaconda\lib\site-packages\sympy\plotting\plot.pyc in plot(*args, **kwargs)
1158 show = kwargs.pop('show', True)
1159 series = []
-> 1160 plot_expr = check_arguments(args, 1, 1)
1161 series = [LineOver1DRangeSeries(*arg, **kwargs) for arg in plot_expr]
1162
C:\Anaconda\lib\site-packages\sympy\plotting\plot.pyc in check_arguments(args, expr_len, nb_of_free_symbols)
1620 if len(free_symbols) > nb_of_free_symbols:
1621 raise ValueError("The number of free_symbols in the expression"
-> 1622 "is greater than %d" % nb_of_free_symbols)
1623 if len(args) == i + nb_of_free_symbols and isinstance(args[i], Tuple):
1624 ranges = Tuple(*[range_expr for range_expr in args[i:i + nb_of_free_symbols]])
ValueError: The number of free_symbols in the expressionis greater than 1
如果我重新输入 h 的 corect 方程,那么我会得到正确的图。
感谢您的帮助,我正在尝试为我的物理学生开发这个以供明年使用