diff --git a/.gitignore b/.gitignore index c28ecf35..a2f18293 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,9 @@ # Directories to ignore .vs/ +.vscode out/ +build/ ### macOS ### # General diff --git a/readme.md b/readme.md index 8f7b8178..2b708dd3 100644 --- a/readme.md +++ b/readme.md @@ -33,7 +33,7 @@ |11|Крагель Алина||||||||||| |12|Куликович Иван||||||||||| |13|Кульбеда Кирилл||||||||||| -|14|Кухарчук Илья||||||||||| +|14|Кухарчук Илья|[as0006314](trunk/as0006314)|||||||||| |15|Логинов Глеб||||||||||| |16|Мороз Евгений||||||||||| |17|Никифоров Александр||||||||||| @@ -43,7 +43,7 @@ |21|Стельмашук Иван||||||||||| |22|Тунчик Антон||||||||||| |23|Филипчук Дмитрий||||||||||| -|24|Ярмола Александр||||||||||| +|24|Ярмола Александр|[as0006325](./trunk/as0006325/)|:white_check_mark:|:white_check_mark:|||||||| |25|Ярмолович Александр||||||||||| ## Группа АС-64 @@ -62,7 +62,7 @@ |10|Игнаткевич Кирилл Сергеевич||||||||||| |11|Кашпир Дмитрий Русланович||||||||||| |12|Котковец Кирилл Викторович||||||||||| -|13|Кужир Владислав Витальевич||||||||||| +|13|Кужир Владислав Витальевич|[as0006313](./trunk/as0006413/)|:white_check_mark:||||||||| |14|Немирович Дмитрий Александрович||||||||||| |15|Попов Алексей Сергеевич||||||||||| |16|Рабченя Максим Юрьевич||||||||||| diff --git a/trunk/as0006314/task_01/doc/readme.md b/trunk/as0006314/task_01/doc/readme.md new file mode 100644 index 00000000..9f6b81be --- /dev/null +++ b/trunk/as0006314/task_01/doc/readme.md @@ -0,0 +1,51 @@ +# Laboratory work .1 +

MINISTRY OF EDUCATION OF THE REPUBLIC OF BELARUS

+

EDUCATIONAL INSTITUTION

+

BREST STATE TECHNICAL UNIVERSITY

+

Department of IIT

+



+

Laboratory work .1

+


+

Completed by the 3rd year student of

+

the Faculty of Electronic Information Systems

+

the group AC-63 Kukharchuk I.N.

+

Checked by Ivanuk D.S.

+


+

Brest 2024

+ +--- + +## Task 1. Modeling controlled object : + +Write program (C++), which simulate object temperature. + +### Realization +There are two classes in the program: + +1. LinearModel represents linear model. +2. NonlinearModel represents nonlinear model. + +

+RESULTS

+ +

