tan 函数的 Sympy 计算
当具有三角函数和复数指数时,在 sympy 中简化符号表达式时遇到问题,即我只是假设了 tan 函数的不同定义,并且发生了一件奇怪的事情。所以我这样做:
# Deleting variables
from IPython import get_ipython;
get_ipython().magic('reset -sf')
import sympy as sym;
# defining variables
test1 = sym.Symbol('test');
test2 = sym.Symbol('test2');
a = sym.Symbol('a');
# Defining tests
test1 = sym.tan(a) + sym.I*(sym.exp(sym.I*a)-sym.exp(-sym.I*a))/(sym.exp(sym.I*a)+sym.exp(-sym.I*a));
test2 = sym.I*(sym.exp(sym.I*a)-sym.exp(-sym.I*a))/(sym.exp(sym.I*a)+sym.exp(-sym.I*a));
符号变量 sym.simplify(test2) 等于 -tan(a) 并且正常情况下 test1 变量应该等于 0,但是当我简化 test1 变量时,我确实得到:
sym.simplify(test1)
Out[140]:
(-I*(1 - exp(2*I*a)) + (exp(2*I*a) + 1)*tan(a))/(exp(2*I*a) + 1)
所以问题是我得到什么错误,如何告诉Python简化text1表达式以获得自然应该是的0
I have a problem when simplifying a symbolic expression in sympy when having a trigonometric function and a complex exponent, namely I just assumed a different definition of tan function, and I have a weird thing going on. So I do:
# Deleting variables
from IPython import get_ipython;
get_ipython().magic('reset -sf')
import sympy as sym;
# defining variables
test1 = sym.Symbol('test');
test2 = sym.Symbol('test2');
a = sym.Symbol('a');
# Defining tests
test1 = sym.tan(a) + sym.I*(sym.exp(sym.I*a)-sym.exp(-sym.I*a))/(sym.exp(sym.I*a)+sym.exp(-sym.I*a));
test2 = sym.I*(sym.exp(sym.I*a)-sym.exp(-sym.I*a))/(sym.exp(sym.I*a)+sym.exp(-sym.I*a));
Symbolic variable sym.simplify(test2) is equal to -tan(a) and normaly test1 variable should be equal to 0, however when I simplify a test1 variable, I do get:
sym.simplify(test1)
Out[140]:
(-I*(1 - exp(2*I*a)) + (exp(2*I*a) + 1)*tan(a))/(exp(2*I*a) + 1)
So the question is what do I get wrong, how to tell Python to simplify a text1 expression in order to get 0 which it naturally should be
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用
exp
重写,然后简化得到0
Rewriting in terms of
exp
then simplifying gives0