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
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();
}
}
}