[英]Complex numbers in sympy
我正在使用 lcapy 和 sympy 並嘗試處理電路中的復數。
我有以下同情表達:
import sympy
from lcapy import j
expr = sympy.parse_expr('L*w_0*(C*R*w_0 - I)')
expr
Output:
L⋅w₀⋅(C⋅R⋅w₀ - ⅉ)
上面的expr
是一個復數表達式, ⅉ
是虛數。 我可以使用 sympy 並從expr
中刪除括號,以便以更規范的復數形式查看它
w₀^2⋅R⋅L⋅C - ⅉ⋅w₀⋅L
sympy 是否支持處理復數? 我想得到expr
的論點,它應該是:
arctan(L⋅w₀ / w₀^2⋅R⋅L⋅C)
我可以(在isympy
會話中):
In [13]: expr
Out[13]: L⋅w₀⋅(C⋅R⋅w₀ - ⅈ)
In [14]: expr.expand()
Out[14]:
2
C⋅L⋅R⋅w₀ - ⅈ⋅L⋅w₀
嘗試
atan2(im(expr), re(expr))
https://docs.sympy.org/latest/modules/functions/elementary.html
細化變量:
In [53]: C,L,R,w_0=symbols('C L R w_0',real=True, positive=True)
In [54]: expr=L*w_0*(C*R*w_0-I)
In [55]: expr
Out[55]: L⋅w₀⋅(C⋅R⋅w₀ - ⅈ)
In [56]: expr.expand()
Out[56]:
2
C⋅L⋅R⋅w₀ - ⅈ⋅L⋅w₀
In [57]: im(_),re(_)
Out[57]:
⎛ 2⎞
⎝-L⋅w₀, C⋅L⋅R⋅w₀ ⎠
現在atan2
被簡化:
In [59]: atan2(*_)
Out[59]:
⎛ 1 ⎞
-atan⎜──────⎟
⎝C⋅R⋅w₀⎠
和arg
做同樣的事情:
In [60]: arg(_56)
Out[60]: arg(C⋅R⋅w₀ - ⅈ)
In [62]: arg(expr)
Out[62]: arg(C⋅R⋅w₀ - ⅈ)
In [77]: arg(expr)._eval_rewrite_as_atan2(expr)
Out[77]:
⎛ 1 ⎞
-atan⎜──────⎟
⎝C⋅R⋅w₀⎠
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.