gpt4 book ai didi

python - 获取 SimpifyError

转载 作者:行者123 更新时间:2023-11-28 17:03:10 26 4
gpt4 key购买 nike

我需要在一张图上为 x+y=0 线绘制 8 个贝壳线。等式是 l**2 * y**2 = (x**2 + y**2)*(y+a)**2l 等于 {a/4, a/2, 3*a/4..., 2*a}。因此,我有一个代码:

x, y, a, l = symbols('x, y, a, l')
a = 1
equat = l**2 * y**2 - (x**2 + y**2)*(y+a)**2
equats = [None] * 8
for i in range(1, 9):
equats[i-1] = equat.subs({l : a*i*1/4})
print(equats)
plot_implicit(equats, (x, -5,5), (y, -5, 5))

这段代码引发了一个SympifyError:

---------------------------------------------------------------------------
SympifyError Traceback (most recent call last)
<ipython-input-31-26c783d64bc7> in <module>()
6 equats[i-1] = equat.subs({l : a*i*1/4})
7 print(equats)
----> 8 plot_implicit(equats, (x, -5,5), (y, -5, 5))

~\Anaconda3\lib\site-packages\sympy\plotting\plot_implicit.py in plot_implicit(expr, x_var, y_var, **kwargs)
316
317 elif not isinstance(expr, Relational):
--> 318 expr = Eq(expr, 0)
319 has_equality = True
320 elif isinstance(expr, (Equality, GreaterThan, LessThan)):

~\Anaconda3\lib\site-packages\sympy\core\relational.py in __new__(cls, lhs, rhs, **options)
290 from sympy.simplify.simplify import clear_coefficients
291
--> 292 lhs = _sympify(lhs)
293 rhs = _sympify(rhs)
294

~\Anaconda3\lib\site-packages\sympy\core\sympify.py in _sympify(a)
385
386 """
--> 387 return sympify(a, strict=True)
388
389

~\Anaconda3\lib\site-packages\sympy\core\sympify.py in sympify(a, locals, convert_xor, strict, rational, evaluate)
301
302 if strict:
--> 303 raise SympifyError(a)
304
305 try:

SympifyError: SympifyError: [0.0625*y**2 - (x**2 + y**2)*(y + 1)**2, 0.25*y**2 - (x**2 + y**2)*(y + 1)**2, 0.5625*y**2 - (x**2 + y**2)*(y + 1)**2, 1.0*y**2 - (x**2 + y**2)*(y + 1)**2, 1.5625*y**2 - (x**2 + y**2)*(y + 1)**2, 2.25*y**2 - (x**2 + y**2)*(y + 1)**2, 3.0625*y**2 - (x**2 + y**2)*(y + 1)**2, 4.0*y**2 - (x**2 + y**2)*(y + 1)**2]

我该如何解决这个问题?我在谷歌上搜索,但没有找到任何解决方案。

最佳答案

如果您一个一个地绘制方程而不是传递方程的列表,则问题可能会得到解决。

p = plot_implicit(equats[0], (x, -5,5), (y, -5,5), show=False)
for eq in equats[1:]:
p2 = plot_implicit(eq, (x, -5,5), (y, -5,5), show=False)
p.append(p2[0])
p.show()

关于python - 获取 SimpifyError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52974515/

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