看板 Visual_Basic 關於我們 聯絡資訊
如題 我都是被這些變數給搞混了!! 不知有沒有人使用過這個模組 知道的高手說一下 感激不盡!! 我把我的模組PO上來 Public Function InverseLU(ByRef A() As Double, _ ByRef Pivots() As Long, _ ByVal N As Long) As Boolean Dim Result As Boolean Dim WORK() As Double Dim I As Long Dim IWS As Long Dim J As Long Dim JB As Long Dim JJ As Long Dim JP As Long Dim JP1 As Long Dim V As Double Dim i_ As Long Result = True ' ' Quick return if possible ' If N = 0# Then InverseLU = Result Exit Function End If ReDim WORK(1# To N) ' ' Form inv(U) ' If Not InvTriangular(A, N, True, False) Then Result = False InverseLU = Result Exit Function End If ' ' Solve the equation inv(A)*L = inv(U) for inv(A). ' For J = N To 1# Step -1 ' ' Copy current column of L to WORK and replace with zeros. ' For I = J + 1# To N Step 1 WORK(I) = A(I, J) A(I, J) = 0# Next I ' ' Compute current column of inv(A). ' If J < N Then JP1 = J + 1# For I = 1# To N Step 1 V = 0# For i_ = JP1 To N Step 1 V = V + A(I, i_) * WORK(i_) Next i_ A(I, J) = A(I, J) - V Next I End If Next J ' ' Apply column interchanges. ' For J = N - 1# To 1# Step -1 JP = Pivots(J) If JP <> J Then For i_ = 1# To N Step 1 WORK(i_) = A(i_, J) Next i_ For i_ = 1# To N Step 1 A(i_, J) = A(i_, JP) Next i_ For i_ = 1# To N Step 1 A(i_, JP) = WORK(i_) Next i_ End If Next J InverseLU = Result End Function '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Inversion of a general matrix. ' 'Input parameters: ' A - matrix. Array whose indexes range within [1..N, 1..N]. ' N - size of matrix A. ' 'Output parameters: ' A - inverse of matrix A. ' Array whose indexes range within [1..N, 1..N]. ' 'Result: ' True, if the matrix is not singular. ' False, if the matrix is singular. ' ' -- ALGLIB -- ' Copyright 2005 by Bochkanov Sergey ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function Inverse(ByRef A() As Double, ByVal N As Long) As Boolean Dim Result As Boolean Dim Pivots() As Long Call LUDecomposition(A, N, N, Pivots) Result = InverseLU(A, Pivots, N) Inverse = Result End Function 我有一個3*3的矩陣,要將它做反(逆)矩陣(inv) 但是我不知怎麼去呼叫它 我的矩陣如下 1 5 6 7 4 2 -3 6 7 做完反(逆)矩陣如下 0.2462 0.0154 -0.2154 -0.8462 0.3846 0.6154 0.8308 -0.3231 -0.4769 這是用matlab做出來的,但是現在要用vb寫...就一直卡在這裡 請各位高手幫幫忙 感激不盡!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.113.139.87 ※ 編輯: silent1017 來自: 59.113.139.87 (08/24 16:21) ※ 編輯: silent1017 來自: 61.223.244.68 (08/25 20:47) ※ 編輯: silent1017 來自: 61.223.232.178 (08/26 15:13)