- 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庫 - sinh() 函式
C庫函式`sinh()`,型別為double,接受引數x,返回雙曲正弦值。
此函式在複數計算中非常有用,尤其是在處理復指數的虛部時。我們也可以在數值方法中使用此函式。
語法
以下是C庫函式`sinh()`的語法:
double sinh(double x)
引數
此函式只接受一個引數。
x − 這是一個浮點值。
返回值
此函式返回x的雙曲正弦值。
示例1
以下是一個基本的C庫程式,用於演示`sinh()`函式。
#include <stdio.h>
#include <math.h>
int main () {
double x, ret;
x = 0.5;
ret = sinh(x);
printf("The hyperbolic sine of %lf is %lf degrees", x, ret);
return(0);
}
輸出
以上程式碼產生以下輸出:
The hyperbolic sine of 0.500000 is 0.521095 degrees
示例2
該程式對浮點值陣列進行操作,透過迴圈計算雙曲正弦值。
#include <stdio.h>
#include <math.h>
int main() {
double val[] = {11.0, 21.0, 31.0, 41.0};
int num_val = sizeof(val) / sizeof(val[0]);
printf("Hyperbolic Sine values:\n");
for (int i = 0; i < num_val; ++i) {
double res = sinh(val[i]);
printf("sinh(%.2f) = %.4f\n", val[i], res);
}
return 0;
}
輸出
執行以上程式碼後,我們得到以下結果:
Hyperbolic Sine values: sinh(11.00) = 29937.0708 sinh(21.00) = 659407867.2416 sinh(31.00) = 14524424832623.7129 sinh(41.00) = 319921746765027456.0000
示例3
在這個程式中,我們使用梯形法則進行數值積分來計算雙曲正弦值。
#include <stdio.h>
#include <math.h>
// Function to calculate the hyperbolic sine
double sinh(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
// Numerical integration using the trapezium rule
double integrate_sinh(double a, double b, int num_intervals) {
double h = (b - a) / num_intervals;
double integral = 0.0;
for (int i = 0; i < num_intervals; ++i) {
double x0 = a + i * h;
double x1 = a + (i + 1) * h;
integral += (sinh(x0) + sinh(x1)) * h / 2.0;
}
return integral;
}
int main() {
// Lower limit of integration
double a = 0.0;
// Upper limit of integration
double b = 2.0;
// Number of intervals for numerical integration
int num_intervals = 1000;
double result = integrate_sinh(a, b, num_intervals);
printf("Integral of sinh(x) from %.2lf to %.2lf = %.6lf\n", a, b, result);
return 0;
}
輸出
執行程式碼後,我們得到以下結果:
Integral of sinh(x) from 0.00 to 2.00 = 2.762197
廣告