Адамса-Башфорта void Prediction_correctio float float float FILE fp in

 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
// Адамса-Башфорта
void Prediction_correction(float x, float b, float h, FILE *fp) {
int size = 3;
float *vector_elements_exact, *vector_elements_numerical;
vector_elements_exact = new float[size];
vector_elements_exact[0] = 1.;
vector_elements_exact[1] = 1.;
vector_elements_exact[2] = 1.;
Vector y_exact(size, vector_elements_exact);
vector_elements_numerical = new float[size];
vector_elements_numerical[0] = 1.;
vector_elements_numerical[1] = 1.;
vector_elements_numerical[2] = 1.;
Vector y_numerical_0(size, vector_elements_numerical);
Vector y_numerical_1(size, vector_elements_numerical);
Vector y_numerical_2(size, vector_elements_numerical);
Vector y_numerical(size, vector_elements_numerical);
Vector y_pr(size, vector_elements_numerical);
Vector y_cor(size, vector_elements_numerical);
y_numerical_0 = Exact(x-h);
y_numerical_1 = Exact(x-2*h);
y_numerical_2 = Exact(x-3*h);
if(fp != NULL) {
// Выводим первую строку
fprintf(fp, "Адамса-Башфорта при h = %f\n", h);
fprintf(fp, "0 | %.3f | ", x);
y_exact.print(fp);
y_numerical.print(fp);
fprintf(fp, "%f\n", norm(y_exact, y_numerical));
for(int i=1; x<=b; i++) {
x += h;
// Вычесляем точное значение
y_exact = Exact(x);
// Вычисляем численное значение
y_pr = y_numerical + (f(y_numerical)*55. - f(y_numerical_0)*59. + f(y_numerical_1)*37. - f(y_numerical_2)*9.)*(h/24.);
y_cor = y_numerical + (f(y_pr)*9. + f(y_numerical)*19. - f(y_numerical_0)*5. + f(y_numerical_1))*(h/24.);
fprintf(fp, "%d | %.3f | ", i, x);
y_exact.print(fp);
y_cor.print(fp);
fprintf(fp, "%f\n", norm(y_exact, y_cor));
y_numerical_2 = y_numerical_1;
y_numerical_1 = y_numerical_0;
y_numerical_0 = y_numerical;
y_numerical = y_cor;
}
fprintf(fp, "\n\n");
}
}