using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CourseWork { class Program { // Задание 1 static double[] xval = new double[] { 49.6, 51.58, 52.55, 53.35, 54.15, 55.59, 56.71, 57.83, 58.8, 60.08, 61 }; // Олины циферки нужны static double[] yval = new double[] { 1400, 1384, 1320, 1300, 1290, 1270, 1250, 1240, 1230, 1220, 1200 }; static double[] abc = new double[] { 0.0, 0.0, 0.0 }; static double l = 1, tm0 = 20, tmk = 1400, c = 0.7 * 1000, R = 20.9 * 1000000, hi = 0.8; static double[] metzona1; static double[] metzona2; static double[] metzone3; static double[,] matrix = new double[3, 3]; static double[] rval = new double[3]; static void task1() { //Заполняем матрицу нулями for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) matrix[i, j] = 0; rval[0] = rval[1] = rval[2] = 0; int n = xval.Length; for (int i = 0; i < n; ++i) { double x = xval[i]; //Заполняем первую строку матрицы matrix[0, 0] += 1; matrix[0, 1] += Math.Tan(x / (1 + x)); matrix[0, 2] += Math.Atan(x); //Заполняем вторую строку матрицы matrix[1, 0] += Math.Tan(x / (1 + x)); matrix[1, 1] += Math.Tan(x / (1 + x)) * Math.Tan(x / (1 + x)); matrix[1, 2] += Math.Atan(x) * Math.Tan(x / (1 + x)); //Заполняем третью строку матрицы matrix[2, 0] += Math.Atan(x); matrix[2, 1] += Math.Tan(x / (1 + x)) * Math.Atan(x); matrix[2, 2] += Math.Atan(x) * Math.Atan(x); rval[0] += yval[i]; rval[1] += yval[i] * Math.Tan(x / (1 + x)); rval[2] += yval[i] * Math.Atan(x); } n = rval.Length; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { double value = matrix[i, i]; double koeff = matrix[j, i] / value; for (int c = 0; c < n; ++c) matrix[j, c] -= koeff * matrix[i, c]; rval[j] -= koeff * rval[i]; } } for (int i = n - 1; i >= 0; --i) { for (int j = i - 1; j >= 0; --j) { double value = matrix[i, i]; double koeff = matrix[j, i] / value; for (int c = 0; c < n; ++c) matrix[j, c] -= koeff * matrix[i, c]; rval[j] -= koeff * rval[i]; } } for (int i = 0; i < n; ++i) { abc[i] = rval[i] / matrix[i, i]; } } // 1я зона 0 <= x <= 15.4 static double zone1(double x) { return 802.384 + 861.422 * Math.Tan(x / (1 + x)) - 595.278 * Math.Atan(x); } // 2я зона 15.4 < x <= 49.6 static double zone2(double x) { return 50130 + 20420 * Math.Tan(x / (1 + x)) - 51080 * Math.Atan(x); } // 3я зона 49,6 ≤ x ≤ 61 static double zone3(double x) { return abc[0] + abc[1] * Math.Tan(x / (1 + x)) + abc[2] * Math.Atan(x); } // Задание 2 static int steps = 50; delegate double solveFunc(double x); static double diffur(double x, double y) { return x - y; } static void rungeKutt(double[] temp, solveFunc func, double a, double b) { double h = (b - a) / steps; double x = a; double k1, k2, k3, k4; for (int i = 0; i < steps; ++i) { k1 = h * diffur(func(x), temp[i]); k2 = h * diffur(func(x + h / 2), temp[i] + k1 / 2); k3 = h * diffur(func(x + h / 2), temp[i] + k2 / 2); k4 = h * diffur(func(x + h), temp[i] + k3); temp[i + 1] = temp[i] + (k1 + 2 * k2 + 2 * k3 + k4) / 6; x += h; } } static double gran(double x) { if (x <= 15.4) { double tn = zone1(x); int index = (int)(x / (15.4 / steps)); return (tn - metzona1[index]) / (tmk - tn); } else { if (x <= 49.6) { double tn = zone2(x); int index = (int)((x - 15.4) / ((49.6 - 15.4) / steps)); return (tn - metzona2[index]) / (tmk - tn); } else { double tn = zone3(x); int index = (int)((x - 49.6) / ((61 - 49.6) / steps)); return (tn - metzona2[index]) / (tmk - tn); } } } static double trap(double a, double b, int n) { double s, x, h; int i; s = gran(a) + gran(b); h = (b - a) / n; x = a; for (i = 1; i < n; i++) { x = x + h; s = s + 2 * gran(x); } return s * h / 2; } static void Main(string[] args) { task1(); metzona1 = new double[steps + 1]; metzona2 = new double[steps + 1]; metzone3 = new double[steps + 1]; metzona1[0] = tm0; rungeKutt(metzona1, zone1, 0, 15.4); metzona2[0] = metzona1[steps]; rungeKutt(metzona2, zone2, 15.4, 49.6); metzone3[0] = metzona2[steps]; rungeKutt(metzone3, zone3, 49.6, 61); Console.WriteLine(" Результаты "); Console.WriteLine("Коэфф. a,b,c: a = {0:F4}, b = {1:F4}, c = {2:F4}", rval[0], rval[1], rval[2]); Console.WriteLine(" Температуры металла в печи "); Console.WriteLine(" Первая зона "); double h = 15.4 / steps; double x = 0; for (int i = 0; i < metzona1.Length; ++i) { Console.WriteLine("x = {0:F4} Temp. = {1:F4}", x, metzona1[i]); x += h; } x -= h; Console.WriteLine(" Вторая зона "); h = (49.6 - 15.4) / steps; for (int i = 0; i < metzona1.Length; ++i) { Console.WriteLine("x = {0:F4} Temp. = {1:F4}", x, metzona2[i]); x += h; } Console.WriteLine(" Третья зона "); h = (61 - 49.6) / steps; for (int i = 0; i < metzona1.Length; ++i) { Console.WriteLine("x = {0:F4} Temp. = {1:F4}", x, metzone3[i]); x += h; } double answer3 = tmk * c / (hi * R) * trap(0, 49.6, 50); Console.WriteLine("Потребление топлива: {0:F4} ", answer3); Console.ReadKey(); } } }