象征社区

把雄辩捉来施以绞刑……
 
首页常见问题与解答 (FAQ)搜索注册会员群组登录

分享 | 
 

 求逆矩阵

向下 
作者留言
symbol
一星级会员
一星级会员


帖子数 : 3
注册日期 : 08-02-09

帖子主题: 求逆矩阵   周六 二月 16, 2008 8:37 am

Option Base 1
Public Function QHLS(A() As Double, L As Long) As Double ''行列式计算L*L
Dim sum As Double
Dim B() As Double
Dim A行 As Long
Dim B列 As Long
Dim B行 As Long
Dim Cha%
ReDim B(L - 1, L - 1)
If L = 2 Then
QHLS = A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1)
Exit Function
End If
For A行 = 1 To L
For B行 = 1 To L - 1
For B列 = 1 To L - 1
If (A行 <= B行) Then Cha = 1
B(B行, B列) = A(B行 + Cha, B列 + 1)
Next B列
Cha = 0
Next B行
sum = sum + (-1) ^ (A行 + 1) * A(A行, 1) * QHLS(B(), L - 1)
Next A行
QHLS = sum
End Function

Public Function QNJZ(A() As Double, L As Long, C() As Double) As Double ''矩阵求逆
Dim A行, A列, B列, B行 As Long
Dim B() As Double
Dim Chax%, Chay%
Dim add As Double: add = 1 / QHLS(A(), L)
ReDim B(L - 1, L - 1)
For A行 = 1 To L
For A列 = 1 To L
For B行 = 1 To L - 1
If B行 < A行 Then
Chax = 0
Else
Chax = 1
End If
For B列 = 1 To L - 1
If B列 < A列 Then
Chay = 0
Else
Chay = 1
End If
B(B行, B列) = A(B行 + Chax, B列 + Chay)
Next B列
Next B行
C(A列, A行) = add * ((-1) ^ (A列 + A行)) * QHLS(B(), L - 1) ''调用求行列式值
Next A列
Next A行
End Function

Private Sub Command1_Click()
Dim D(1 To 3, 1 To 3) As Double, e As Double, F(1 To 3, 1 To 3) As Double
For i = 1 To 3
For j = 1 To 3
D(i, j) = i * (j ^ (2 + i) - 3) + j * i ^ 2 - 7
Print D(i, j);
Next j
Print
Next i
e = QHLS(D(), 3)
Print e
Call QNJZ(D(), 3, F())
For i = 1 To 3
For j = 1 To 3
Print F(i, j);
Next j
Print
Next i
End Sub
返回页首 向下
查阅用户资料
 
求逆矩阵
返回页首 
1页/共1

您在这个论坛的权限:不能在这个论坛回复主题
象征社区 :: VisulBasic编程-
转跳到: