- C標準庫
- C庫 - 首頁
- C庫 - <assert.h>
- C庫 - <complex.h>
- C庫 - <ctype.h>
- C庫 - <errno.h>
- C庫 - <fenv.h>
- C庫 - <float.h>
- C庫 - <inttypes.h>
- C庫 - <iso646.h>
- C庫 - <limits.h>
- C庫 - <locale.h>
- C庫 - <math.h>
- C庫 - <setjmp.h>
- C庫 - <signal.h>
- C庫 - <stdalign.h>
- C庫 - <stdarg.h>
- C庫 - <stdbool.h>
- C庫 - <stddef.h>
- C庫 - <stdio.h>
- C庫 - <stdlib.h>
- C庫 - <string.h>
- C庫 - <tgmath.h>
- C庫 - <time.h>
- C庫 - <wctype.h>
- C程式設計資源
- C程式設計 - 教程
- C - 有用資源
C庫 - ctanh() 函式
C語言複數庫的ctanh()函式用於計算z(複數)的雙曲正切值。雙曲正切函式的性質與普通正切函式類似,區別在於它與雙曲線而不是圓有關。
雙曲正切(tanh) z(複數)定義為:tanh(z)= sinh(z)/cosh(z)
此函式取決於z(複數)的型別。如果z是“float”型別,我們使用ctanhf()計算tanh;對於long double型別,使用ctanhl();對於double型別,使用ctanh()。
語法
以下是ctanh()函式的C庫語法:
double complex ctanh( double complex z );
引數
此函式接受單個引數:
-
Z - 代表我們要計算tanh的複數。
返回值
此函式返回z(複數)的複數雙曲正切值。
示例1
以下是一個基本的C程式,演示瞭如何在複數上使用ctanh()。
#include <stdio.h>
#include <complex.h>
int main() {
double complex z = 4.0 + 5.0 * I;
// Calculate the hyperbolic tangent
double complex res = ctanh(z);
printf("Complex tanh: %.2f%+.2fi\n", creal(res), cimag(res));
return 0;
}
輸出
以下是輸出:
Complex tanh: 1.00-0.00i
示例2
讓我們看另一個例子,使用ctanh()函式計算實數線的雙曲正切值。
#include <stdio.h>
#include <math.h>
#include <complex.h>
int main(void)
{
// real line
double complex z = ctanh(1);
printf("tanh(1+0i) = %.2f+%.2fi \n", creal(z), cimag(z));
}
輸出
以下是輸出:
tanh(1+0i) = 0.76+0.00i
示例3
下面的程式計算複數虛數線的雙曲正切(tanh)和正切(tan)值,然後比較結果以檢視它們是否相同。
#include <complex.h>
#include <stdio.h>
#include <math.h>
int main() {
double complex z = 0.0 + 1.0*I;
double complex tanh = ctanh(z);
double complex tan = ctan(z);
printf("ctanh(%.1fi) = %.2f + %.2fi\n", cimag(z), creal(tanh), cimag(tanh));
printf("ctan(%.1fi) = %.2f + %.2fi\n", cimag(z), creal(tan), cimag(tan));
if (cabs(tanh - tan) < 1e-10) {
printf("The hyperbolic tangent and tangent of the imaginary line are approximately the same.\n");
} else {
printf("The hyperbolic tangent and tangent of the imaginary line are different.\n");
}
return 0;
}
輸出
以下是輸出:
ctanh(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
廣告