forked from brstu/TMAU-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
534 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,9 @@ | |
|
||
# Directories to ignore | ||
.vs/ | ||
.vscode | ||
out/ | ||
build/ | ||
|
||
### macOS ### | ||
# General | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Laboratory work ¹.1 | ||
<p align="center">MINISTRY OF EDUCATION OF THE REPUBLIC OF BELARUS</p> | ||
<p align="center">EDUCATIONAL INSTITUTION</p> | ||
<p align="center">«BREST STATE TECHNICAL UNIVERSITY»</p> | ||
<p align="center">Department of IIT</p> | ||
<br><br><br><br> | ||
<p align="center">Laboratory work ¹.1</p> | ||
<br><br><br> | ||
<p align="right">Completed by the 3rd year student of</p> | ||
<p align="right">the Faculty of Electronic Information Systems</p> | ||
<p align="right">the group AC-63 Kukharchuk I.N.</p> | ||
<p align="right">Checked by Ivanuk D.S.</p> | ||
<br><br><br> | ||
<p align="center">Brest 2024</p> | ||
|
||
--- | ||
|
||
## 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. | ||
|
||
<p align="center" style="font-size:25px;font-weight: bold"> | ||
RESULTS</p> | ||
|
||
<p align="center"><img style='border:4px solid #000000'src="result.png"/></p> | ||
|
||
### 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 | ||
``` | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake_minimum_required (VERSION 3.0.0) | ||
project (ModelingTemperature) | ||
|
||
add_executable(MainFile main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
// 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<p align="center"> Министерство образования Республики Беларусь</p> | ||
<p align="center">Учреждение образования</p> | ||
<p align="center">“Брестский Государственный технический университет”</p> | ||
<p align="center">Кафедра ИИТ</p> | ||
<br><br><br><br><br><br><br> | ||
<p align="center">Лабораторная работа №1</p> | ||
<p align="center">По дисциплине “Теория и методы автоматического управления”</p> | ||
<p align="center">Тема: “Моделирования температуры объекта”</p> | ||
<br><br><br><br><br> | ||
<p align="right">Выполнил:</p> | ||
<p align="right">Студент 3 курса</p> | ||
<p align="right">Группы АС-63</p> | ||
<p align="right">Ярмола А. О.</p> | ||
<p align="right">Проверила:</p> | ||
<p align="right">Ситковец Я. С.</p> | ||
<br><br><br><br><br> | ||
<p align="center">Брест 2024</p> | ||
|
||
--- | ||
|
||
**Задание**: | ||
|
||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(Task01) | ||
|
||
add_executable(Task01 main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
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; | ||
} |
Oops, something went wrong.