Skip to content

Commit

Permalink
[task_01] Add solution (brstu#20)
Browse files Browse the repository at this point in the history
* create trunk

* Update main.cpp

* edit readme

* edit 2 readme
  • Loading branch information
alexsandro007 authored Sep 28, 2024
1 parent 039469d commit d6c01ae
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 1 deletion.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
|21|Стельмашук Иван|||||||||||
|22|Тунчик Антон|||||||||||
|23|Филипчук Дмитрий|||||||||||
|24|Ярмола Александр|||||||||||
|24|Ярмола Александр|[as0006325](./trunk/as0006325/)|:white_check_mark:|:white_check_mark:||||||||
|25|Ярмолович Александр|||||||||||

## Группа АС-64
Expand Down
63 changes: 63 additions & 0 deletions trunk/as0006325/task_01/doc/readme.md
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
```
4 changes: 4 additions & 0 deletions trunk/as0006325/task_01/src/CMakeLists.txt
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)
57 changes: 57 additions & 0 deletions trunk/as0006325/task_01/src/main.cpp
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;
}

0 comments on commit d6c01ae

Please sign in to comment.