本文整理汇总了Python中sympy.matrices.SparseMatrix.cofactorMatrix方法的典型用法代码示例。如果您正苦于以下问题:Python SparseMatrix.cofactorMatrix方法的具体用法?Python SparseMatrix.cofactorMatrix怎么用?Python SparseMatrix.cofactorMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.matrices.SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix.cofactorMatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sparse_matrix
# 需要导入模块: from sympy.matrices import SparseMatrix [as 别名]
# 或者: from sympy.matrices.SparseMatrix import cofactorMatrix [as 别名]
#.........这里部分代码省略.........
assert A*Ainv == sparse_eye(3)
assert A.inv(method="CH") == Ainv
assert A.inv(method="LDL") == Ainv
# test_cross
v1 = Matrix(1,3,[1,2,3])
v2 = Matrix(1,3,[3,4,5])
assert v1.cross(v2) == Matrix(1,3,[-2,4,-2])
assert v1.norm(2)**2 == 14
# conjugate
a = SparseMatrix(((1, 2 + I), (3, 4)))
assert a.C == SparseMatrix([
[1, 2 - I],
[3, 4]])
# mul
assert a*Matrix(2, 2, [1, 0, 0, 1]) == a
assert a + Matrix(2, 2, [1, 1, 1, 1]) == SparseMatrix([
[2, 3 + I],
[4, 5]])
# col join
assert a.col_join(sparse_eye(2)) == SparseMatrix([
[1, 2 + I],
[3, 4],
[1, 0],
[0, 1]])
# symmetric
assert not a.is_symmetric(simplify=False)
# test_cofactor
assert sparse_eye(3) == sparse_eye(3).cofactorMatrix()
test = SparseMatrix([[1,3,2],[2,6,3],[2,3,6]])
assert test.cofactorMatrix() == \
SparseMatrix([[27,-6,-6],[-12,2,3],[-3,1,0]])
test = SparseMatrix([[1,2,3],[4,5,6],[7,8,9]])
assert test.cofactorMatrix() == \
SparseMatrix([[-3,6,-3],[6,-12,6],[-3,6,-3]])
# test_jacobian
x = Symbol('x')
y = Symbol('y')
L = SparseMatrix(1,2,[x**2*y, 2*y**2 + x*y])
syms = [x,y]
assert L.jacobian(syms) == Matrix([[2*x*y, x**2],[y, 4*y+x]])
L = SparseMatrix(1,2,[x, x**2*y**3])
assert L.jacobian(syms) == SparseMatrix([[1, 0], [2*x*y**3, x**2*3*y**2]])
# test_QR
A = Matrix([[1,2],[2,3]])
Q, S = A.QRdecomposition()
R = Rational
assert Q == Matrix([
[5**R(-1,2), (R(2)/5)*(R(1)/5)**R(-1,2)],
[2*5**R(-1,2), (-R(1)/5)*(R(1)/5)**R(-1,2)]])
assert S == Matrix([
[5**R(1,2), 8*5**R(-1,2)],
[0, (R(1)/5)**R(1,2)]])
assert Q*S == A
assert Q.T * Q == sparse_eye(2)
R = Rational
# test nullspace