In order to calculate the Jordan form of a matrix, we will using the jordan_form function available within the sympy package.
In the following code, we will look into obtaining the Jordan form of a given matrix in Python.
- Import the relevant packages:
import numpy as np
from sympy import Matrix
- Initialize an array of numbers:
a = np.array([[5, 4, 2, 1], [0, 1, -1, -1], [-1, -1, 3, 0], [1, 1, -1, 2]])
- Convert the array into a matrix format to be used by the jordan_form function:
m = Matrix(a)
- Apply the function on the preceding matrix:
P, J = m.jordan_form()
- Extract the output of the jordan_form, which is J:
J
Matrix([[1.0, 0, 0, 0],[ 0, 2.0, 0, 0],[ 0, 0, 4.0, 1],[ 0, 0, 0, 4.0]])