With the help of sympy.Matrix().diagonalize() method, we can diagonalize a matrix. diagonalize() returns a tuple
, where
is diagonal and
.
Syntax: Matrix().diagonalize()
Returns: Returns a tuple of matrix where the second element represents the diagonal of the matrix.
Example #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)) |
Output:
Matrix : Matrix([[3, -2, 4, -2], [5, 3, -3, -2], [5, -2, 2, -2], [5, -2, -3, 3]])
Diagonal of a matrix : Matrix([[-2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 5, 0], [0, 0, 0, 5]])
Example #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)) |
Output:
Matrix : Matrix([[1, -3, 3], [3, -5, 3], [6, -6, 4]])
Diagonal of a matrix : Matrix([[-2, 0, 0], [0, -2, 0], [0, 0, 4]])
Recommended Posts:
- Python | sympy.apart() method
- Python | sympy.crt() method
- Python | sympy.sin() method
- Python | sympy.cos() method
- Python | sympy.Add() method
- Python | sympy RGS method
- Python | sympy.rf() method
- Python | sympy.Mul() method
- Python | sympy.Add() method
- Python | sympy.nC() method
- Python | sympy.Pow() method
- Python | sympy.lcm() method
- Python | sympy.gcd() method
- Python | sympy.tan() method
- Python | sympy.ff() method
- Python | sympy.det() method
- Python | sympy.S() method
- Python | sympy.div() method
- Python | sympy.nP() method
- Python | sympy.apart() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

