tan 函数的 Sympy 计算

发布于 2025-01-13 19:58:56 字数 791 浏览 4 评论 0原文

当具有三角函数和复数指数时,在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不羁少年 2025-01-20 19:58:56

exp 重写,然后简化得到 0

test1.rewrite(sym.exp).simplify()

Rewriting in terms of exp then simplifying gives 0

test1.rewrite(sym.exp).simplify()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文