Sympy yields `TypeError: unsupported operand type(s) for *: 'interval' and 'complex'` for complex rational expression

huangapple go评论83阅读模式
英文:

Sympy yields `TypeError: unsupported operand type(s) for *: 'interval' and 'complex'` for complex rational expression

问题

以下是您要翻译的代码部分:

from sympy import *
from sympy.plotting import plot_implicit

x, y = symbols('x y', real=True)

alpha = sqrt(2) / 2
expr = 1 + ((1-alpha) * x + y*I) / (1 - alpha * (x + y*I))**2

expr = Eq(abs(expr), 1)
p1 = plot_implicit(expr)

希望这能帮助您解决代码问题。如果您有其他问题,请随时提出。

英文:

I have this sympy script:

from sympy import *
from sympy.plotting import plot_implicit

x, y = symbols('x y', real=True)

alpha = sqrt(2) / 2
expr = 1 + ((1-alpha) * x + y*I) / (1 - alpha * (x + y*I))**2

expr = Eq(abs(expr), 1)
p1 = plot_implicit(expr)

Which is trying to solve R(z) = 1 where:

As far as I can tell the expression I am giving it is correct. Why am I getting incompatible types? Note that if I get rid of the denominator I do get a plot.

Sympy yields `TypeError: unsupported operand type(s) for *: 'interval' and 'complex'` for complex rational expression

Full error:

Traceback (most recent call last):
  File "/home/makogan/Documents/University/Math521/A3/A5.py", line 49, in <module>
    p1 = plot_implicit(expr)
  File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot_implicit.py", line 430, in plot_implicit
    p.show()
  File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 240, in show
    self._backend.show()
  File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 1533, in show
    self.process_series()
  File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 1530, in process_series
    self._process_series(series, ax, parent)
  File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 1398, in _process_series
    points = s.get_raster()
  File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot_implicit.py", line 87, in get_raster
    func(xinterval, yinterval)
  File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/experimental_lambdify.py", line 272, in __call__
    return self.lambda_func(*args, **kwargs)
  File "<string>", line 1, in <lambda>
TypeError: unsupported operand type(s) for *: 'interval' and 'complex'

答案1

得分: 1

这是代码部分,无需翻译。

英文:

That's caused by the fact that sympy's plotting module is using an old and obsolete evaluation module. If you try this new plotting module you'll get the answer:

from sympy import *
from spb import *
var("x:z")

x, y = symbols('x y', real=True)

alpha = sqrt(2) / 2
expr = 1 + ((1 - alpha) * z) / (1 - alpha * z)**2
expr = expr.subs(z, x + I*y)

expr = Eq(abs(expr), 1)
p1 = plot_implicit(expr, x)

Sympy yields `TypeError: unsupported operand type(s) for *: 'interval' and 'complex'` for complex rational expression

huangapple
  • 本文由 发表于 2023年3月7日 08:51:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657133.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定