简体   繁体   English

在症状中简化双曲函数的指数表示

[英]Simplifying exponential representation of hyperbolic functions in sympy

I am trying to rewrite some exponential functions in an expression to cosh and sinh. 我试图将表达式中的一些指数函数重写为cosh和sinh。 The rewrite() function works to get from a hyperbolic function to its exponential representation. rewrite()函数用于从双曲函数到其指数表示。 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)'. 我希望最后一个命令的结果是'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. 我试图找到关于rewrite()函数的一些文档,但我找到的唯一一点是http://docs.sympy.org/latest/tutorial/simplification.html中的简短部分,这并不是很有用。

Applying .rewrite(sympy.cos) returns cosh(x) as you wanted. 应用.rewrite(sympy.cos)返回cosh(x) Apparently, the hyperbolic cosine is treated by rewrite as a variant of the normal one. 显然,双曲余弦值通过rewrite来处理,作为正常值的变体。

Here is a reference on rewrite method . 这是重写方法参考

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM