Тимофей » 03.05.2005 (Вт) 11:10
' метод Гаусса с обратным ходом
Public Sub MetodGausa(a() As Single, X() As Single, B() As Single, N As Integer)
Dim k As Integer, IM As Integer, D As Single, C As Single, P As Integer, Sum As Single, L As Integer
ReDim Preserve a(N, N + 1)
ReDim Preserve X(N)
ReDim Preserve B(N)
For i = 1 To N
a(i, N + 1) = B(i)
Next i
For k = 1 To N - 1
IM = k
For i = k To N
If Abs(a(i, k)) > Abs(a(IM, k)) Then IM = i
Next i
For J = k To N + 1
Swap a(k, J), a(IM, J)
Next J
D = a(k, k)
If D = 0 Then D = 0.000001
For J = k To N + 1
a(k, J) = a(k, J) / D
Next J
For i = k + 1 To N
C = a(i, k)
For J = k To N + 1
a(i, J) = a(i, J) - a(k, J) * C
Next J
Next i
Next k
' обратный ход
X(N) = a(N, N + 1) / a(N, N)
P = 0: Sum = 0
For i = N - 1 To 1 Step -1
L = N - P
For J = L To N
Sum = Sum + a(i, J) * X(L)
L = L + 1
Next J
X(i) = a(i, N + 1) - Sum
P = P + 1: Sum = 0
Next i
End Sub