Finding the matrix hyperbolic sine
Here’s a Java program that calculates the hyperbolic sine of a matrix:
import java.util.Arrays; public class MatrixHyperbolicSine { public static double[][] matrixSinh(double[][] matrix) { int rows = matrix.length; int cols = matrix[0].length; double[][] result = new double[rows][cols]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { result[i][j] = Math.sinh(matrix[i][j]); } } return result; } public static void main(String[] args) { double[][] inputMatrix = { {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }; double[][] resultMatrix = matrixSinh(inputMatrix); System.out.println("Input Matrix:"); printMatrix(inputMatrix); System.out.println("Result Matrix (Hyperbolic Sine):"); printMatrix(resultMatrix); } public static void printMatrix(double[][] matrix) { for (double[] row : matrix) { System.out.println(Arrays.toString(row)); } System.out.println(); } }
This program defines a method `matrixSinh()` that takes a 2D matrix as input and returns a new matrix with the hyperbolic sine of each element. The `main()` method demonstrates how to use this method with a sample input matrix. The `printMatrix()` method is a utility function to print the matrix.
When you run this program, it will output the original input matrix and the result matrix, which contains the hyperbolic sine of each element in the input matrix.
No comments yet! You be the first to comment.