# using System using System Collections Generic using System Linq using

 ``` 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 94 95``` ```using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RK_methods_diffur { class Program { static double y(double x) { return Math.Pow(Math.E, x); } static double p(double x) { return (double)3; } static double q(double x) { return (double)(-2); } static double f(double x) { return 2 * y(x); } static double[] count(int n, double a, double b, double []xi, double []fi) { double[] yi = new double[n + 1]; double h = 1 / (double)n; yi[0] = y(a); yi[n] = y(b); double[] ai = new double[n]; double[] bi = new double[n]; double[] ci = new double[n]; double[] di = new double[n]; for (int i = 1; i < n; i++) { ai[i] = 1.0 - p(xi[i + 1]) * h / 2.0;//1;// bi[i] = q(xi[i]) * h * h - 2.0;// 4;// ci[i] = 1.0 + ((p(xi[i]) * h) / 2);//1;// di[i] = f(xi[i]) * h * h; } di[1] -= (1 - p(xi[0]) * h / 2)*yi[0]; di[n - 1] -= (1 + p(xi[n]) * h / 2)*yi[n];//-1.17; //di[2] = di[3] = 6; n = 5; for (int i = 0; i < n; i++) Console.WriteLine("a=" + ai[i] + "\tb=" +bi[i]+"\tc="+ci[i]+"\td="+di[i]); //--------------copy------------------- double[] alpha = new double[n]; double[] beta = new double[n]; alpha[1] = -ci[1] / bi[1]; beta[1] = di[1] / bi[1]; for (int i = 2; i < n; i++) { alpha[i] = -(ci[i] / (ai[i - 1] * alpha[i - 1] + bi[i])); beta[i] = (di[i] - ai[i - 1] * beta[i - 1]) / (ai[i - 1] * alpha[i - 1] + bi[i]); } //for (int i = 1; i < n; i++) // Console.WriteLine("al="+alpha[i]+"\tbt="+beta[i]); yi[n-1] = beta[n-1];// (di[n] - ai[n - 1] * beta[n - 1]) / (ai[n - 1] * alpha[n - 1] + bi[n]); Console.WriteLine("yn: "+ yi[n - 1]); for (int i = n - 2; i > 0; i--) yi[i] = alpha[i] * yi[i + 1] + beta[i]; return yi; } static void Main(string[] args) { int n = 10; double a = 0, b = 1; double h = 1 / (double)n; double []xi = new double[n + 1]; double []yi = new double[n + 1]; double []fi = new double[n + 1]; for (int i = 0; i <= n; i++) { double j = a + i * h; xi[i] = j; yi[i] = y(j); fi[i] = f(j); } for (int i = 0; i <= n; i++) Console.WriteLine(xi[i] + "\t" + yi[i] + "\t" + fi[i]); double []result = count(n, a, b, xi, fi); result[n] = y(b); result[0] = y(a); for (int i = 0; i <= n; i++) Console.WriteLine("y=" + yi[i] + " \t\tresult=" + result[i] + " d: "+ Math.Abs(yi[i]-result[i])); //Console.WriteLine("y=" + f(1)); Console.ReadLine(); } } } ```