明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1672|回复: 0

[VBA]各位老大我改了一段矩阵求逆的程序~请帮忙改正一下谢谢

[复制链接]
发表于 2006-5-30 11:26:00 | 显示全部楼层 |阅读模式

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阵
 

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 02:24 , Processed in 0.151290 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表