Word / Эйлер
.doc'Модифицированный метод Эйлера
Private Sub CommandButton1_Click()
Dim a, b, n, h, x0, y0, x1, y1, st, x, y, FF As Single
a = InputBox("Введи a", "Ввод", -2.15)
b = InputBox("Введи b", "Ввод", 3.97)
n = InputBox("Введи n", "Ввод", 4)
x0 = InputBox("Введи a", "Ввод", a)
y0 = InputBox("Введи y0", "Ввод", 2.662)
Cells(1, 1) = "x"
Cells(1, 2) = "y"
Cells(1, 3) = "f(x,y)"
Cells(1, 4) = "h*f(x,y)"
h = (b - a) / n
y = y0
x = x0
st = 1
For n = 1 To 4
If x <= b Then
FF = f(x, y)
x1 = x + h / 2
y1 = y + h * FF / 2
y = y + h * f(x1, y1)
x = x + h
Cells(st + 1, 1) = x
Cells(st + 1, 2) = y
Cells(st + 1, 3) = f(x, y)
Cells(st + 1, 4) = h * f(x, y)
st = st + 1
End If
Next n
End Sub
Public Function f(xx As Variant, yy As Variant)
f = -2.508 * yy + 0.617 * xx / yy + 1.418 * xx + 2.136
End FuOption Explicit
Метод простых итераций
Sub iterathii()
Dim n As Byte, a!(), c!(), b!(), eps!, d!(), s!, z!(), x!(), i As Byte, j As Byte, norma_c!(), w!(), r!
n = InputBox("Введите количество уравнений", "Ввод данных")
ReDim a(n, n + 1), c(n, n), b(n), d(n), z(n), x(n), norma_c(n), w(n)
eps = InputBox("Введите точность е", "Ввод данных")
For i = 1 To n
For j = 1 To n
a(i, j) = InputBox("Введите коэффициэнты системы при х", "Ввод данных")
Cells(i, j) = a(i, j)
Next j
b(i) = InputBox("Введите коэффициэнт без х", "Ввод данных")
Cells(i, n + 1) = "="
Cells(i, n + 2) = b(i)
Next i
For i = 1 To n
For j = 1 To n
c(i, j) = -a(i, j) / a(i, i)
Cells(i + n + 1, j) = c(i, j)
Next j
c(i, i) = 0: d(i) = b(i) / a(i, i)
Cells(i + n + 1, i) = c(i, i)
Next i
norma_c(n) = 0
For i = 1 To n
For j = 1 To n
norma_c(i) = norma_c(i) + Abs(c(i, j))
Next j
Next i
s = norma_c(1)
For i = 2 To n
If s < norma_c(i) Then
s = norma_c(i)
End If
Next i
Cells(2 * n + 3, 1) = "||c|| = "
Cells(2 * n + 3, 2) = s
If s > 1 Then
Cells(1, 1) = "Внимание! Условие сходимости не выполняется!"
Exit Sub
End If
For i = 1 To n
z(i) = d(i)
Next i
r = 1
Do
For i = 1 To n
x(i) = 0
For j = 1 To n
x(i) = x(i) + c(i, j) * z(j)
Next j
Next i
For i = 1 To n
x(i) = x(i) + d(i)
w(i) = Abs(x(i) - z(i))
Next i
r = w(1)
For i = 2 To n
If r < w(i) Then
r = w(i)
End If
Next i
For i = 1 To n
z(i) = x(i)
Next i
Loop Until r < eps
For i = 1 To n
Cells(2 * n + 3, 4) = "x(i)"
Cells(i + 2 * n + 3, 4) = z(i)
Next i
End Subnction-