当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.is_symmetric方法代码示例

本文整理汇总了Python中sympy.Matrix.is_symmetric方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.is_symmetric方法的具体用法?Python Matrix.is_symmetric怎么用?Python Matrix.is_symmetric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.Matrix的用法示例。


在下文中一共展示了Matrix.is_symmetric方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_diagonal_symmetrical

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_symmetric [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()
开发者ID:pyc111,项目名称:sympy,代码行数:23,代码来源:test_matrices.py

示例2: test_diagonal_symmetrical

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_symmetric [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)
开发者ID:jegerjensen,项目名称:sympy,代码行数:33,代码来源:test_matrices.py

示例3: test_diagonalization

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import is_symmetric [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()
开发者ID:robotment,项目名称:sympy,代码行数:76,代码来源:test_matrices.py


注:本文中的sympy.Matrix.is_symmetric方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。