简化 sympy 中双曲函数的指数表示 [英] Simplifying exponential representation of hyperbolic functions in sympy

查看:59
本文介绍了简化 sympy 中双曲函数的指数表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将表达式中的一些指数函数重写为 cosh 和 sinh.rewrite() 函数用于将双曲线函数转换为指数表示.但是回来也没有用.

<预><代码>>>>进口同情>>>x=sympy.Symbol('x')>>>sympy.cosh(x).rewrite(sympy.exp)exp(x)/2 + exp(-x)/2>>>sympy.cosh(x).rewrite(sympy.exp).rewrite(sympy.cosh)exp(x)/2 + exp(-x)/2

我希望最后一个命令的结果是cosh(x)".有人可以向我解释为什么不是吗?我试图找到一些关于 rewrite() 函数的文档,但我发现的唯一一点是 http://docs.sympy.org/latest/tutorial/simplification.html 这不是很有帮助.

解决方案

Applying .rewrite(sympy.cos) 会根据需要返回 cosh(x).显然,双曲余弦被 rewrite 视为普通余弦的一种变体.

这是关于重写方法的参考.

或者,simplify(expr) 也将 exp(x)/2 + exp(-x)/2 转换为 cosh(x)>.

I am trying to rewrite some exponential functions in an expression to cosh and sinh. The rewrite() function works to get from a hyperbolic function to its exponential representation. But it does not work to get back.

>>> import sympy
>>> x=sympy.Symbol('x')
>>> sympy.cosh(x).rewrite(sympy.exp)
exp(x)/2 + exp(-x)/2
>>> sympy.cosh(x).rewrite(sympy.exp).rewrite(sympy.cosh)
exp(x)/2 + exp(-x)/2

I would expect the result of the last command to be 'cosh(x)'. Can someone explain to me why it is not? I tried to find some documentation on the rewrite() function but the only bit I found was the short section in http://docs.sympy.org/latest/tutorial/simplification.html that is not really helpful.

解决方案

Applying .rewrite(sympy.cos) returns cosh(x) as you wanted. Apparently, the hyperbolic cosine is treated by rewrite as a variant of the normal one.

Here is a reference on rewrite method.

Alternatively, simplify(expr) also transforms exp(x)/2 + exp(-x)/2 into cosh(x).

这篇关于简化 sympy 中双曲函数的指数表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