+ +### How to build the project? + +1. The first you need to clone this repository to your computer. + +2. Go to the folder "trunk\as0006314\task_01\src". + +3. Run the command line and type 6 commands : + +```console +mkdir build +cd build +cmake .. +cmake --build . +cd trunk\as0006314\task_01\src\Debug\ +.\MainFile.exe +``` + + + diff --git a/trunk/as0006314/task_01/doc/result.png b/trunk/as0006314/task_01/doc/result.png new file mode 100644 index 00000000..a63a16cc Binary files /dev/null and b/trunk/as0006314/task_01/doc/result.png differ diff --git a/trunk/as0006314/task_01/src/CMakeLists.txt b/trunk/as0006314/task_01/src/CMakeLists.txt new file mode 100644 index 00000000..89cb30b7 --- /dev/null +++ b/trunk/as0006314/task_01/src/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required (VERSION 3.0.0) +project (ModelingTemperature) + +add_executable(MainFile main.cpp) \ No newline at end of file diff --git a/trunk/as0006314/task_01/src/main.cpp b/trunk/as0006314/task_01/src/main.cpp new file mode 100644 index 00000000..1cd8b7da --- /dev/null +++ b/trunk/as0006314/task_01/src/main.cpp @@ -0,0 +1,99 @@ +#include +#include + +// Interface for different models +class TemperatureModel { +public: + virtual ~TemperatureModel() = default; + virtual double calculate(double currentTemp, double heatInput) = 0; +}; + +// Linear temperature control model +class SimpleLinearModel : public TemperatureModel { +private: + double coeff1; + double coeff2; +public: + SimpleLinearModel(double coeff1, double coeff2) : coeff1(coeff1), coeff2(coeff2) {} + + ~SimpleLinearModel() override = default; + + // Calculate temperature based on a linear equation + double calculate(double currentTemp, double heatInput) override { + return coeff1 * currentTemp + coeff2 * heatInput; + } +}; + +// Nonlinear temperature control model +class ComplexNonlinearModel : public TemperatureModel { +private: + double coeff1; + double coeff2; + double coeff3; + double coeff4; + double previousTemp = 0; + double previousHeat = 0; +public: + ComplexNonlinearModel(double coeff1, double coeff2, double coeff3, double coeff4) + : coeff1(coeff1), coeff2(coeff2), coeff3(coeff3), coeff4(coeff4) {} + + ~ComplexNonlinearModel() override = default; + + // Calculate temperature based on a nonlinear equation + double calculate(double currentTemp, double heatInput) override { + double result = coeff1 * currentTemp - coeff2 * pow(previousTemp, 2) + coeff3 * heatInput + coeff4 * sin(previousHeat); + previousTemp = currentTemp; + previousHeat = heatInput; + return result; + } +}; + +// Function to simulate the temperature modeling process +void runSimulation(TemperatureModel& model, double initialTemp, int steps) { + double heatInput; + for (int step = 1; step <= steps; ++step) { + std::cout << "Enter heat flow value (Uw): "; std::cin >> heatInput; + initialTemp = model.calculate(initialTemp, heatInput); + std::cout << "\tStep " << step << "\tTemperature: " << initialTemp << std::endl; + } +} + +int main() { + double initialTemp; + double coeff1, coeff2, coeff3, coeff4; + int numSteps; + + // Input parameters for the linear model + std::cout << "Enter parameters for the linear model" << std::endl; + std::cout << "Parameter a: "; std::cin >> coeff1; + std::cout << "Parameter b: "; std::cin >> coeff2; + + SimpleLinearModel linearModel(coeff1, coeff2); + + // Input parameters for the nonlinear model + std::cout << "Enter parameters for the nonlinear model" << std::endl; + std::cout << "Parameter a: "; std::cin >> coeff1; + std::cout << "Parameter b: "; std::cin >> coeff2; + std::cout << "Parameter c: "; std::cin >> coeff3; + std::cout << "Parameter d: "; std::cin >> coeff4; + + ComplexNonlinearModel nonlinearModel(coeff1, coeff2, coeff3, coeff4); + + std::cout << "Enter initial temperature: "; std::cin >> initialTemp; + + // Simulation for the linear model + std::cout << "Enter the number of simulation steps for the linear model: "; + std::cin >> numSteps; + std::cout << "\n--- Simulation for the linear model ---" << std::endl; + runSimulation(linearModel, initialTemp, numSteps); + + std::cout << std::endl; + + // Simulation for the nonlinear model + std::cout << "Enter the number of simulation steps for the nonlinear model: "; + std::cin >> numSteps; + std::cout << "\n--- Simulation for the nonlinear model ---" << std::endl; + runSimulation(nonlinearModel, initialTemp, numSteps); + + return 0; +} diff --git a/trunk/as0006325/task_01/doc/readme.md b/trunk/as0006325/task_01/doc/readme.md new file mode 100644 index 00000000..1002a85c --- /dev/null +++ b/trunk/as0006325/task_01/doc/readme.md @@ -0,0 +1,63 @@ +

