1.数学定义
定义:对于n阶矩阵A,如果有一个n阶矩阵B,使
AB=BA=E
则说矩阵A是可逆的,并把矩阵B称为A的逆矩阵.
定理:若矩阵A可逆,则|A|≠0.
定理:若|A|≠0,则矩阵A可逆,且
A-1=1/|A|*A*
2.算法实现
1)矩阵的行列式
‘‘‘ <summary> ‘‘‘ 返回一个矩阵的行列式 ‘‘‘ </summary> ‘‘‘ <param name="dMatrix">原矩阵</param> ‘‘‘ <returns></returns> ‘‘‘ <remarks></remarks> Public Shared Function DetOfMatrix(ByVal dMatrix As Matrix) As Determinant Dim tempDet As New Determinant(dMatrix.RowLength) For i = 1 To tempDet.Rank For j = 1 To tempDet.Rank tempDet.Item(i, j) = dMatrix.Item(i, j) Next Next Return tempDet End Function
2)矩阵求逆
‘‘‘ <summary> ‘‘‘ 返回一个矩阵的逆矩阵 ‘‘‘ </summary> ‘‘‘ <param name="iMatrix">原矩阵</param> ‘‘‘ <returns></returns> ‘‘‘ <remarks></remarks> Public Shared Function InverseMatrix(ByVal iMatrix As Matrix) As Matrix Dim TempMatrix As New Matrix(iMatrix.RowLength, iMatrix.ColLength) Dim TempDet As Determinant = Matrix.DetOfMatrix(iMatrix) Dim TempDetValue As Double = TempDet.value TempMatrix = Matrix.AdjointMatrix(iMatrix) MsgBox(TempDetValue) If Not TempDetValue = 0 Then Return (TempMatrix * (1 / TempDetValue)) Else Return Nothing End If End Function
时间: 2024-10-12 20:56:02