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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CourseWork_eko
{
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()
{
///////////////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.Atan(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.Atan(x) * Math.Tan(x / (1 + x));
///////// Fill third line in matrix //////////////////
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];
}
}
// 3rd zone 49,6 ≤ x ≤ 61
static double zone3(double x)
{
return abc[0] + abc[1] * Math.Tan(x / (1 + x)) + abc[2] * Math.Atan(x);
}
// Second zone 15.4 < x <= 49.6
static double zone2(double x)
{
return 50130 + 20420 * Math.Tan(x / (1 + x)) - 51080 * Math.Atan(x);
}
// 1st zone 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 */
/* */
//////////
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 = 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 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 double f(double x)
{
return Math.Log(x) / (x * Math.Sqrt(1 + Math.Log(x)));
}
static double trap(double a, double b, int n)
{
double s, x, h;
int i;
s = currCons(a) + currCons(b);
h = (b - a) / n;
x = a;
for (i = 1; i < n; i++)
{
x = x + h;
s = s + 2 * f(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;
rungeKutta(metzona1, zone1, 0, 15.4);
metzona2[0] = metzona1[steps];
rungeKutta(metzona2, zone2, 15.4, 49.6);
metzone3[0] = metzona2[steps];
rungeKutta(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} 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;
}
Console.WriteLine("------------------Третья зона-----------------------");
h = (61 - 49.6) / steps;
for (int i = 0; i < metzona1.Length; ++i)
{
Console.WriteLine("x = {0:F4} Temperature = {1:F4}", x, metzone3[i]);
x += h;
}
double answer3 = tmk * c / (hi * R) * trap(0, 49.6, 100);
Console.WriteLine("Потребление топлива: {0:F4} ", answer3);
Console.ReadKey();
}
}
}