Министерство образования Республики Беларусь

+

Учреждение образования

+

“Брестский Государственный технический университет”

+

Кафедра ИИТ

+






+

Лабораторная работа №1

+

По дисциплине “Теория и методы автоматического управления”

+

Тема: “Моделирования температуры объекта”

+




+

Выполнил:

+

Студент 3 курса

+

Группы АС-63

+

Ярмола А. О.

+

Проверила:

+

Ситковец Я. С.

+




+

Брест 2024

+ +--- + +**Задание**: + +Let's get some object to be controlled. We want to control its temperature, which can be described by this differential equation: + +$$\Large\frac{dy(\tau)}{d\tau}=\frac{u(\tau)}{C}+\frac{Y_0-y(\tau)}{RC} $$ (1) + +where $\tau$ – time; $y(\tau)$ – input temperature; $u(\tau)$ – input warm; $Y_0$ – room temperature; $C,RC$ – some constants. + +After transformation we get these linear (2) and nonlinear (3) models: + +$$\Large y_{\tau+1}=ay_{\tau}+bu_{\tau}$$ (2) + +$$\Large y_{\tau+1}=ay_{\tau}-by_{\tau-1}^2+cu_{\tau}+d\sin(u_{\tau-1})$$ (3) + +where $\tau$ – time discrete moments ($1,2,3{\dots}n$); $a,b,c,d$ – some constants. + +Task is to write program (**С++**), which simulates this object temperature. + +Пример вывода программы: + +``` bash +Enter the value for constant a: 1 +Enter the value for constant b: 2 +Enter the value for constant c: 3 +Enter the value for constant d: 4 +Enter the initial value for current temperature, y: 10 +Enter the initial control value, u: 5 +Enter the number of iterations, steps: 5 + +Linear model simulation: +Step 1: y = 20 +Step 2: y = 30 +Step 3: y = 40 +Step 4: y = 50 +Step 5: y = 60 + +Nonlinear model simulation: +Step 1: y = 25 +Step 2: y = -163.836 +Step 3: y = -1402.67 +Step 4: y = -55075.8 +Step 5: y = -3.99004e+06 +``` \ No newline at end of file diff --git a/trunk/as0006325/task_01/src/CMakeLists.txt b/trunk/as0006325/task_01/src/CMakeLists.txt new file mode 100644 index 00000000..f9d44bc0 --- /dev/null +++ b/trunk/as0006325/task_01/src/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.10) +project(Task01) + +add_executable(Task01 main.cpp) \ No newline at end of file diff --git a/trunk/as0006325/task_01/src/main.cpp b/trunk/as0006325/task_01/src/main.cpp new file mode 100644 index 00000000..da165283 --- /dev/null +++ b/trunk/as0006325/task_01/src/main.cpp @@ -0,0 +1,57 @@ +#include +#include + +using namespace std; + +// Function for linear model +void linearModel(double y, double u, double a, double b, int steps) { + for (int i = 1; i <= steps; i++) { + double y_next = a * y + b * u; + cout << "Step " << i << ": y = " << y_next << endl; + + y = y_next; + } +} + +// Function for nonlinear model +void nonlinearModel(double y, double u, double a, double b, double c, double d, int steps) { + double y_prev = 0; + double u_prev = 0; + + for (int i = 1; i <= steps; i++) { + double y_next = a * y - b * y_prev * y_prev + c * u + d * sin(u_prev); + cout << "Step " << i << ": y = " << y_next << endl; + + y_prev = y; // Update the previous temperature value + u_prev = u; // Update the previous control value + + y = y_next; // Update the current temperature value + } +} + +int main() { + double a, b, c, d; // Constants + double y; // Current temperature + double u; // Current heat + int steps; // Number of modeling steps + + cout << "Enter the value for constant a: "; cin >> a; + cout << "Enter the value for constant b: "; cin >> b; + cout << "Enter the value for constant c: "; cin >> c; + cout << "Enter the value for constant d: "; cin >> d; + + cout << "Enter the initial value for current temperature, y: "; cin >> y; + cout << "Enter the initial control value, u: "; cin >> u; + + cout << "Enter the number of iterations, steps: "; cin >> steps; + + // Linear model + cout << "\nLinear model simulation:\n"; + linearModel(y, u, a, b, steps); + + // Nonlinear model + cout << "\nNonlinear model simulation:\n"; + nonlinearModel(y, u, a, b, c, d, steps); + + return 0; +} diff --git a/trunk/as0006413/task_01/doc/readme.md b/trunk/as0006413/task_01/doc/readme.md new file mode 100644 index 00000000..3f4a8801 --- /dev/null +++ b/trunk/as0006413/task_01/doc/readme.md @@ -0,0 +1,154 @@ + Ministry of Education of the Republic of Belarus + + Educational Institution + + “Brest State Technical University” + + Department of Information and Intelligent Technologies + + + + Laboratory work №1 + + On the discipline “Theory and methods of automatic control” + + Topic: “Temperature modeling of an object” + + + + Performed by: + + Student of the 3rd course + + Group AS-64 + + Kuzhyr U. V. + + Supervised by: + + Sitkovets J. S. + + + Brest 2024 + + + + +## Task: + +Let's get some object to be controlled. We want to control its temperature, which can be described by this differential equation: + + +$$ +\Large\frac{dy(\tau)}{d\tau}=\frac{u(\tau)}{C}+\frac{Y_0-y(\tau)}{RC}(1) + $$ + +where τ – time; y ( τ ) – input temperature; u ( τ ) – input warm; Y 0 – room temperature; C , R C – some constants. + +After transformation we get these linear (2) and nonlinear (3) models: + +$$ +\Large y_{\tau+1}=ay_{\tau}+bu_{\tau}(2) +$$ + +$$ +\Large y_{\tau+1}=ay_{\tau}-by_{\tau-1}^2+cu_{\tau}+d\sin(u_{\tau-1})(3) +$$ + +where τ – time discrete moments ( 1 , 2 , 3 … n ); a , b , c , d – some constants. + +Task is to write program (С++), which simulates this object temperature. +Example of program output: + +``` + +Choose an option (0 - exit, 1 - linear model, 2 - nonlinear model): Input choice: 1 +Input A: 12 +Input B: 2 +Input current temperature: 36 +Input heat input: 2 +Input simulation time: 10 +TIME Linear Model +========================= +1 436 +2 5236 +3 62836 +4 754036 +5 9.04844e+06 +6 1.08581e+08 +7 1.30297e+09 +8 1.56357e+10 +9 1.87628e+11 +10 2.25154e+12 + +Choose an option (0 - exit, 1 - linear model, 2 - nonlinear model): Input choice: 2 +Input A: 3 +Input B: 15 +Input C: 20 +Input D: 25 +Input current temperature: 27 +Input heat input: 37 +Input simulation time: 20 +TIME Nonlinear Model +1 804.912 +2 -7796.35 +3 -9.7409e+06 +4 -9.40969e+08 +5 -1.42328e+15 +6 -1.32856e+19 +7 -3.03859e+31 +8 -2.64761e+39 +PS C:\Users\user\Desktop\TMAU-2024\build\trunk\as006417\task_01\src> ./lab_01.exe + +Choose an option (0 - exit, 1 - linear model, 2 - nonlinear model): Input choice: 1 +Input A: 1.1 +Input B: 0.5 +Input current temperature: 25 +Input heat input: 10 +Input simulation time: 5 +TIME Linear Model +========================= +1 32.5 +2 40.75 +3 49.825 +4 59.8075 +5 70.7883 + +Choose an option (0 - exit, 1 - linear model, 2 - nonlinear model): Input choice: 2 +Input A: 1.2 +Input B: 0.1 +Input C: 0.3 +Input D: 0.05 +Input current temperature: 30 +Input heat input: 15 +Input simulation time: 5 +TIME Nonlinear Model +========================= +1 40.5325 +2 -36.8285 +3 -203.95 +4 -375.841 +``` + +## Input erroe handling + +``` +Choose an option (0 - exit, 1 - linear model, 2 - nonlinear model): Input choice: p + +*** Incorrect input *** +Input choice: 5 +*** Invalid input *** +``` + +## Exit the program +``` +Choose an option (0 - exit, 1 - linear model, 2 - nonlinear model): Input choice: 0 +PS C:\Users\user\Desktop\TMAU-2024\build\trunk\as006417\task_01\src> ^C +``` + +The source code + +The source code is located in the src folder. + + CMakeLists.txt - this is a file that contains CMake commands to control the project build process. + main.cpp - source file, contains the main function that controls the program execution. diff --git a/trunk/as0006413/task_01/src/CMakeLists.txt b/trunk/as0006413/task_01/src/CMakeLists.txt new file mode 100644 index 00000000..c5b94f2c --- /dev/null +++ b/trunk/as0006413/task_01/src/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required (VERSION 3.0.0) + +project (lab_01) + +add_executable(${PROJECT_NAME} main.cpp) \ No newline at end of file diff --git a/trunk/as0006413/task_01/src/main.cpp b/trunk/as0006413/task_01/src/main.cpp new file mode 100644 index 00000000..bf8ddc23 --- /dev/null +++ b/trunk/as0006413/task_01/src/main.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +using namespace std; + +void run_linear_model(); +void run_nonlinear_model(); +bool get_choice(int &choice); + +void get_input(double &value, const string &prompt) { + cout << prompt << ": "; + while (!(cin >> value)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid input! Try again.\n" << prompt << ": "; + } +} + +void get_input(int &value, const string &prompt) { + cout << prompt << ": "; + while (!(cin >> value)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid input! Try again.\n" << prompt << ": "; + } +} + +void display_results(const map &temps, const string &model_type) { + cout << "\n--- " << model_type << " Results ---\n"; + for (const auto &entry : temps) { + cout << "Step " << entry.first << ": Temperature = " << entry.second << endl; + } +} + +void run_linear_model() { + double A, B, temp, heat; + int steps; + get_input(A, "Enter coefficient A"); + get_input(B, "Enter coefficient B"); + get_input(temp, "Enter initial temperature"); + get_input(heat, "Enter heat input"); + get_input(steps, "Enter number of steps"); + + map temps; + for (int i = 1; i <= steps; ++i) { + temp = A * temp + B * heat; + temps[i] = temp; + } + display_results(temps, "Linear Model"); +} + +void run_nonlinear_model() { + double A, B, C, D, temp, heat; + int steps; + get_input(A, "Enter coefficient A"); + get_input(B, "Enter coefficient B"); + get_input(C, "Enter coefficient C"); + get_input(D, "Enter coefficient D"); + get_input(temp, "Enter initial temperature"); + get_input(heat, "Enter heat input"); + get_input(steps, "Enter number of steps"); + + map temps; + double prev_temp = 0; + for (int i = 1; i <= steps; ++i) { + double new_temp = A * temp - B * pow(prev_temp, 2) + C * heat + D * sin(heat); + prev_temp = temp; + temp = new_temp; + temps[i] = temp; + } + display_results(temps, "Nonlinear Model"); +} + +bool get_choice(int &choice) { + get_input(choice, "Choose option (0 - Exit, 1 - Linear, 2 - Nonlinear)"); + return choice >= 0 && choice <= 2; +} + +int main() { + void (*models[])() = { []() { exit(0); }, run_linear_model, run_nonlinear_model }; + int choice; + + while (true) { + if (!get_choice(choice)) { + cout << "Invalid choice! Try again.\n"; + } else { + models[choice](); + } + } +}