Предлагаемые версии программной реализации для моделей
Option Explicit
' Текст модуля модели Жертва-Хищник.
Sub JertvaHi2001()'Модель Жертва-Хищник
Dim z As String: Dim v As String: v = "Модель: Жертва-Хищник"
Dim g As String: g = "Введите исходное количество"
Dim Xo As Single: z = lnputBox(g + "жертв- Xo", v): Xo = CSng(z)
Dim Yo As Single: z = lnputBox(g + "хищников- Yo", v): Yo = CSng(z)
g = "Введите значение коэффициента": Dim a As Single: Dim b As Single
z = lnputBox(g + "прироста жертв при отсутствии хищников- а=", v)
а = CSng(z): z = lnputBox(g + "убытия жертв как пища для хищников- b", v)
b = CSng(z): Dim с As Single: Dim d As Single
z = lnputBox(g + "вымирания хищников при отсутствии жертв- с", v)
с = CSng(z): z = lnputBox(g + "прироста хищников в силу наличия жертв- d", v)
d = CSng(z): Dim AY As Single: Dim BX As Single
z = lnputBox(g + "А-(учет процесса насыщения числа хищников)", v)
AY = CSng(z): z = lnputBox(g + "В- (учета ресурсов существования жертв)", v)
BX = CSng(z): Dim T As Single: Dim h As Single: Dim e As Single
z = InputВох("Введите интервал времени для анализа системы- Т", v)
Т = CSng(z): z = InputВох("Введите начальный шаг численного решения- h", v)
h = CSng(z): z = InputВох("Введите точность расчета- е", v): е = CSng(z)
Dim i As Integer: Dim f As Single: Dim s As Single: Dim XT As Single
Dim YT As Single: XT = Xo: YT = Yo: Dim N As Integer: N = 1
Dim x As Single: Dim Y As Single: Dim X1 As Single: Dim Y1 As Single
Metka: f = 0: x = Xo: Y = Yo
Do While f < T
X1 =x*(1 + (a-b*Y/(1 + AY*x)-BX*x)*h/N)
Y1 =Y*(1 + (d*x/(1 + AY*x)-c)*h/N):f = f + h/N
x = X1: Y = Y1: Loop
'f<T
If Abs(x - XT) + Abs(Y - YT) > e Then
XT = x: YT = Y: N = N +
1:
GoTo Metka: End If
v = "Численность жертв(Х) и хищников(У)"
z = "Модуль VBA:" + "За время t=" & CStr(Clnt(T))
z = z & "; X(t)=" & CStr(Clnt(x)) &"; Y(t)=" & CStr(Clnt(Y))
i = MsgBox(z, 1, v): i = МsgВох('Занести результат в ЭТ?", 1, v)
If i > 0 Then
Dim w As String: Dim NT As Integer:Dim NR As lnteger:Dim NC As Integer:
Dim p as string: р="Укажите номер"
w = lnputBox(p+" электронной таблицы", v, 1): NT = Clnt(w)
w = InputBox(p+" номер строки электронной таблицы", v, 45): NR = Clnt(w)
w = InputВох("Укажите номер столбца ЭТ", v, 1): NC = Clnt(w)
z = z + ";(Точность e=" + CStr(e) + ";шаг h=" + CStr(h) + ")"
w = "(При Xo=" + CStr(Xo) + ";a=" + CStr(a) + ";b="
w = w + CStr(b) + ";A=" + CStr(AY) + ";Yo=" + CStr(Yo) + ";c="
w = w + CStr(c) + ";d=" & CStr(d) + ";B=" + CStr(BX) + ")"
Worksheets(NT).Cells(NR, NC).Formula = z
Worksheets(NT).Cells(NR + 1, NC).Formula = w
End If:
End Sub 'JH2001
Текст модуля модели Жертва-Пища-Хищник
Option Explicit
Function НGP1(a1As Single, a2 As Single, a3 As Single, X As Single, _
Y As Single, Z As Single) As Single
HGP1 = X * (a1 * (a2 - X/Y)*(X/Y - a3) - Z):
End Function 'HGP1
Function HGP2(c1As Single, c2 As Single, X As Single, Y As Single) As Single
Dim s As Single: s = X
Lf Y<X Then
: s = Y: End If: HGP2 = d * (1 - Y) * (Y - c2) - s
End Function 'HGP2
Function HGP3(b1As Single, b2 As Single, X As Single, Z As Single) As Single
HGP3 =b1 * Z * (X - b2):
End Function 'HGP3
Function Ochibka(RM() As Single) As Single Dim a As Single: Dim i As Integer: Ochibka = 0 For i = 0 To 2: a = Abs(RM(15 + i) - RM(12 + i)) If a > Ochibka Then:
Ochibka = a: End If: Next i:
Дата добавления: 2016-02-04; просмотров: 499;