Численные методы решения прикладных задач - page 45

45
Dim j As Integer
Dim k As Integer
For i = 1 To n
For j = 1 To n
A(i, j) = ActiveSheet.Cells(3 + i, j).Value
AA(i, j) = ActiveSheet.Cells(3 + i, j).Value
Next j
F(i) = ActiveSheet.Cells(3 + i, 5).Value
FF(i) = ActiveSheet.Cells(3 + i, 5).Value
Next i
'метод Гаусса
For k = 1 To n - 1
For j = k + 1 To n
B(k, j) = AA(k, j) / AA(k, k)
Next j
G(k) = FF(k) / AA(k, k)
For i = k + 1 To n
For j = k + 1 To n
AA(i, j) = AA(i, j) - AA(i, k) * B(k, j)
Next j
FF(i) = FF(i) - AA(i, k) * G(k)
Next i
Next k
G(n) = FF(n) / AA(n, n)
x(n) = G(n)
ActiveSheet.Cells(15, 2).Value = x(n)
For k = n - 1 To 1 Step -1
x(k) = G(k)
For j = k + 1 To n
x(k) = x(k) - B(k, j) * x(j)
Next j
ActiveSheet.Cells(11 + k, 2).Value = x(k)
Nextk
'Проверка условия сходимости
ActiveSheet.Cells(17, 1).Value = ""
U1 = Abs(A(1, 1)) >Abs(A(1, 2)) + Abs(A(1, 3)) + Abs(A(1, 4))
U2 = Abs(A(2, 2)) >Abs(A(2, 1)) + Abs(A(2, 3)) + Abs(A(2, 4))
U3 = Abs(A(3, 3)) >Abs(A(3, 1)) + Abs(A(3, 2)) + Abs(A(3, 4))
U4 = Abs(A(4, 4)) > Abs(A(4, 1)) + Abs(A(4, 2)) + Abs(A(4, 3))
If U1 And U2 And U3 And U4 Then
ActiveSheet.Cells(17, 1).Value = "Условие сходимости выполнено"
'Метод простой итерации
Fori = 1 Ton
x(i) = 0
G(i) = 100
Next i
k = 0
While toch(x(), G()) = False
For i = 1 To n
G(i) = x(i)
I...,35,36,37,38,39,40,41,42,43,44 46,47,48,49,50,51,52,53,54,55,...284
Powered by FlippingBook