using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CourseWork_eko { class Program { // Задание 1 static double[] xval = new double[] { 0, 1.97, 3.91, 5.8, 6.22, 6.52, 6.87, 8.73, 10.73, 13.62, 15.4 }; // Олины циферки нужны static double[] yval = new double[] { 800, 840, 880, 905, 970, 995, 1003, 1020, 1030, 1060, 1100 }; 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[,] matrix = new double[3, 3] ; static double[] rval = new double[3]; static void task1() { ///////////////Fill matrix with nulls ////////////////////// 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]; ///////// Fill first line in matrix ////////////////// matrix[0, 0] += 1; matrix[0, 1] += Math.Tan(x / (1 + x)); matrix[0, 2] += Math.Log(1 + x); ///////// Fill second line in matrix ////////////////// 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.Log(1 + x) * Math.Tan(x / (1 + x)); ///////// Fill third line in matrix ////////////////// matrix[2, 0] += Math.Log(1 + x); matrix[2, 1] += Math.Tan(x / (1 + x)) * Math.Log(1 + x); matrix[2, 2] += Math.Log(1 + x) * Math.Log(1 + x); /////////////////////////////////////////////////////// rval[0] += yval[i]; rval[1] += yval[i] * Math.Tan(x / (1 + x)); rval[2] += yval[i] * Math.Log(1 + 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]; } } // First zone 0 <= x <= 15.4 static double zona1(double x) { return abc[0] + abc[1] * Math.Tan(x / (1 + x)) + abc[2] * Math.Log(1 + x); } // Second zone 15.4 < x <= 49.6 static double zona2(double x) { return 365.861 - 5.697 * Math.Sin(x) + 258.083 * Math.Log(1 + x); } // Сюда тоже уравнение ебалы для третей зоны она считается также как сдесь для первой а на место первой прикрутишь формулу /*/////////////////////////////////////////////////////////////////////////////////////////*/ /* Задание 2 */ /* */////////// static int steps = 100; delegate double solveFunc(double x); static double diffur(double x, double y) { return x - y; } static void rungeKutta(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 currCons(double x) { if (x <= 15.4) { double tn = zona1(x); int index = (int)(x / (15.4 / steps)); return (tn - metzona1[index]) / (tmk - tn); } else { double tn = zona2(x); int index = (int)( (x - 15.4) / ((49.6 - 15.4) / steps)); return (tn - metzona2[index]) / (tmk - tn); } } //* Вот эту херню перепелить полностью тебе не симпсон а трапеции нужны */ static double simpson(double a, double b, int n) { double h = (b - a) / n; double s = currCons(a) + currCons(b); double x = a; int c = 1; for (int i = 1; i < n; ++i) { x = x + h; s += (3 + c) * currCons(x); c = -c; } return s * h / 3; } static void Main(string[] args) { task1(); metzona1 = new double[steps + 1]; metzona2 = new double[steps + 1]; metzona1[0] = tm0; rungeKutta(metzona1, zona1, 0, 15.4); metzona2[0] = metzona1[steps]; rungeKutta(metzona2, zona2, 15.4, 49.6); // Сюда прилепишь считалку для третьей зоны 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} Temperature = {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} Temperature = {1:F4}", x, metzona2[i]); x += h; } double answer3 = tmk * c / (hi * R) * simpson(0, 49.6, 100); Console.WriteLine("Потребление топлива: {0:F4} ", answer3); } } }