我试图绘制一个等式,这是使用sympy 这里是我的代码和下面的错误消息的一个解决块的结果:IPython的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
如果我重新键入小时corect方程式然后我得到了正确的阴谋。
感谢您的帮助,我试图发展为我的物理学生使用明年
这不是SymPy或IPython的问题,它是python语法的基本问题。首先阅读python语言教程或类似http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch06.html。在开始使用它提供的任何库之前,了解您正在使用的语言非常重要。 – Krastanov
顺便说一下,您应该更新到SymPy 0.7.3。 – asmeurer
@Krastanov即使是那些了解Python的人也会被困在这个问题中,因为它并不总是清楚有多少魔法库可以提供。我认为如果你了解了http://docs.sympy.org/0.7.3/tutorial/gotchas.html上的所有内容,那么你应该很好。 – asmeurer