Python - AI 助手

Python cmath.cosh() 函数



Python 的 cmath.cosh() 函数返回给定复数的双曲余弦。

双曲余弦函数表示为 cosh(x),它是计算复数或实数 x 的余弦值的数学函数。此函数返回大于或等于 1 的实数值。

双曲余弦函数的数学表示定义为:

cosh(x) = (ex + e-x)/ 2

其中 e (e = 2.71828) 是自然对数的底数。此函数关于 y 轴对称;cosh(x) = cosh(-x)。

语法

以下是 Python cmath.cosh() 函数的基本语法:

cmath.cosh(x)

参数

此函数接受实数作为参数,我们需要为此找到双曲余弦。

返回值

此函数返回给定数字的双曲余弦,范围为 [1,∞)。

示例 1

在下面的示例中,我们使用 cmath.cosh() 函数计算正数的双曲余弦:

import cmath
x = 4.0
result = cmath.cosh(x)
print(result)

输出

以下是上述代码的输出:

(27.308232836016487+0j)

示例 2

当我们将分数值传递给 cmath.cosh() 函数时,它将返回一个正复数:

import cmath
from fractions import Fraction 
x = Fraction(3, -5)
result = cmath.cosh(-x)
print(result)

输出

获得的输出如下:

(1.1854652182422676+0j)

示例 3

在下面的示例中,我们使用 cmath.cosh() 函数检索负数的双曲余弦。

import cmath
x = -0.67
result = cmath.cosh(x)
print(result)

输出

以下是上述代码的输出:

(1.232972949211241-0j)

示例 4

在这里,我们创建一个循环来使用 cmath.cosh() 函数计算双曲余弦值。循环将遍历列表中的每个值。

import cmath
values = [3.0, 4.0, 7.0]
for x in values:
   result = cmath.cosh(x)
   print("cosh({}) = {}".format(x, result))

输出

生成的输出如下:

cosh(3.0) = (10.067661995777765+0j)
cosh(4.0) = (27.308232836016487+0j)
cosh(7.0) = (548.317035155212+0j)
python_modules.htm
广告
© . All rights reserved.