C庫 - cacosh() 函式



C語言複數庫的cacosh()函式用於計算複數反雙曲餘弦,即z的反雙曲餘弦,其分支切割在實軸上小於1的值處。這意味著該函式在除實軸z<1外的所有地方都是連續且單值的。

The inverse hyperbolic cosine (acosh) z is defined as:
acosh(z)=ln(z + √(z2 - 1))

此函式取決於z的型別。如果z是“float”型別,我們使用cacoshf()計算acosh;對於long double型別,使用cacoshl();對於double型別,使用cacosh()

語法

以下是cacosh()函式的C庫語法:

double complex cacosh( double complex z );

引數

此函式接受一個引數:

  • Z − 它表示我們要計算acosh的複數。

返回值

此函式返回z的複數反雙曲餘弦,在實軸上的區間為[0; ∞),在虛軸上的區間為[−iπ; iπ]。

示例1

以下是一個基本的C程式,演示了在複數上使用cacosh()的方法。

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

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

   // Calculate the hyperbolic cosine
   double complex res = cacosh(z);
   printf("Inverse hyperbolic cosine: %.2f%+.2fi\n", creal(res), cimag(res));

   return 0;
}

輸出

以下是輸出:

Inverse hyperbolic cosine: 1.98+1.00i

示例2

讓我們看另一個例子,使用cacosh()函式計算實軸上的反雙曲餘弦。

#include <stdio.h>
#include <math.h>
#include <complex.h>
 
int main(void)
{
    // inverse cosine of real axis
    double complex z = 1;
    double complex res = cacosh(z);
    printf("acosh(1+0i) = %f+%fi \n", creal(res), cimag(res));
}

輸出

以下是輸出:

acosh(1+0i) = 0.000000+0.000000i 

示例3

下面的C程式在計算複數的共軛後,計算複數反雙曲餘弦。

#include <stdio.h>
#include <complex.h>
#include <math.h>
int main() {
   double complex z = 1.0 + 2.0 * I;
   
   // Calculate the conjugate of z
   double complex conjugate = conj(z);

   // Compute the acosh of the conjugate
   double complex result = acosh(conjugate);

   // Display the result
   printf("Conjugate of z: %.2f + %.2fi\n", creal(conjugate), cimag(conjugate));
   printf("acosh(conjugate): %.2f + %.2fi\n", creal(result), cimag(result));

   return 0;
}

輸出

以下是輸出:

Conjugate of z: 1.00 + -2.00i
acosh(conjugate): 0.00 + 0.00i
c_library_complex_h.htm
廣告
© . All rights reserved.