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.