SciPy - sinhm() Function



The scipy.linalg.sinhm() returns the matrix hyperbolic sine of a square matrix 'A'. This extends the hyperbolic sine function to matrices via the Taylor series expansion. The method is suitable for both real and complex matrices and yields an output of the same dimensions as A with elements being a transformation of the matrix structures in hyperbolic sine.

This method is widely used in physics, engineering, and numerical computations to model oscillatory systems, solve differential equations, and analyze system dynamics involving exponential or oscillatory growth.

The sinhm() method is very often combined with the matrix hyperbolic cosine coshm() or matrix exponential expm() to analyze and solve complex systems. For instance, while the combination of sinhm() and coshm() aids in modeling dynamic systems, its combination with expm() helps study continuous-time systems.

The coshm() method computes the hyperbolic cosine, preserving symmetry and reflecting stability, while the sinhm() method computes the hyperbolic sine, capturing oscillatory or growing behavior with skewness. They complement each other very well in modeling hyperbolic equations and system dynamics.

Syntax

Following is the syntax of the SciPy sinhm() method −

scipy.linalg.sinhm(A)

Parameters

Following are the parameters of sinhm() method

  • A (array_like) − The input matrix must be square (n x n), meaning it has the same number of rows and columns. Typically, this matrix can be either real or complex.

Return Value

sinhm_A (ndarray) − The matrix hyperbolic cosine of A will have the same dimensions as A.

Example 1: Hyperbolic Sine of a Matrix with Negative Values

In this code, we used a matrix with negative elements as input. The hyperbolic sine is applied to each diagonal element individually.

# Input: Matrix with negative values
A = np.array([[-1, -2], 
              [-3, -4]])

# Compute the matrix hyperbolic sine
sinhm_A = sinhm(A)
print(sinhm_A)

When we run above program, it produces following result

[[-4.04865381 -7.28703715]
 [-10.93055572 -14.97920953]]

Example 2: Hyperbolic Sine of a Block Diagonal Matrix

In this code, we created a block diagonal using block_diag as input. The sinhm() function computes the hyperbolic sine of each block independently, resulting in a block-diagonal output matrix.

import numpy as np
from scipy.linalg import block_diag, sinhm

# Input: Block diagonal matrix
A_block1 = np.array([[1, 2], 
                     [3, 4]])
A_block2 = np.array([[5, 6], 
                     [7, 8]])
A = block_diag(A_block1, A_block2)
sinhm_A = sinhm(A)
print(sinhm_A)

Following is an output of the above code

[[ 27.2899172   36.38306443   0.           0.        ]
 [ 54.57459664  81.86451384   0.           0.        ]
 [  0.           0.         484.83963845 674.48922344]
 [  0.           0.         786.57074402 1133.18038247]]

Example 3: Symmetry Preservation in Matrices with sinhm

When sinhm() is used on a symmetric matrix, the computation of hyperbolic sine is performed preserving the symmetry of the input in the output.

In the below code, a 22 matrix is given to sinhm(). The function utilizes eigenvalues to calculate the hyperbolic sine, and the result is a symmetric output matrix.

import numpy as np
from scipy.linalg import sinhm

# Input: Symmetric matrix
A = np.array([[1, 2], 
              [2, 1]])
sinhm_A = sinhm(A)
print(sinhm_A)

Following is an output of the above code

[[4.42133687 5.59653806]
 [5.59653806 4.42133687]]

Example 4: Hyperbolic Sine of Complex-Valued Matrices

The sinhm() function can evaluate the hyperbolic sine of matrices that are complex valued, and it returns an output matrix which will be complex valued.

In the below example we will create a 22 complex matrix. It uses its eigenvalues to compute the hyperbolic sine of each one and then it comes out as a matrix with complex values.

import numpy as np
from scipy.linalg import sinhm

# Input: Complex matrix
A = np.array([[1 + 1j, 0], 
              [0, 2 + 2j]])
sinhm_A = sinhm(A)
print(sinhm_A)

Following is an output of the above code

[[ 0.63496391+1.29845758j  0.        +0.j        ]
 [ 0.        +0.j         -1.50930649+3.42095486j]]

Example 5: Error: Non-Square Matrix Input in sinhm

The sinhm() function accepts a square matrix as the input. Providing a non-square matrix results in a ValueError.

In the below code, we will create a 23, non-square input matrix as input. Since sinhm() only accepts the square matrices as input, sinhm() throws up an error identifying the invalid argument.

import numpy as np
from scipy.linalg import expm

# Input: Matrix with negative values
A = np.array([[-1, -2], 
              [-3, -4]])

# Compute the matrix hyperbolic sine using its definition
sinhm_A = (expm(A) - expm(-A)) / 2

print(sinhm_A)

Following is an output of the above code

ValueError: expected square array_like input

Example 6: Hyperbolic Sine of an Identity Matrix

If an identity matrix were passed as argument to sinhm(), it produced another diagonal matrix with each member of the diagonals representing hyperbolic sine of 1.

In the below example, we have created a identity matrix using np.eye(n), and then the function takes the hyperbolic sine for the diagonal elements and returns a diagonal matrix of sinh(1)=1.17520.

import numpy as np
from scipy.linalg import sinhm

# Input: Identity matrix
A = np.eye(3)
sinhm_A = sinhm(A)
print(sinhm_A)

Following is an output of the above code

[[1.17520119 0.         0.        ]
 [0.         1.17520119 0.        ]
 [0.         0.         1.17520119]]

Example 7: Modeling a Damped Pendulum Using sinhm and coshm

In a damped pendulum, sinhm() represents oscillatory motion, indicating how movement decreases with time due to damping, but coshm() represents stability, demonstrating how damping forces stabilize the system. Combining these matrices allows us to better comprehend the pendulum's overall dynamics.

A illustrates a damped pendulum, with values for angular displacement, velocity, and damping forces. sinhm() calculates oscillatory motion, with positive values indicating forward motion and negative values indicating energy loss. coshm() reflects stability, and big negative values indicate severe damping effects. Combining the two yields the whole state transition matrix.

This study integrates oscillation effects (damping and motion) with stability components, revealing how the pendulum changes over time, which is critical for building control systems.

import numpy as np
from scipy.linalg import sinhm, coshm

# Define a state matrix for a damped pendulum
A = np.array([[0, 1], 
              [-9.8, -0.5]])

# Compute oscillatory behavior
oscillation_matrix = sinhm(A)

# Compute stability behavior
stability_matrix = coshm(A)

# Combine results to model full state transition
state_transition = stability_matrix + oscillation_matrix

print("State Transition Matrix:\n", state_transition)

Following is an output of the above code

State Transition Matrix:
 [[-0.77731133  0.00526464]
 [-0.05159345 -0.77994365]]
scipy_linalg.htm
Advertisements