Dim N As Integer Dim ch As Double, Z As Double, zz As Double Dim P As Integer Dim qn(1 To 6, 1 To 6) As Double Dim nb(1 To 6, 1 To 6) As Double '返回的逆阵
'对mc(1to 6,1 to 6)求逆
Dim E(1 To 6, 1 To 12) As Double '应用的原理是: [ A I]经过矩阵行变换后成为[ I ivt_A], E阵(N,2N)阶 既 [ A I] For i = 1 To 6 For j = 1 To 6 E(i, j) = mc(i, j) Next j Next i For i = 1 To 6 For j = 7 To 12 If i = j - 6 Then E(i, j) = 1 Else E(i, j) = 0 End If Next j Next i '以上步骤实现用A,I初始化E阵
For j = 1 To 6 If E(j, j) = 0 Then For i = 1 To 6 If E(i, j) <> 0 Then Exit For Next i For P = 1 To 12 ch = E(i, P) E(i, P) = E(j, P) E(j, P) = ch Debug.Print E(i, P) Next P '将对角线元素为0的行与对应列上元素非零的行,进行行变换
End If
Z = E(j, j) For P = 1 To 12 E(j, P) = E(j, P) / Z '将矩阵E (A,I) A矩阵每行都除以对角线元素,使对角线元素变为1 Next P
For i = 1 To 6 If i <> j And E(i, j) <> 0 Then zz = E(i, j)
For P = 1 To 12 E(i, P) = E(i, P) - E(j, P) * zz Next P End If Next i Next j
For i = 1 To 6 For j = 1 To 6 nb(i, j) = E(i, j + 6) Next j Next i ' qn(i, j) = nb(i, j) '返回求出的A阵的逆阵B阵
|