How to do it…

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.

  1. Import the relevant packages:
import numpy as np
from sympy import Matrix
  1. Initialize an array of numbers:
a = np.array([[5, 4, 2, 1], [0, 1, -1, -1], [-1, -1, 3, 0], [1, 1, -1, 2]]) 
  1. Convert the array into a matrix format to be used by the jordan_form function:
m = Matrix(a) 
  1. Apply the function on the preceding matrix:
P, J = m.jordan_form() 
  1. 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]])
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset