2

我需要显示一个圆周。为了做到这一点,我认为我可以计算 的很多x两个值y,所以我做了:

import sympy as sy
from sympy.abc import x,y
f = x**2 + y**2 - 1
a = x - 0.5
sy.solve([f,a],[x,y])

这就是我得到的:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/sympy/solvers/solvers.py", line 484, in
 solve
    solution = _solve(f, *symbols, **flags)
  File "/usr/lib/python2.7/dist-packages/sympy/solvers/solvers.py", line 749, in
 _solve
    result = solve_poly_system(polys)
  File "/usr/lib/python2.7/dist-packages/sympy/solvers/polysys.py", line 40, in
solve_poly_system
    return solve_biquadratic(f, g, opt)
  File "/usr/lib/python2.7/dist-packages/sympy/solvers/polysys.py", line 48, in
solve_biquadratic
    G = groebner([f, g])
  File "/usr/lib/python2.7/dist-packages/sympy/polys/polytools.py", line 5308, i
n groebner
    raise DomainError("can't compute a Groebner basis over %s" % domain)
DomainError: can't compute a Groebner basis over RR

如何计算y's 值?

4

2 回答 2

1

为我工作;也许解决方案就像升级一样简单?

>>> import sympy
>>> sympy.__version__
'0.7.2'
>>> import sympy as sy
>>> from sympy.abc import x,y
>>> f = x**2 + y**2 - 1
>>> a = x - 0.5
>>> sy.solve([f,a],[x,y])
[(0.500000000000000, -0.866025403784439), (0.500000000000000, 0.866025403784439)]

[虽然如果我需要画一个圆或弧线,我会r cos(theta), r sin(theta)改用,以便更容易以正确的顺序获得点。]

于 2012-10-18T16:57:46.920 回答
0

您还可以使用有理数来获得准确的答案(并避免该错误)

In [22]: a = x - Rational(1,2)

In [23]: sy.solve([f,a],[x,y])
Out[23]:
⎡⎛        ___⎞  ⎛       ___⎞⎤
⎢⎜     -╲╱ 3 ⎟  ⎜     ╲╱ 3 ⎟⎥
⎢⎜1/2, ──────⎟, ⎜1/2, ─────⎟⎥
⎣⎝       2   ⎠  ⎝       2  ⎠⎦
于 2012-10-19T05:33:25.613 回答