Java sinh 函数是 Math 函数之一,用于计算指定表达式的双曲正弦值。
Java 编程语言中 Math.sinh 的基本语法如下所示。
static double sinh(double number); //Return Type is Double // In order to use in program: Math.sinh(double number);
Number: 这是您想找到双曲正弦值的数字或有效的数值表达式。
- 如果 number 参数是正数或负数,Math.sinh 函数将返回双曲正弦值。
- 如果 number 参数为零,Math.sinh 函数将返回具有相同符号的零。
- 当 number 参数为无穷大时,Math.sinh 函数将返回具有相同符号的“无穷大”结果。
- 如果它不是一个数字,Math.sinh 函数将返回 NaN(非数字)。
注意:x 的双曲正弦定义为 (e^x – e^-x)/2,其中 e 是欧拉数。
Java sinh 函数示例
在此示例中,我们使用 Math.sinh 函数来查找正值和负值的双曲正弦值并显示输出。
package TrigonometricFunctions;
public class SinhMethod {
public static void main(String[] args) {
double x = Math.sinh(10.65 - 13.95 + 4.38);
System.out.println("Hyperbolic Sine value = " + x);
System.out.println("\nHyperbolic Sine value of Positive Value = " + Math.sinh(4.25));
System.out.println("Hyperbolic Sine value of Positive Value = " + Math.sinh(7.28));
System.out.println("\nHyperbolic Sine value of Negative Value = " + Math.sinh(-2.85));
System.out.println("Hyperbolic Sine value of Negative Value = " + Math.sinh(-0.95));
double m = Math.toRadians(45);
System.out.println("\nHyperbolic Sine value of Negative Value = " + Math.sinh(m));
}
}

在此 Sinh 函数示例中,我们声明了一个 Double 类型的变量 x。接下来,我们直接在表达式上使用了 Math.sinh 函数。在这里,我们使用 System.out.println 语句将结果作为输出打印出来。
double x = Math.sinh(10.65 - 13.95 + 4.38);
System.out.println("Hyperbolic Sine value = " + x);
接下来,我们直接在正双精度值上使用了 Math.sinh 函数。
System.out.println("\nHyperbolic Sine value of Positive Value = " + Math.sinh(4.25));
System.out.println("Hyperbolic Sine value of Positive Value = " + Math.sinh(7.28));
接下来,我们直接在负双精度值上使用了该函数。
System.out.println("\nHyperbolic Sine value of Negative Value = " + Math.sinh(-2.85));
System.out.println("Hyperbolic Sine value of Negative Value = " + Math.sinh(-0.95));
在这里,我们声明了一个 Double 类型的变量并为其赋值。接下来,我们使用 Math.toRadians 函数将 45 转换为等效的弧度。然后 System.out.println 语句将结果作为输出打印出来。
double m = Math.toRadians(45);
System.out.println("\nHyperbolic Sine value of Negative Value = " + Math.sinh(m));
Java sinh 数组示例
在此程序中,我们查找批量数据的双曲正弦值。在这里,我们将声明一个双精度类型数组并查找数组元素的双曲正弦值。
package TrigonometricFunctions;
public class SinhMethodOnArrays {
public static void main(String[] args) {
double [] myArray = {0, 1, 0.30, 0.45, 0.60, 0.75, -0.90, -0.920, -1.98, -6.48};
for (int i = 0; i < myArray.length; i++) {
System.out.format("Hyperbolic Sine of Array Element %.2f = %.4f\n", myArray[i], Math.sinh(myArray[i]));
}
}
}
Hyperbolic Sine of Array Element 0.00 = 0.0000
Hyperbolic Sine of Array Element 1.00 = 1.1752
Hyperbolic Sine of Array Element 0.30 = 0.3045
Hyperbolic Sine of Array Element 0.45 = 0.4653
Hyperbolic Sine of Array Element 0.60 = 0.6367
Hyperbolic Sine of Array Element 0.75 = 0.8223
Hyperbolic Sine of Array Element -0.90 = -1.0265
Hyperbolic Sine of Array Element -0.92 = -1.0554
Hyperbolic Sine of Array Element -1.98 = -3.5523
Hyperbolic Sine of Array Element -6.48 = -325.9847
我们使用For 循环来迭代数组。在 sinh For 循环中,我们将 i 值初始化为 0。接下来,编译器将检查条件 (i < myArray.length)。myArray.length 查找数组的长度。
for (int i = 0; i < myArray.length; i++) {
以下语句将打印输出。如果您观察代码片段,我们在 System.out.format 语句内部直接使用了 sinh Math 函数。在这里,编译器将调用 Math.sinh 方法(static double sinh(double number) )来查找相应的正弦值。
System.out.format("Hyperbolic Sine of Array Element %.2f = %.4f\n", myArray[i], Math.sinh(myArray[i]));
注意:要查找单个项的双曲正弦值,请使用:Math.sinh(myArray[index_position])
Java sinh ArrayList 示例
在此 Java 程序中,我们将声明一个双精度类型的 ArrayList 并查找列表元素双曲正弦值。
package TrigonometricFunctions;
import java.util.ArrayList;
public class SinhMethodOnArrayList {
public static void main(String[] args) {
ArrayList<Double> myList = new ArrayList<Double>(5);
myList.add(2.45);
myList.add(9.49);
myList.add(-15.60);
myList.add(-0.75);
myList.add(5.48);
myList.add(-5.48);
for (double x : myList) {
System.out.format("Hyperbolic Sine value of ArrayList Item %.2f = %.4f \n", x, Math.sinh(x));
}
}
}
Hyperbolic Sine value of ArrayList Item 2.45 = 5.7510
Hyperbolic Sine value of ArrayList Item 9.49 = 6613.3976
Hyperbolic Sine value of ArrayList Item -15.60 = -2978269.0066
Hyperbolic Sine value of ArrayList Item -0.75 = -0.8223
Hyperbolic Sine value of ArrayList Item 5.48 = 119.9213
Hyperbolic Sine value of ArrayList Item -5.48 = -119.9213
我们使用 For 循环迭代 ArrayList 中的双精度值。
for (double x : myList) {
在这里,编译器将调用 math sinh 方法( static double sinh(double x) )来查找相应的正弦值并打印输出。
System.out.format("Hyperbolic Sine value of ArrayList Item %.2f = %.4f \n", x, Math.sinh(x));