Compute Jordan normal form of matrix in Python / NumPy

前端 未结 2 581
小蘑菇
小蘑菇 2020-12-09 19:11

In MATLAB you can compute the Jordan normal form of a matrix by using the the function jordan.

It there an equivalent function available in NumPy and Sc

2条回答
  •  抹茶落季
    2020-12-09 19:14

    The MATLAB jordan function is from the Symbolic Math Toolbox, so it does not seem unreasonable to get its Python replacement from the SymPy library. Specifically, the Matrix class has the method jordan_form. You can pass a numpy array as an argument when you create a sympy Matrix. For example, the following is from the wikipedia article on the Jordan normal form:

    In [1]: import numpy as np
    
    In [2]: from sympy import Matrix
    
    In [3]: a = np.array([[5, 4, 2, 1], [0, 1, -1, -1], [-1, -1, 3, 0], [1, 1, -1, 2]])
    
    In [4]: m = Matrix(a)
    
    In [5]: m
    Out[5]: 
    Matrix([
    [ 5,  4,  2,  1],
    [ 0,  1, -1, -1],
    [-1, -1,  3,  0],
    [ 1,  1, -1,  2]])
    
    In [6]: P, J = m.jordan_form()
    
    In [7]: J
    Out[7]: 
    Matrix([
    [1, 0, 0, 0],
    [0, 2, 0, 0],
    [0, 0, 4, 1],
    [0, 0, 0, 4]])
    

提交回复
热议问题