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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
| #include "stdafx.h"
#include "pch.h"
#include <iostream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
class Complex // класс "Комплексное число"
{
private:
double re, im; // действительная и мнимая части
public:
// конструкторы
Complex(double r = 0, double i = 0)
{
re = r;
im = i;
}
Complex(const Complex &c) // конструктор копирования
{
re = c.re;
im = c.im;
}
// деструктор
~Complex()
{
}
// остальные функции
// Модуль комплексного числа
double abs() const
{
return sqrt(re * re + im * im);
}
const Complex conj()
{
re = re;
im = -im;
return *this;
}
// оператор присваивания
const Complex& operator = (const Complex &c)
{
re = c.re;
im = c.im;
return (*this);
}
// оператор +=
const Complex& operator += (const Complex &c)
{
re += c.re;
im += c.im;
return *this;
}
// оператор сложения
const Complex operator + (const Complex &c)
{
return Complex(re + c.re, im + c.im);
}
// оператор вычитания
const Complex operator - (const Complex &c)
{
return Complex(re - c.re, im - c.im);
}
// оператор умножения
const Complex operator * (const Complex &c)
{
return Complex(re * c.re - im * c.im, re * c.im + im * c.re);
}
const Complex operator*(const double& a)
{
return Complex(re*a, im*a);
}
const Complex operator*(double &c)
{
Complex fp1;
double i, j;
i = re * c;
j = im * c;
fp1 = (i, j);
return fp1;
}
// оператор деления
const Complex operator / (const Complex &c)
{
Complex temp;
double r = c.re * c.re + c.im * c.im;
temp.re = (re * c.re + im * c.im) / r;
temp.im = (im * c.re - re * c.im) / r;
return temp;
}
double Complex::Re()
{
return re;
}
double Complex::Im()
{
return im;
}
Complex expon(Complex c)
{
c.re = exp(re) * cos(im);
c.im = exp(re) * sin(im);
return c;
}
Complex sinus(Complex c)
{
c.re = sin(re) * cosh(im);
c.im = cos(re) * sinh(im);
return c;
}
Complex cosinus(Complex c)
{
c.re = cos(re) * cosh(im);
c.im = -sin(re) * sinh(im);
return c;
}
// укажем дружественные операторы, которым мы разрешаем доступ
// к личным (private) данным
friend ostream & operator<< (ostream &, const Complex &);
friend istream & operator >> (istream &, Complex &);
};
// перегрузка оператора <<
ostream& operator<< (ostream &out, const Complex &c)
{
out << "(" << c.re << ", " << c.im << ")";
return out;
}
// перегрузка оператора >>
istream& operator >> (istream &in, Complex &c)
{
in >> c.re >> c.im;
return in;
}
void top(double r[12][5], double a[6][12])
{
for (int i = 0; i < 6; i++)
for (int j = 0; j < 12; j++)
a[i][j] = 0;
for (int j = 0; j < 12; j++)
{
for (int i = 0; i < 6; i++)
{
for (int e = 1; e <= 7; e++)
for (int c = 1; c <= 7; c++)
if (r[j][0] == e && r[j][1] == c)
{
if (e == i + 1)
a[i][j] = 1;
if (c == i + 1)
a[i][j] = -1;
}
}
}
}
void tr(double a[6][12], double at[12][6])
{
for (int i = 0; i < 6; i++)
for (int j = 0; j < 12; j++)
at[j][i] = a[i][j];
}
void Y(Complex y[12][12], double f, double r[12][5], double p[12][4])
{
for (int i = 0; i < 12; i++)
for (int j = 0; j < 12; j++)
y[i][j] = 0.0;
for (int i = 0; i < 12; i++)
{
double xl, xc;
xl = 2 * 3.14 * f * r[i][3];
xc = 1 / (2 * 3.14*f*r[i][4]);
if (r[i][4] == 0)
xc = 0;
Complex z(r[i][2], (xl - xc));
Complex x(1, 0);
x = (x / z);
if (p[i][3] == 0)
{
y[i][i] = x;
}
else
{
y[i][i] = 0.0;
}
}
}
void mul(double a[6][12], Complex y[12][12], Complex q1[6][12])
{
for (int i = 0; i < 6; i++)
for (int j = 0; j < 12; j++)
{
q1[i][j] = 0.0;
for (int k = 0; k < 12; k++)
{
Complex x = a[i][k];
q1[i][j] += x * y[k][j];
}
}
}
void mul2(Complex a[6][12], double y[12][6], Complex q[6][7])
{
for (int i = 0; i < 6; i++)
for (int j = 0; j < 6; j++)
{
q[i][j] = 0.0;
for (int k = 0; k < 12; k++)
{
Complex x = a[i][k];
Complex z(y[k][j]);
q[i][j] += x * z;
}
}
}
void mul3(Complex y[12][12], Complex e[12], Complex q[12])
{
for (int i = 0; i < 12; i++)
{
q[i] = y[i][i] * e[i];
}
}
void mul4(double a[6][12], Complex y[12], Complex q[6])
{
for (int i = 0; i < 6; i++)
{
q[i] = 0.0;
for (int k = 0; k < 12; k++)
{
Complex x = a[i][k];
q[i] += x * y[k];
}
Complex x = -1.0;
q[i] = x * q[i];
}
}
void eds(double r[12][5], double c[12][4], Complex e[12])
{
for (int i = 0; i < 12; i++)
{
if (c[i][0] == r[i][0])
{
double x = c[i][2] * cos(c[i][3] * 3.14 / 180);
double y = c[i][2] * sin(c[i][3] * 3.14 / 180);
Complex x1(x, 0);
Complex y1(0, y);
e[i] = x1 + y1;
}
else
{
if (c[i][0] == r[i][1])
{
double x = -c[i][2] * cos(c[i][3] * 3.14 / 180);
double y = -c[i][2] * sin(c[i][3] * 3.14 / 180);
Complex x1(x, 0);
Complex y1(0, y);
e[i] = x1 + y1;
}
else
{
e[i] = 0.0;
}
}
}
}
void amp(double r[12][5], double p[12][4], Complex j[12])
{
for (int i = 0; i < 12; i++)
{
if (p[i][0] == r[i][0])
{
double x = p[i][2] * cos(p[i][3] * 3.14 / 180);
double y = p[i][2] * sin(p[i][3] * 3.14 / 180);
Complex x1(x, 0);
Complex y1(0, y);
j[i] = x1 + y1;
}
else
{
if (p[i][0] == r[i][1])
{
double x = -p[i][2] * cos(p[i][3] * 3.14 / 180);
double y = -p[i][2] * sin(p[i][3] * 3.14 / 180);
Complex x1(x, 0);
Complex y1(0, y);
j[i] = x1 + y1;
}
else
{
j[i] = 0.0;
}
}
}
}
void add(Complex q[12], Complex j[12], Complex s[12])
{
for (int i = 0; i < 12; i++)
s[i] = q[i] + j[i];
}
Complex Amperage(Complex x[7], Complex y[12][12], Complex e[12], Complex j[12], double p[12][4], double r[12][5], Complex I[12], Complex Uj, double f)
{
for (int i = 0; i < 12; i++)
{
if (p[i][3] == 0)
{
int x1 = r[i][0];
int x2 = r[i][1];
Complex z = x[x1 - 1] - x[x2 - 1];
Complex c = z + e[i];
Complex v = c * y[i][i];
I[i] = v;
}
else
{
I[i] = j[i];
int x1 = p[i][0];
int x2 = p[i][1];
Complex z1 = x[x1] - x[x2];
double xl, xc;
xl = 2 * 3.14 * f * r[i][3];
xc = 1 / (2 * 3.14*f*r[i][4]);
if (r[i][4] == 0)
xc = 0;
Complex z(r[i][2], (xl - xc));
Complex c = I[i] * z;
Complex v = z1 + c;
Uj = v;
}
}
return Uj;
}
Complex Sp(double p[12][4], double r[12][5], Complex I[12], int f)
{
Complex Sp = 0.0;
for (int i = 0; i < 12; i++)
{
double xl, xc;
xl = 2 * 3.14 * f * r[i][3];
xc = 1 / (2 * 3.14*f*r[i][4]);
if (r[i][4] == 0)
xc = 0;
Complex z(r[i][2], (xl - xc));
Complex I2 = I[i] * I[i];
Complex x = z * I2;
Sp += x;
}
return Sp;
}
Complex Si(Complex j[12], Complex e[12], Complex I[12], Complex Uj)
{
Complex Si = 0.0;
for (int i = 0; i < 12; i++)
{
Complex x = j[i] * Uj;
Complex r(I[i]);
Complex c = r.conj();
Complex y = e[i] * I[i];
Complex z = x + y;
Si += z;
}
return Si;
}
void Gauss(Complex mas[6][7], Complex x[6])
{
//прямой ход
for (int i = 0; i < 6; i++) {
Complex first = mas[i][i]; //временная переменная для элемента главной диагонали
for (int j = 0; j < 7; j++) {
Complex a(mas[i][j] / first);
mas[i][j] = (a); //деление строки на элемент главной диагонали
}
for (int k = i + 1; k < 6; k++) {
Complex first_in_line = mas[k][i];
for (int c = i; c < 7; c++) {
Complex a(mas[i][c] * first_in_line);
Complex b(a - mas[k][c]);
mas[k][c] = b; //зануление элементов под главной диагональю
}
}
}
//обратный ход
x[5] = mas[5][6];
for (int i = 4; i >= 0; i--) {
for (int j = 5; j > i; j--) {
Complex a(mas[i][j] * x[j]);
Complex b(mas[i][6] - a);
mas[i][6] = (b);
}
x[i] = mas[i][6];
}
}
int main()
{
setlocale(LC_ALL, "Russian");
ifstream inputr("inputr.txt");
ifstream inputc("inputc.txt");
ifstream inputp("inputp.txt");
double r[12][5];
double c[12][4];
double p[12][4];
for (int i = 0; i < 12; i++)
{
inputr >> r[i][0] >> r[i][1] >> r[i][2] >> r[i][3] >> r[i][4];
}
for (int i = 0; i < 12; i++)
{
inputc >> c[i][0] >> c[i][1] >> c[i][2] >> c[i][3];
}
for (int i = 0; i < 12; i++)
{
inputp >> p[i][0] >> p[i][1] >> p[i][2] >> p[i][3];
}
int f;
inputr >> f;
double a[6][12]; double at[12][6];
Complex j[12];
Complex e[12];
Complex q[12];
Complex s[12];
Complex rr[6];
Complex y[12][12];
Complex q1[6][12];
Complex x[6][7];
Complex x1[6][6];
Complex I[12];
Complex x2[7];
Complex Uj;
top(r, a);
tr(a, at);
eds(r, c, e);
amp(r, p, j);
Y(y, f, r, p);
mul(a, y, q1);
mul2(q1, at, x);
mul3(y, e, q);
add(q, j, s);
mul4(a, s, rr);
//расширенная матрица
Complex Extended_matrix[6][7];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
Extended_matrix[i][j] = x[i][j]; //заполнение расширенной матрицы значениями проводимостей
}
Extended_matrix[i][6] = rr[i]; //заполнение последнего столбца исчтониками тока
}
Gauss(Extended_matrix, x2);
Uj = Amperage(x2, y, e, j, p, r, I, Uj, f);
Complex Spotr = Sp(p, r, I, f);
Complex Sist = Si(j, e, I, Uj);
for (int i = 0; i < 12; i++)
cout << r[i][0] << " " << r[i][1] << " " << r[i][2] << " " << r[i][3] << " " << r[i][4] << " " << c[i][0] << " " << c[i][1] << " " << c[i][2]
<< " " << c[i][3] << " " << p[i][0] << " " << p[i][1] << " " << p[i][2] << " " << p[i][3] << endl;
cout << endl;
cout << endl;
ofstream res("res.txt");
for (int i = 0; i < 7; i++)
{
res << "fi[" << i + 1 << "]=" << x2[i] << endl;
cout << "fi[" << i + 1 << "]=" << x2[i] << endl;
}
res << endl;
cout << endl;
for (int i = 0; i < 12; i++)
{
res << "I[" << i + 1 << "]=" << I[i] << endl;
cout << "I[" << i + 1 << "]=" << I[i] << endl;
}
res << "Uj=" << Uj << endl;
res << "Sпотр=" << Spotr << endl;
res << "Sист=" << Sist << endl;
cout << "Uj=" << Uj << endl;
cout << "Sпотр=" << Spotr << endl;
cout << "Sист=" << Sist << endl;
inputr.close();
inputc.close();
inputp.close();
res.close();
system("pause");
return 0;
} |