U
unbarh
Здравствуйте, у меня курсовая работа по бейсику. Я написал код по найденному аналогу, но есть несколько очень непонятных моментов. Кому не трудно, код довольно короткий, можете написать пояснения к строкам?
Код под спойлером.
Код под спойлером.
Код:
Dim x(50) As Single
Dim y(50) As Single
Dim y1(50) As Single
Dim y2(50) As Single
Private y0 As Single
Private x0 As Single
Private xk As Single
Function f(l As Single, q As Single) As Single
f = (Exp(l) / l) + q
End Function
Private Sub Command1_Click()
x0 = Val(Text1.Text)
xk = Val(Text2.Text)
y0 = Val(Text4.Text)
h = Val(Text3.Text)
N = Round((xk - x0) / h)
MSFlexGrid1.Rows = N + 2
MSFlexGrid1.TextMatrix(0, 0) = "X"
MSFlexGrid1.TextMatrix(0, 1) = "Эйлер"
MSFlexGrid1.TextMatrix(0, 2) = "Рунге-Кутт"
MSFlexGrid1.TextMatrix(0, 3) = "Общее реш."
Max = 17
Min = 4
y(0) = y0
y1(0) = y0
y2(0) = y0
For i = 0 To N
x(i) = x0 + i * h
y(i + 1) = Round(y(i) + f(x(i), y(i)) * h, 4)
K1 = h * f(x(i), y1(i))
K2 = h * f(x(i) + h / 2, y1(i) + K1 / 2)
K3 = h * f(x(i) + h / 2, y1(i) + K2 / 2)
K4 = h * f(x(i) + h, y1(i) + K3)
K = (K1 + 2 * K2 + 2 * K3 + K4) / 6
y1(i + 1) = y1(i) + K4
y2(i) = Round(Exp(x(i)) * (Log(x(i)) + 1.48), 4)
If y(i) > Max Then Max = y(i)
If y(i) < Min Then Min = y(i)
MSFlexGrid1.TextMatrix(i + 1, 0) = Str(x(i))
MSFlexGrid1.TextMatrix(i + 1, 1) = Str(y(i))
MSFlexGrid1.TextMatrix(i + 1, 2) = Str(y1(i))
MSFlexGrid1.TextMatrix(i + 1, 3) = Str(y2(i))
Next i
Picture1.Cls
kx = (Picture1.Width - 1200) / (xk - x0)
ky = (Picture1.Height - 1000) / (Max - Min)
Label4.Caption = Str(Min)
Label5.Caption = Str(Max)
Label6.Caption = Str(x0)
Label7.Caption = Str(xk)
For i = 0 To N - 1
z1 = Round(720 + (x(i) - x0) * kx)
z2 = Round(5400 - (y(i) - Min) * ky)
z3 = Round(5400 - (y1(i) - Min) * ky)
z4 = Round(5400 - (y2(i) - Min) * ky)
z5 = Round(720 + (x(i + 1) - x0) * kx)
z6 = Round(5400 - (y(i + 1) - Min) * ky)
z7 = Round(5400 - (y1(i + 1) - Min) * ky)
z8 = Round(5400 - (y2(i + 1) - Min) * ky)
Picture1.Line (z1, z2)-(z5, z6), vbGreen
Picture1.Line (z1, z3)-(z5, z7), vbRed
Picture1.Line (z1, z4)-(z5, z8)
Next i
End Sub
Private Sub Command2_Click()
End
End Sub