Q (x) * V [i]; v = z [i] + h/2 * k1z; z = F (x + h/2) - P (x + h/2) * (z [i] + h/2 * k1z)-Q (x + h/2) * (V [i] + h/2 * k1v); v = z [i] + h/2 * k2z; z = F (x + h/2) - P (x + h/2) * (z [i] + h/2 * k2z)-Q (x + h/2) * (V [i] + h/2 * k2v); v = z [i] + h * k3z; z = F (x + h) - P (x + h) * (z [i] + h * k3z)-Q (x + h) * (V [i] + h * k3v); u = t [i];
}
} Proverka_Tochnosti (double y [], double y_tochnoe [], int n, double delta, double eps [])
{i = 0; = 0; (i = 0; i <= n/2; i + +)
{[i] = fabs (y [2 * i]-y_tochnoe [i]); (eps [i]> delta) = eps [i]; } delta;} Nahozdenie_y (double y [], double U [], double V [], int n, double C)
{i; (i = 0; i <= n; i + +) [i] = C * U [i] + V [i];
} Prisvoenie_y_Tochnoe (double y [], double y_tochnoe [], double y_vivodimoe [], int n)
{i; (i = 0; i <= n; i + +) {_vivodimoe [i] = y_tochnoe [i]; _tochnoe [i] = y [i];}
} Pechat (double y_vivodimoe [], double a, double eps [], int n, int N, double delta)
{i, j = 1, k; h, x = a; = n/N; = (ba)/n; ("n =% d nh =% 1.2f nMax_Delta =% 1.2e n n ", n, h, delta); (" tx ty t tE n "); (i = 0; i <= n; i + = k)
{
printf ("% d) t% 1.2f t% f t% 1.2e n", j + +, x, y_vivodimoe [i], eps [i]); = x + k * h;
}
} ()
{(n> = N_max)
{("Vihod za predeli massiva"); 0;
} (delta> epsel); (y_vivodimoe, a, eps, n/4, N, delta); ("n =% d nh =% 1.2f nMax_Delta =% 1.2e n n ", n, h, delta);
return 0;}
Додаток 2.
Лістинг програми В«Метод кінцевих різницьВ»
# include "stdafx.h"
# include "math.h" int N_max = 200; double epsel = 0.00001; double a = 1.3, b = 1.8, A = 2.2, B = -1.4; F (double x)
{return 1.8/(x * x) -4;} Q (double x)
{return 2.3/x;} P (double x)
{return 0.9 * x;} Metod_K_R (double y [], double h, int n)
{int i; x, m, k, f; double c [N_max], d [N_max]; [0] = 0; [0] = A; (i = 1; i
{= a + i * h; = (Q (x) - 2/(h * h))/(1/(h * h) + P (x)/(2 * h)); = ( 1/(h * h) - P (x)/(2 * h))/(1/(h * h) + P (x)/(2 * h)); = F (x)/(1/ (h * h) + P (x)/(2 * h)); [i] = 1/(mk * c [i-1]); [i] = c [i] * (fk * d [i -1]);
} [n] = B; (i = n-1; i> = 0; i -)
y [i] = d [i]-c [i] * y [i +1];
} Prov_toch (double y [], double y_tochnoe [], int n, double delta, double eps [])