Selected Reading

SciPy - coshm() Function



The linear systems of equations Ax=b, where A is a Hermitian (or symmetric) banded matrix, can be solved using the scipy.linalg.solveh_banded method. Computations are more efficient when non-zero entries are contained within a diagonal band in a banded matrix.

Compared to generic solvers, this approach is faster and uses less memory since it is specifically made to handle the structure of Hermitian or symmetric banded matrices.

TComputations are made easier by hermitian or symmetric structures, which just need the matrix's upper or lower triangle.

Syntax

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

.coshm(A)

Parameters

Following are the parameters of coshm() 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

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

Example 1

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

import numpy as np
from scipy.linalg import coshm

# Input: Diagonal matrix
A = np.diag([1, 2, 3])

# Compute the matrix hyperbolic cosine
coshm_A = coshm(A)
print(coshm_A)

When we run above program, it produces following result

[[ 1.54308063  0.          0.        ]
 [ 0.          3.76219569  0.        ]
 [ 0.          0.         10.067662  ]]

Example 2

In this code, we input 3x3 matrix as input. The coshm function computes the hyperbolic cosine of the matrix, considering its eigenvalues and transformations.

import numpy as np
from scipy.linalg import expm

# Input: Random 3x3 matrix
A = np.array([[1, 2, 0], 
              [0, 1, 3], 
              [4, 0, 1]])

# Compute the matrix hyperbolic cosine using its definition
coshm_A = (expm(A) + expm(-A)) / 2

print("Matrix Hyperbolic Cosine:\n", coshm_A)

Following is an output of the above code

[[0.  0.55]
 [0.55 0. ]]
scipy_linalg.htm
Advertisements