Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[task_01] Add solution #39

Merged
merged 19 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
|8|Козлович Антон|||||||||||
|9|Козловская Анна|||||||||||
|10|Колодич Максим|||||||||||
|11|Крагель Алина|||||||||||
|11|Крагель Алина|[as0006311](./trunk/as0006311/)|:white_check_mark:|:white_check_mark:||||||||
|12|Куликович Иван|||||||||||
|13|Кульбеда Кирилл|||||||||||
|14|Кухарчук Илья|[as0006314](trunk/as0006314)||||||||||
Expand Down
58 changes: 58 additions & 0 deletions trunk/as0006311/task_01/doc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<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 consider the wrong object, the control of which consists of controlling its temperature, described by the following differential equations:

After transformations we have the following linear (2) and nonlinear (3) models:

The goal is to write a program in C++ that will simulate the temperature of a given object.

Пример вывода программы:

``` bash
Enter the constant alpha for the model: 0.08
Enter the constant beta for the linear model: 0.06
Enter the constant gamma for the nonlinear model: 0.02
Enter the constant delta for the nonlinear model: 0.01
Enter the initial temperature (initialTemp): 20
Enter the number of discrete time moments: 5
Enter the heat values (heatInput) for each time moment:
heatInput[1]: 10
heatInput[2]: 15
heatInput[3]: 20
heatInput[4]: 25
heatInput[5]: 30

Linear Model Simulation:
Time 1: Temperature = 20
Time 2: Temperature = 2.2
Time 3: Temperature = 1.076
Time 4: Temperature = 1.28608
Time 5: Temperature = 1.60289

Non-linear Model Simulation:
Time 1: Temperature = 20
Time 2: Temperature = -22.2054
Time 3: Temperature = -31.0548
Time 4: Temperature = -59.9394
Time 5: Temperature = -219.86
```
4 changes: 4 additions & 0 deletions trunk/as0006311/task_01/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.5.0)
project(main VERSION 0.1.0 LANGUAGES C CXX)

add_executable(main main.cpp)
80 changes: 80 additions & 0 deletions trunk/as0006311/task_01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

// Function to simulate the linear model
vector<double> calculateLinearTemp(double alpha, double beta, double initialTemp, const vector<double>& heatInput, int steps) {
vector<double> temperature(steps);
temperature[0] = initialTemp; // Initial temperature

// Loop through each time step to calculate the temperature
for (int time = 1; time < steps; ++time) {
temperature[time] = alpha * temperature[time - 1] + beta * heatInput[time - 1]; // Update temperature based on the linear model
}

return temperature; // Return the vector of temperatures
}

// Function to simulate the nonlinear model
vector<double> calculateNonLinearTemp(double alpha, double beta, double gamma, double delta, double initialTemp, const vector<double>& heatInput, int steps) {
vector<double> temperature(steps);
temperature[0] = initialTemp; // Initial temperature

// Loop through each time step to calculate the temperature
for (int time = 1; time < steps; ++time) {
double prev_temp = temperature[time - 1];
double prev_input = heatInput[time - 1];
temperature[time] = alpha * prev_temp - beta * pow(prev_temp, 2) + gamma * prev_input + delta * sin(prev_input); // Nonlinear model update
}

return temperature; // Return the vector of temperatures
}

int main() {
// Input constants from user
double alpha, beta, gamma, delta, initialTemp;
cout << "Enter the constant alpha for the model: ";
cin >> alpha;
cout << "Enter the constant beta for the linear model: ";
cin >> beta;
cout << "Enter the constant gamma for the nonlinear model: ";
cin >> gamma;
cout << "Enter the constant delta for the nonlinear model: ";
cin >> delta;
cout << "Enter the initial temperature (initialTemp): ";
cin >> initialTemp;

// Input the number of time moments
int steps;
cout << "Enter the number of discrete time moments: ";
cin >> steps;

// Input the heat values
vector<double> heatInput(steps);
cout << "Enter the heat values (heatInput) for each time moment:" << endl;
for (int i = 0; i < steps; ++i) {
cout << "heatInput[" << i + 1 << "]: ";
cin >> heatInput[i]; // Read input for each heat value
}

// Simulate the linear model
vector<double> linearTemp = calculateLinearTemp(alpha, beta, initialTemp, heatInput, steps);

// Simulate the nonlinear model
vector<double> nonLinearTemp = calculateNonLinearTemp(alpha, beta, gamma, delta, initialTemp, heatInput, steps);

// Output results
cout << "\nLinear Model Simulation:" << endl;
for (int time = 0; time < steps; ++time) {
cout << "Time " << time + 1 << ": Temperature = " << linearTemp[time] << endl;
}

cout << "\nNon-linear Model Simulation:" << endl;
for (int time = 0; time < steps; ++time) {
cout << "Time " << time + 1 << ": Temperature = " << nonLinearTemp[time] << endl;
}

return 0; // Indicate successful completion
}
Loading