Solving equations
Author Message
Solving equations

Hi!
Does anyone have a function, module to solve linear matrix equations by
Gauss method
written in Vbasic :-) ?
This could help me to end my project...

Best regards,

maras

Thu, 21 Jun 2001 03:00:00 GMT
Solving equations
Marek:

Here is something I wrote a while ago. It solves a matrix where the Number
of rows = the number of columns.  A() is the matrix, N is the number of
rows/cols, and X is the solution vector.  You may need to modify if the
matrix is not square.  Also, YOU MUST VERIFY THE ACCURACY YOURSELF. I have
not run into problems, but I cannot guarantee it will work. Good Luck

Sub Gauss2(A() As Double, N As Integer, X() As Double, ErrorVal As Boolean)
On Error GoTo Err_Gauss2

Dim N1 As Integer
Dim M As Integer
Dim K As Integer
Dim K1 As Integer
Dim K2 As Integer
Dim B0 As Double
Dim I As Integer
Dim B1 As Double
Dim J As Integer
Dim C As Double
Dim I1 As Double
Dim S As Double
Dim J1 As Double

N1 = N - 1
M = N + 1

'Find the row with the largest pivot element
For K = 1 To N1
K1 = K + 1
K2 = K
B0 = Abs(A(K, K))
For I = K1 To N
B1 = Abs(A(I, K))
If (B0 - B1) < 0 Then
B0 = B1
K2 = I
End If
Next I

'Interchange rows to obtain the largest pivot element
If K2 - K <> 0 Then
For J = K To M
C = A(K2, J)
A(K2, J) = A(K, J)
A(K, J) = C
Next J
End If

'Apply the Gaussean Elimination Algorithm
For I = K1 To N
For J = K1 To M
A(I, J) = A(I, J) - A(I, K) * A(K, J) / A(K, K)
Next J
A(I, K) = 0#
Next I
Next K

'Apply Back Substitution
X(N) = A(N, M) / A(N, N)
For I1 = 1 To N1
I = N - I1
S = 0#
J1 = I + 1
For J = J1 To N
S = S + A(I, J) * X(J)
Next J
X(I) = (A(I, M) - S) / A(I, I)
Next I1

Exit_Gauss2:
Exit Sub

Err_Gauss2:
Select Case Err
Case 6
MsgBox "Structure is not stable", vbCritical, "Solution Termination"
ErrorVal = True
Case Else
MsgBox Error, , Err
ErrorVal = True
End Select
Resume Exit_Gauss2

End Sub

Quote:

>Hi!
>Does anyone have a function, module to solve linear matrix equations by
>Gauss method
>written in Vbasic :-) ?
>This could help me to end my project...

>Best regards,

>    maras

Fri, 22 Jun 2001 03:00:00 GMT
Solving equations
http://lib.stat.cmu.edu/apstat/
Has tons of Stat Algorithms.  Among these are methods for solving
linear equations.   However they are mostly fortran.
Neila
Quote:

>Hi!
>Does anyone have a function, module to solve linear matrix equations by
>Gauss method
>written in Vbasic :-) ?
>This could help me to end my project...

>Best regards,

>    maras

Sat, 23 Jun 2001 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages