This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathMMIPLAB2.cpp
106 lines (101 loc) · 2.16 KB
/
MMIPLAB2.cpp
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
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
class Regulator
{
protected:
const double k = 0.1, t = 15, t_d = 50, t_0 = 10;
const double a = 1, b = 0.0033, y_0 = 18, c = 0.525, d = 0.525, w_t = 100;
const int j = 150;
double e = 0;
double prev_e = 0;
double prev2_e = 0;
double u = 0;
double d_u = 0;
double prev_u = 0;
};
class Linear : public Regulator
{
private:
double* y = new double[j + 1];
double q0, q1, q2;
public:
Linear()
{
ofstream fout("D:\\repos\\MMIPLAB2\\Linear.txt");
if (!fout.is_open())
{
cout << "Ошибка открытия файла!\n";
return;
}
y[0] = y_0;
q0 = k * (1 + t_d / t_0);
q1 = -k * (1 + 2 * t_d / t_0 - t_0 / t);
q2 = k * t_d / t_0;
for (int i = 0; i < j; i++)
{
prev_u = u;
prev2_e = prev_e;
prev_e = e;
e = w_t - y[i];
d_u = q0 * e + q1 * prev_e + q2 * prev2_e;
u = prev_u + d_u;
y[i + 1] = a * y[i] + b * u;
fout << i << "\t" << y[i] << "\t" << u << "\t" << e << endl;
}
fout << j << "\t" << y[j] << "\t" << u << "\t" << e << endl;
fout.close();
cout << "Файл Linear.txt обновлён!\n";
}
~Linear()
{
delete[] y;
}
};
class NonLinear : public Regulator
{
private:
double* y = new double[j + 1];
double q0, q1, q2;
public:
NonLinear()
{
ofstream fout("D:\\repos\\MMIPLAB2\\NonLinear.txt");
if (!fout.is_open())
{
cout << "Ошибка открытия файла!\n";
return;
}
y[0] = y_0;
q0 = k * (1 + t_d / t_0);
q1 = -k * (1 + 2 * t_d / t_0 - t_0 / t);
q2 = k * t_d / t_0;
for (int i = 0; i < j; i++)
{
prev_u = u;
prev2_e = prev_e;
prev_e = e;
e = w_t - y[i];
d_u = q0 * e + q1 * prev_e + q2 * prev2_e;
u = prev_u + d_u;
if (i != 0) y[i + 1] = a * y[i] - b * y[i - 1] * y[i - 1] + c * u + d * sin(prev_u);
else y[i + 1] = a * y[i] + c * u + d * sin(prev_u);
fout << i << "\t" << y[i] << "\t" << u << "\t" << e << endl;
}
fout << j << "\t" << y[j] << "\t" << u << "\t" << e << endl;
fout.close();
cout << "Файл NonLinear.txt обновлён!\n";
}
~NonLinear()
{
delete[] y;
}
};
int main()
{
setlocale(LC_ALL, "rus");
Linear L;
NonLinear NL;
return 0;
}