double funcVals new double 1000 double yVals new double 1000 double de

 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
double[] funcVals = new double[1000];
double[] yVals = new double[1000];
double[] derVals = new double[1000];
double[] kouellAnswers = new double[1000];
double getNextByRunge(double x, double y, fnc funcForRunge, double h, int ind = 0)
{
double ni1 = funcForRunge(x, y, ind);
double ni2 = funcForRunge(x + h / 2.0, y + h / 2.0 * ni1, ind);
double ni3 = funcForRunge(x + h / 2.0, y + h / 2.0 * ni2, ind);
double ni4 = funcForRunge(x + h, y + h * ni3, ind);
double delta = h / 6.0 * (ni1 + 2 * ni2 + 2 * ni3 + ni4);
y = y + delta;
return y;
}
double funForFireMethod(double x, double y, int ind)
{
return Math.Sin(3 * x) + 2 * y + 3 * yVals[ind];
}
double secFunFir(double x, double y, int ind)
{
return derVals[ind];
}
void kouell(double a, double b, double y0, double y0d)
{
int ind = 0;
double x = a;
derVals[ind] = y0d;
yVals[ind] = y0;
funcVals[ind] = funForFireMethod(x, derVals[ind], ind);
for (int i = 0; i < 2; ++i)
{
yVals[ind + 1] = getNextByRunge(x, yVals[ind], secFunFir, h, ind);
derVals[ind + 1] = getNextByRunge(x, derVals[ind], funForFireMethod, h, ind);
ind++;
x += h;
}
while (x < b)
{
yVals[ind + 1] = getNextByRunge(x, yVals[ind], secFunFir, h, ind);
derVals[ind + 1] = getNextByRunge(x, derVals[ind], funForFireMethod, h, ind);
ind++;
x += h;
}
}
void fireMethod()
{
double ya = - 1000;
double yb = 1000;
double a = 1.2;
double b = 1.9;
int steps = (int)((b - a) / h + 0.5);
double A = 5.1;
double B = 1.4;
double al1 = 2;
double al2 = -1.7;
double bet1 = -4;
double bet2 = 5;
while (yb - ya > 1e-8)
{
double cy = (ya + yb) / 2.0;
double cyd = (5.1 - 2 * cy) / -1.7;
kouell(a, b, cy, cyd);
double yAtB = yVals[steps];
double derAtB = derVals[steps];
double diffAtB = -4 * yAtB + 5 * derAtB - 1.4;
if (diffAtB > 0)
yb = cy;
else
ya = cy;
}
}