1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
| Imports System.Windows.Forms.DataVisualization.Charting
Imports System.ComponentModel
Imports System.Math
Public Class Form
Dim x(), y1(), y2(), y3() As Single
Private x0, xk, y0, h, k, k1, k2, k3, k4, c As Single
Private n As Integer
Function f(ByVal x, ByVal y1) As Single
f = (2 * x ^ 2) - 2 * y1
End Function
Function f2(ByVal x, ByVal y2) As Single
f2 = (2 * x ^ 2) - 2 * y2
End Function
Function f3(ByVal x, ByVal y3) As Single
f3 = (2 * x ^ 2) - 2 * y3
c = 1.5 * Math.Exp(2 * x) - x ^ 2 - x - y3
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
x0 = TextBox1.Text
xk = TextBox2.Text
y0 = TextBox3.Text
h = TextBox4.Text
n = (xk - x0) / h
DataGridView1.RowCount = 1
DataGridView1.ColumnCount = 4
ReDim x(n), y1(n), y2(n), y3(n)
DataGridView1.Item(0, 0).Value = "x"
DataGridView1.Item(1, 0).Value = "y"
DataGridView1.Item(2, 0).Value = "y"
DataGridView1.Item(3, 0).Value = "y"
y1(0) = Val(TextBox4.Text)
x(0) = Val(TextBox1.Text)
y2(0) = y1(0)
DataGridView1.Item(0, 1).Value = x0
DataGridView1.Item(1, 1).Value = y0
For i As Integer = 1 To n - 1
y1(0) = y0
k1 = h * f(x(i), y2(i))
k2 = h * f(x(i) + (h / 2), y2(i) + (k1 / 2))
k3 = h * f(x(i) + (h / 2), y2(i) + (k2 / 2))
k4 = h * f(x(i) + h, y2(i) + k3)
k = (k1 + 2 * k2 + 2 * k3 + k4) / 6
y2(i + 1) = y2(i) + 1 / 6 * (k1 + 2 * k2 + 2 * k3 + k4)
Next i
For i As Integer = 1 To n - 1
y2(i + 1) = y2(i) + h * f(x(i) + (h / 2), y2(i) + (h / 2) * f(x(i), y2(i)))
DataGridView1.Item(2, i + 1).Value = Str(y2(i))
Next i
For i As Integer = 1 To n
y3(i) = x(i) - (x(i) ^ 2)
DataGridView1.Item(3, i + 1).Value = Str(y3(i))
Next i
Chart1.Series.Add("Метод Рунге-Кутты")
Chart1.Series("Метод Рунге-Кутты").ChartType = SeriesChartType.Point
Chart1.Series.Add("Метод Эйлера модифицированный")
Chart1.Series("Метод Эйлера модифицированный").ChartType = SeriesChartType.Point
Chart1.Series.Add("Общее решение")
Chart1.Series("Общее решение").ChartType = SeriesChartType.Point
For i As Integer = 0 To n - 1
Chart1.Series("Метод Рунге-Кутты").Points.AddXY(x(i), y1(i))
Chart1.Series("Метод Рунге-Кутты").ChartArea = "ChartArea1"
Chart1.Series("Метод Эйлера модифицированный").Points.AddXY(x(i), y2(i))
Chart1.Series("Метод Эйлера модифицированный").ChartArea = "ChartArea1"
Chart1.Series("Общее решение").Points.AddXY(x(i), y3(i))
Chart1.Series("Общее решение").ChartArea = "ChartArea1"
Next i
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = 0
TextBox2.Text = 1
TextBox3.Text = 1
TextBox4.Text = 0.1
End Sub
End Class |