尝试使用 sympy 来解决家庭作业问题。我已经完成了问题,但我想超越要求



长话短说,这是加迪斯书中关于种植新葡萄藤的一个问题。

if R < (2 * E):
print('Please try again, the length of row must be greater than twice the space for the end post assembly.')
elif S == 0:
print('Please try again, the amount of space can not be zero.')
elif R > (2 * E):
V = (R - (2 * E)) / S
# expr.subs(r, R)
# expr.subs(e, E)
# expr.subs(s, S)
eq1 = Eq(v=((r - (2 * e)) / s))
print(f'The solution is x = {eq1}')
print('Number of grapevines that will fit in a row = ', math.floor(V))

这是我的小if语句,所以没有任何东西被0整除,并且(R-2E)没有负数。我所要做的就是在成功的if语句结束时打印等式。什么好主意吗?

您没有指定运行SymPy的环境,SymPy本身不是图形程序。SymPy(以及更普遍的Python)可以以不同的方式使用:

  1. 从系统终端
  2. 从一个IDE,如Spyder
  3. 来自木星笔记本
  4. 等。

我个人在终端上使用isympy(ipython的改编版)运行sympy。我得到了这样的输出:

In [7]: V, R, E, S = symbols('V, R, E, S')
In [8]: eq = Eq(V, (R - 2*E)/S)
In [9]: eq
Out[9]: 
-2⋅E + R
V = ────────
S

我想大多数SymPy用户会使用Jupyter笔记本,它看起来像这样:

https://github.com/sympy/sympy/blob/master/examples/notebooks/Sylvester_resultant.ipynb

SymPy教程中的更多信息:

https://docs.sympy.org/latest/tutorial/printing.html

最新更新