稠密矩阵#
- class sympy.matrices.dense.DenseMatrix[源代码]#
Matrix implementation based on DomainMatrix as the internal representation
- LDLdecomposition(hermitian=True)[源代码]#
返回矩阵A的LDL分解(L,D),使L * D * 五十、 如果hermitian标志为真,则H==A,或L * D * 五十、 如果hermitian为假,则T==A。这种方法消除了平方根的使用。此外,这确保了L的所有对角线条目都是1。如果Hermitian为真,A必须是Hermitian正定矩阵,否则必须是对称矩阵。
实例
>>> from sympy import Matrix, eye >>> A = Matrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11))) >>> L, D = A.LDLdecomposition() >>> L Matrix([ [ 1, 0, 0], [ 3/5, 1, 0], [-1/5, 1/3, 1]]) >>> D Matrix([ [25, 0, 0], [ 0, 9, 0], [ 0, 0, 9]]) >>> L * D * L.T * A.inv() == eye(A.rows) True
矩阵可以有复杂的条目:
>>> from sympy import I >>> A = Matrix(((9, 3*I), (-3*I, 5))) >>> L, D = A.LDLdecomposition() >>> L Matrix([ [ 1, 0], [-I/3, 1]]) >>> D Matrix([ [9, 0], [0, 4]]) >>> L*D*L.H == A True
- as_mutable()[源代码]#
返回此矩阵的可变版本
实例
>>> from sympy import ImmutableMatrix >>> X = ImmutableMatrix([[1, 2], [3, 4]]) >>> Y = X.as_mutable() >>> Y[1, 1] = 5 # Can set values in Y >>> Y Matrix([ [1, 2], [3, 5]])
- cholesky(hermitian=True)[源代码]#
返回矩阵a的Cholesky类型分解,使L * L.H == A if hermitian flag is True, or L * 五十、 如果hermitian为假,则T==A。
如果Hermitian为真,A必须是一个Hermitian正定矩阵,如果Hermitian为False,则必须是对称矩阵。
实例
>>> from sympy import Matrix >>> A = Matrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11))) >>> A.cholesky() Matrix([ [ 5, 0, 0], [ 3, 3, 0], [-1, 1, 3]]) >>> A.cholesky() * A.cholesky().T Matrix([ [25, 15, -5], [15, 18, 0], [-5, 0, 11]])
矩阵可以有复杂的条目:
>>> from sympy import I >>> A = Matrix(((9, 3*I), (-3*I, 5))) >>> A.cholesky() Matrix([ [ 3, 0], [-I, 2]]) >>> A.cholesky() * A.cholesky().H Matrix([ [ 9, 3*I], [-3*I, 5]])
当矩阵不是正定矩阵时,非厄米型Cholesky分解可能是有用的。
>>> A = Matrix([[1, 2], [2, 1]]) >>> L = A.cholesky(hermitian=False) >>> L Matrix([ [1, 0], [2, sqrt(3)*I]]) >>> L*L.T == A True
- class sympy.matrices.immutable.ImmutableDenseMatrix(*args, **kwargs)[源代码]
创建矩阵的不可变版本。
实例
>>> from sympy import eye, ImmutableMatrix >>> ImmutableMatrix(eye(3)) Matrix([ [1, 0, 0], [0, 1, 0], [0, 0, 1]]) >>> _[0, 0] = 42 Traceback (most recent call last): ... TypeError: Cannot set values of ImmutableDenseMatrix