📜  Python同情 | Matrix.diagonalize() 方法

📅  最后修改于: 2022-05-13 01:54:49.983000             🧑  作者: Mango

Python同情 | Matrix.diagonalize() 方法

借助sympy.Matrix().diagonalize()方法,我们可以对矩阵进行对角化。对角化()返回一个元组(P, D) , 在哪里D是对角线并且M = PDP^{-1} .

示例 #1:

# import sympy 
from sympy import * M = Matrix([[3, -2,  4, -2],
                                [5,  3, -3, -2],
                                [5, -2,  2, -2],
                                [5, -2, -3,  3]])
  
print("Matrix : {} ".format(M))
   
# Use sympy.diagonalize() method 
P, D = M.diagonalize()  
      
print("Diagonal of a matrix : {}".format(D))  

输出:

示例 #2:

# import sympy 
from sympy import * M = Matrix([[1, -3, 3], [3, -5, 3], [6, -6, 4]]) 
print("Matrix : {} ".format(M))
   
# Use sympy.diagonalize() method 
P, D = M.diagonalize()  
      
print("Diagonal of a matrix : {}".format(D))

输出: