- Код: Выделить всё
Dim Xf(1 To 7) As Double
Dim a(1 To 4, 1 To 5) As Double
Private Sub Command1_Click()
Dim Result As Boolean
Dim i As Long
Dim J As Long
Dim k As Long
Dim M As Double
Dim t As Double
n = 4
a(1, 1) = 3
a(1, 2) = 2
a(1, 3) = 22
a(1, 4) = -32
a(1, 5) = -5
a(2, 1) = 2
a(2, 2) = -12
a(2, 3) = 5
a(2, 4) = 7
a(2, 5) = -1
a(3, 1) = 3
a(3, 2) = -8
a(3, 3) = 4
a(3, 4) = 3
a(3, 5) = -1
a(4, 1) = 0
a(4, 2) = 2
a(4, 3) = -4
a(4, 4) = 7
a(4, 5) = 8
For d = 1 To 4
Result = True
For i = 1 To n Step 1
k = i
M = Abs(a(i, i))
For J = i + 1 To n Step 1
If M < Abs(a(J, i)) Then
M = Abs(a(J, i))
k = J
End If
Next J
If Abs(M) > 0 Then
For J = i To n + 1 Step 1
t = a(i, J)
a(i, J) = a(k, J)
a(k, J) = t
Next J
For k = i + 1 To n Step 1
t = a(k, i) / a(i, i)
a(k, i) = 0
For J = i + 1 To n + 1 Step 1
a(k, J) = a(k, J) - t * a(i, J)
Next J
Next k
Else
Result = False
Exit For
End If
Next i
If Result Then
i = n
Do
Xf(i) = a(i, n + 1)
J = i + 1
Do While J <= n
Xf(i) = Xf(i) - a(i, J) * Xf(J)
J = J + 1
Loop
Xf(i) = Xf(i) / a(i, i)
i = i - 1
Loop Until Not i >= 1
End If
Xf(d) = Result
Picture2.Print "X(" & d & ")=" & Xf(d) & ";"
Next
End Sub
Public Function Gauss(ByRef a() As Double, ByRef n As Integer, ByRef Xf() As Double, ByRef Epsilon As Double) As Boolean
Gauss = Result
End Function
найдите ошибки, пожалуйста. матрицу неверно считает.