C 庫 - catanh() 函式



C 的complexcatanh() 函式用於計算複數的反雙曲正切,即 z 的反雙曲正切,其分支切割位於實軸上的區間 [−1,+1] 之外。它使函式對於任何不位於實軸此區間上的複數 z 連續且單值。

The arc hyperbolic tangent (atanh) z is defined as:
atanh(z) = 1/2ln(1+z/1-z)

此函式取決於 z 的型別。如果 z 是“float”型別,我們使用catanhf()計算反雙曲正切,對於長雙精度型別,使用catanhl(),對於雙精度型別,使用catanh()

語法

以下是 catanh() 函式的 C 庫語法 -

double complex catanh( double complex z );

引數

此函式接受一個引數 -

  • Z - 它表示我們要計算 atanh 的複數。

返回值

此函式返回 z 的複數反(弧)雙曲正切,在沿實軸無界的半帶內,虛軸始終位於 [−iπ/2, +iπ/2] 之間。

示例 1

以下是一個基本的 c 程式,用於演示在複數上使用 catanh()

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

int main() {
   // Define z
   double complex z = 0.5 + 0.5*I;

   // Calculate the complex inverse hyperbolic tangent of z
   double complex res= catanh(z);

   // Display the result
   printf("catanh(%.2f + %.2fi) = %.2f + %.2fi\n", creal(z), cimag(z), creal(res), cimag(res));

   return 0;
}

輸出

以下是輸出 -

catanh(0.50 + 0.50i) = 0.40 + 0.55i

示例 2

讓我們看另一個示例,使用 catanh() 函式計算實軸的反雙曲正切。

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

輸出

以下是輸出 -

tanh(1+0i) = inf+0.00i

示例 3

下面的程式計算複數的虛線的反雙曲正切 (atanh) 和雙曲正切 (tanh),然後比較答案以檢視它們是否相同。

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

int main() {
   double complex z = 0.0 + 1.0*I;

   double complex atanh = catanh(z);
   double complex tanh = ctanh(z);

   printf("catanh(%.1fi) = %.2f + %.2fi\n", cimag(z), creal(atanh), cimag(atanh));
   printf("ctanh(%.1fi) = %.2f + %.2fi\n", cimag(z), creal(tanh), cimag(tanh));

   if (cabs(atanh) == cabs(tanh)) {
      printf("The arc hyperbolic tangent and hyperbolic tangent of the imaginary line are approximately the same.\n");
   } else {
      printf("The arc hyperbolic tangent and hyperbolic tangent of the imaginary line are different.\n");
   }
   return 0;
}

輸出

以下是輸出 -

catanh(1.0i) = 0.00 + 1.56i
ctan(1.0i) = 0.00 + 0.76i
The hyperbolic tangent and tangent of the imaginary line are different.
c_library_complex_h.htm
廣告

© . All rights reserved.