double Calc int double step double left double right метод прогонки do

 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
double* Calc(int n, double step, double left, double right) //метод прогонки
{
double* alpha = new double[n];
double* betta = new double[n];
double* A = new double[n];
double* B = new double[n];
double* C = new double[n];
double* D = new double[n];
double* y = new double[n + 1];
y[0] = lbc;
y[n] = rbc;
/*Прямой ход метода прогонки*/
for (int i = 1; i < n; i++) {
double x = left + step * i;
A[i] = 1 - p(x + step) * step / 2;
B[i] = q(x) * step * step - 2;
C[i] = 1 + p(x) * step / 2;
D[i] = f(x) * step * step;
}
D[1] -= (1 - p(left) * step / 2) * y[0];
D[n - 1] -= (1 + p(right) * step / 2) * y[n];
alpha[1] = -C[1] / B[1];
betta[1] = D[1] / B[1];
for (int i = 2; i < n; i++) {
alpha[i] = -C[i] / (A[i - 1] * alpha[i - 1] + B[i]);
betta[i] = (D[i] - A[i - 1] * betta[i - 1]) / (A[i - 1] * alpha[i - 1] + B[i]);
}
y[n - 1] = betta[n-1];
/*Обратный ход метода прогонки*/
for (int i = n - 2; i > 0; i--) {
y[i] = alpha[i] * y[i + 1] + betta[i];
}
delete [] A;
delete [] B;
delete [] C;
delete [] D;
delete [] alpha;
delete [] betta;
return y;
}