本文整理汇总了Python中sympy.Matrix.is_diagonalizable方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.is_diagonalizable方法的具体用法?Python Matrix.is_diagonalizable怎么用?Python Matrix.is_diagonalizable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Matrix
的用法示例。
在下文中一共展示了Matrix.is_diagonalizable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_jordan_form
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_diagonalizable [as 别名]
def test_jordan_form():
m = Matrix(3,2,[-3, 1, -3, 20, 3, 10])
raises(NonSquareMatrixError, 'm.jordan_form()')
# diagonalizable
m = Matrix(3, 3, [7, -12, 6, 10, -19, 10, 12, -24, 13])
Jmust = Matrix(3, 3, [1, 0, 0, 0, 1, 0, 0, 0, -1])
(P, J) = m.jordan_form()
assert Jmust == J
assert Jmust == m.diagonalize()[1]
#m = Matrix(3, 3, [0, 6, 3, 1, 3, 1, -2, 2, 1])
#m.jordan_form() # very long
# m.jordan_form() #
# diagonalizable, complex only
# Jordan cells
# complexity: one of eigenvalues is zero
m = Matrix(3, 3, [0, 1, 0, -4, 4, 0, -2, 1, 2])
Jmust = Matrix(3, 3, [2, 0, 0, 0, 2, 1, 0, 0, 2])
assert Jmust == m.jordan_form()[1]
(P, Jcells) = m.jordan_cells()
assert Jcells[0] == Matrix(1, 1, [2])
assert Jcells[1] == Matrix(2, 2, [2, 1, 0, 2])
#complexity: all of eigenvalues are equal
m = Matrix(3, 3, [2, 6, -15, 1, 1, -5, 1, 2, -6])
Jmust = Matrix(3, 3, [-1, 0, 0, 0, -1, 1, 0, 0, -1])
(P, J) = m.jordan_form()
assert Jmust == J
#complexity: two of eigenvalues are zero
m = Matrix(3, 3, [4, -5, 2, 5, -7, 3, 6, -9, 4])
Jmust = Matrix(3, 3, [1, 0, 0, 0, 0, 1, 0, 0, 0])
(P, J) = m.jordan_form()
assert Jmust == J
m = Matrix(4, 4, [6, 5, -2, -3, -3, -1, 3, 3, 2, 1, -2, -3, -1, 1, 5, 5])
Jmust = Matrix(4, 4, [2, 1, 0, 0, 0, 2, 0, 0, 0, 0, 2, 1, 0, 0, 0, 2])
(P, J) = m.jordan_form()
assert Jmust == J
m = Matrix(4, 4, [6, 2, -8, -6, -3, 2, 9, 6, 2, -2, -8, -6, -1, 0, 3, 4])
Jmust = Matrix(4, 4, [2, 0, 0, 0, 0, 2, 1, 0, 0, 0, 2, 0, 0, 0, 0, -2])
(P, J) = m.jordan_form()
assert Jmust == J
m = Matrix(4, 4, [5, 4, 2, 1, 0, 1, -1, -1, -1, -1, 3, 0, 1, 1, -1, 2])
assert not m.is_diagonalizable()
Jmust = Matrix(4, 4, [1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4, 1, 0, 0, 0, 4])
(P, J) = m.jordan_form()
assert Jmust == J
示例2: test_diagonalization
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_diagonalizable [as 别名]
def test_diagonalization():
x, y, z = symbols('x y z')
m = Matrix(3,2,[-3, 1, -3, 20, 3, 10])
assert not m.is_diagonalizable()
assert not m.is_symmetric()
raises(NonSquareMatrixError, 'm.diagonalize()')
# diagonalizable
m = diag(1, 2, 3)
(P, D) = m.diagonalize()
assert P == eye(3)
assert D == m
m = Matrix(2,2,[0, 1, 1, 0])
assert m.is_symmetric()
assert m.is_diagonalizable()
(P, D) = m.diagonalize()
assert P.inv() * m * P == D
m = Matrix(2,2,[1, 0, 0, 3])
assert m.is_symmetric()
assert m.is_diagonalizable()
(P, D) = m.diagonalize()
assert P.inv() * m * P == D
assert P == eye(2)
assert D == m
m = Matrix(2,2,[1, 1, 0, 0])
assert m.is_diagonalizable()
(P, D) = m.diagonalize()
assert P.inv() * m * P == D
m = Matrix(3,3,[1, 2, 0, 0, 3, 0, 2, -4, 2])
assert m.is_diagonalizable()
(P, D) = m.diagonalize()
assert P.inv() * m * P == D
m = Matrix(2,2,[1, 0, 0, 0])
assert m.is_diagonal()
assert m.is_diagonalizable()
(P, D) = m.diagonalize()
assert P.inv() * m * P == D
assert P == eye(2)
# diagonalizable, complex only
m = Matrix(2,2,[0, 1, -1, 0])
assert not m.is_diagonalizable(True)
raises(MatrixError, '(D, P) = m.diagonalize(True)')
assert m.is_diagonalizable()
(P, D) = m.diagonalize()
assert P.inv() * m * P == D
m = Matrix(2,2,[1, 0, 0, I])
raises(NotImplementedError, 'm.is_diagonalizable(True)')
# !!! bug because of eigenvects() or roots(x**2 + (-1 - I)*x + I, x)
# see issue 2193
# assert not m.is_diagonalizable(True)
# raises(MatrixError, '(P, D) = m.diagonalize(True)')
# (P, D) = m.diagonalize(True)
# not diagonalizable
m = Matrix(2,2,[0, 1, 0, 0])
assert not m.is_diagonalizable()
raises(MatrixError, '(D, P) = m.diagonalize()')
m = Matrix(3,3,[-3, 1, -3, 20, 3, 10, 2, -2, 4])
assert not m.is_diagonalizable()
raises(MatrixError, '(D, P) = m.diagonalize()')
# symbolic
a, b, c, d = symbols('a b c d')
m = Matrix(2,2,[a, c, c, b])
assert m.is_symmetric()
assert m.is_diagonalizable()