本文整理汇总了Python中sympy.Matrix.is_diagonal方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.is_diagonal方法的具体用法?Python Matrix.is_diagonal怎么用?Python Matrix.is_diagonal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Matrix
的用法示例。
在下文中一共展示了Matrix.is_diagonal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_diagonal_symmetrical
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_diagonal [as 别名]
def test_diagonal_symmetrical():
m = Matrix(2,2,[0, 1, 1, 0])
assert not m.is_diagonal()
assert m.is_symmetric()
m = Matrix(2,2,[1, 0, 0, 1])
assert m.is_diagonal()
m = diag(1, 2, 3)
assert m.is_diagonal()
assert m.is_symmetric()
m = Matrix(3,3,[1, 0, 0, 0, 2, 0, 0, 0, 3])
assert m == diag(1, 2, 3)
m = Matrix(2,3,[0, 0, 0, 0, 0, 0])
assert not m.is_symmetric()
x, y = symbols('x','y')
m = Matrix(3,3,[1, x**2 + 2*x + 1, y, (x + 1)**2 , 2, 0, y, 0, 3])
assert m.is_symmetric()
示例2: test_diagonal_symmetrical
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_diagonal [as 别名]
def test_diagonal_symmetrical():
m = Matrix(2,2,[0, 1, 1, 0])
assert not m.is_diagonal()
assert m.is_symmetric()
assert m.is_symmetric(simplify=False)
m = Matrix(2,2,[1, 0, 0, 1])
assert m.is_diagonal()
m = diag(1, 2, 3)
assert m.is_diagonal()
assert m.is_symmetric()
m = Matrix(3,3,[1, 0, 0, 0, 2, 0, 0, 0, 3])
assert m == diag(1, 2, 3)
m = Matrix(2, 3, [0, 0, 0, 0, 0, 0])
assert not m.is_symmetric()
assert m.is_diagonal()
m = Matrix(((5, 0), (0, 6), (0, 0)))
assert m.is_diagonal()
m = Matrix(((5, 0, 0), (0, 6, 0)))
assert m.is_diagonal()
x, y = symbols('x y')
m = Matrix(3,3,[1, x**2 + 2*x + 1, y, (x + 1)**2 , 2, 0, y, 0, 3])
assert m.is_symmetric()
assert not m.is_symmetric(simplify=False)
assert m.expand().is_symmetric(simplify=False)
示例3: test_diagonalization
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_diagonal [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()