SciPy - sinm() Function



The matrix sine of a square matrix is calculated via the scipy.linalg.sinm function. Although it uses a series expansion to work on matrices, the matrix sine is defined similarly to the sine function for scalars. Numerous applications, including the analysis of dynamic systems and the solution of differential equations, benefit from this.

We use sinm() while dealing with systems involving rotational, oscillatory, or wave-like behaviour, such as when analyzing the behavior of systems defined by matrix equations and solving systems of equations that include the sine of a matrix.

This method is valuable in solving problems in differential equations, dynamic systems, and control theory, which contain functions of matrices like sine and cosine.

Syntax

Following is the syntax of the SciPy sinm() method

.sinm(A)

Parameters

This method accepts the following parameters −

  • A − A square matrix for which the matrix sine is to be computed.

Return Value

The sinm(A) returns a sinA(ndarray), where it represents the computed matrix sine, having the same shape as the input matrix.

Example 1

This is the basic example of sinm() method demonstrates the sine of a 2x2 matrix with real values.

In this example, sinm applies the matrix sine function to each element of the matrix.

import numpy as np
from scipy.linalg import sinm

A = np.array([[1, 2],
              [3, 4]])
sin_A = sinm(A)
print(sin_A)       

When we run above program, it produces following result

[[-0.01791444  0.31318642]
 [-0.47128663  0.29594269]]

Example 2: Sine of a Diagonal Matrix with Negative Values

This example demonstrates the use of the matrix exponential to solve a diagonal matrix with negative values.

In this example, the sine of each diagonal entry is computed separately.The sine of -1 and -2 is calculated, resulting in values along the diagonal.

import numpy as np
from scipy.linalg import sinm

A = np.array([[-1, 0],
              [0, -2]])
sin_A = sinm(A)
print(sin_A) 

When we run above program, it produces following result

[[-0.84147098  0.        ]
 [ 0.         -0.90929743]]
scipy_linalg.htm
Advertisements