Compute Jordan normal form of matrix in Python / NumPy

不羁的心 提交于 2019-11-27 03:21:30

问题


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 SciPy?


回答1:


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]])



回答2:


There's this implementation.

It will definitely not be as fast as MATLAB, though.



来源:https://stackoverflow.com/questions/20312216/compute-jordan-normal-form-of-matrix-in-python-numpy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!