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

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

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

问题

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

  1. from sympy import *
  2. from sympy.plotting import plot_implicit
  3. x, y = symbols('x y', real=True)
  4. alpha = sqrt(2) / 2
  5. expr = 1 + ((1-alpha) * x + y*I) / (1 - alpha * (x + y*I))**2
  6. expr = Eq(abs(expr), 1)
  7. p1 = plot_implicit(expr)

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

英文:

I have this sympy script:

  1. from sympy import *
  2. from sympy.plotting import plot_implicit
  3. x, y = symbols('x y', real=True)
  4. alpha = sqrt(2) / 2
  5. expr = 1 + ((1-alpha) * x + y*I) / (1 - alpha * (x + y*I))**2
  6. expr = Eq(abs(expr), 1)
  7. 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:

  1. Traceback (most recent call last):
  2. File "/home/makogan/Documents/University/Math521/A3/A5.py", line 49, in <module>
  3. p1 = plot_implicit(expr)
  4. File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot_implicit.py", line 430, in plot_implicit
  5. p.show()
  6. File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 240, in show
  7. self._backend.show()
  8. File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 1533, in show
  9. self.process_series()
  10. File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 1530, in process_series
  11. self._process_series(series, ax, parent)
  12. File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot.py", line 1398, in _process_series
  13. points = s.get_raster()
  14. File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/plot_implicit.py", line 87, in get_raster
  15. func(xinterval, yinterval)
  16. File "/home/makogan/.local/lib/python3.10/site-packages/sympy/plotting/experimental_lambdify.py", line 272, in __call__
  17. return self.lambda_func(*args, **kwargs)
  18. File "<string>", line 1, in <lambda>
  19. 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:

  1. from sympy import *
  2. from spb import *
  3. var("x:z")
  4. x, y = symbols('x y', real=True)
  5. alpha = sqrt(2) / 2
  6. expr = 1 + ((1 - alpha) * z) / (1 - alpha * z)**2
  7. expr = expr.subs(z, x + I*y)
  8. expr = Eq(abs(expr), 1)
  9. 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:

确定