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