C 库 - ccosh() 函数



C 的complexccosh() 函数用于计算 z(复数)的双曲余弦。双曲余弦函数具有与普通余弦函数类似的性质,但它与双曲线而不是圆形有关。

The hyperbolic cos(cosh) z(complex number) is defined as:
cosh(z)= ez + e-z/2

此函数取决于 z(复数)的类型。如果 z 是“float”类型,我们使用ccoshf()计算cosh,对于长双精度类型,使用ccoshl(),对于双精度类型,使用ccosh()

语法

以下是 ccosh() 函数的 C 库语法 -

double complex ccosh( double complex z );

参数

此函数接受单个参数 -

  • Z - 它表示我们要计算 cosh 的复数。

返回值

此函数返回 z(复数)的复双曲余弦。

示例 1

以下是演示如何在复数上使用 ccosh() 的基本 C 程序。

#include <stdio.h>
#include <complex.h>

int main() {
   double complex z = 2.0 + 3.0 * I;

   // Calculate the cosh
   double complex res = ccosh(z);
   printf("Complex cosh: %.2f%+.2fi\n", creal(res), cimag(res));

   return 0;
}

输出

以下是输出 -

Complex cosh: -3.72+0.51i

示例 2

让我们看另一个例子,使用 ccosh() 函数计算实数线的双曲余弦。

#include <stdio.h>
#include <math.h>
#include <complex.h>
 
int main(void)
{
    // real line
    double complex z = ccosh(1);
    printf("cosh(1+0i) = %f+%fi (cosh(1)=%f)\n", creal(z), cimag(z), cosh(1));
}

输出

以下是输出 -

cosh(1+0i) = 1.543081+0.000000i (cosh(1)=1.543081)

示例 3

下面的程序使用 ccosh() 函数计算虚数线的双曲余弦。

#include <stdio.h>
#include <math.h>
#include <complex.h>
 
int main(void)
{
   // imaginary line
   double complex z = ccosh(I); 
   printf("cosh(0+1i) = %f+%fi ( cos(1)=%f)\n", creal(z), cimag(z), cos(1));
}

输出

以下是输出 -

cosh(0+1i) = 0.540302+0.000000i ( cos(1)=0.841471)
c_library_complex_h.htm
广告

© . All rights reserved.