diff --git a/.gitignore b/.gitignore index c28ecf35..2cd63d8b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ # Directories to ignore .vs/ out/ +build/ ### macOS ### # General diff --git a/readme.md b/readme.md index 8f7b8178..9f5231db 100644 --- a/readme.md +++ b/readme.md @@ -33,7 +33,7 @@ |11|Крагель Алина||||||||||| |12|Куликович Иван||||||||||| |13|Кульбеда Кирилл||||||||||| -|14|Кухарчук Илья||||||||||| +|14|Кухарчук Илья|[as0006314](trunk/as0006314)|||||||||| |15|Логинов Глеб||||||||||| |16|Мороз Евгений||||||||||| |17|Никифоров Александр||||||||||| 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; +}