我正在尝试在 sympy 中提取复数的相位,但即使对于简单的情况,.arg()
方法也不会返回有用或预期的结果。
import sympy as s
A, theta = s.symbols('A theta', real = True)
expr = A*s.exp(theta*s.I)
angle = s.arg(expr)
print(angle) #Arg(A*exp(theta*I))
我期望输出只是theta
,但它返回Arg(A*exp(theta*I)
,这是正确的,但并不是很有帮助。为什么会这样这么简单的情况会发生吗?
最佳答案
看起来函数arg
的参数必须是一个实际的数字。没有符号。您可以从以下内容中看到这一点
from sympy import *
arg(1+2*I)
Out[5]: atan(2)
A=symbols('A',real=True)
arg(A+2*I)
Out[8]: arg(A + 2*I)
也许你可以实现自己的参数:
from sympy import *
A, theta = symbols('A theta', real = True)
expr = A*exp(theta*I)
simplify(simplify(atan(im(expr)/re(expr))),inverse=True)
给予
theta
ps。奇怪的是为什么这不起作用
simplify(atan(im(expr)/re(expr)),inverse=True)
---> atan(tan(theta))
但必须调用simplify
两次
关于python - 为什么 sympy.arg() 函数没有返回预期的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57098533/