Effacer les filtres
Effacer les filtres

Creating a for loop with coditions

1 vue (au cours des 30 derniers jours)
Hamzah Faraj
Hamzah Faraj le 18 Avr 2020
Commenté : darova le 19 Avr 2020
Hello,
There are 2 heaters with modes on (m1: heter1 , m2 for heter2) and mode off (m0) and I want to keep the temperature in a room between Vmin=18 °C and Vmax= 22 °C within Tmax=7 hours. and the initial temperature at t=0 is 18 °C. Every time the mode switiched on (m1 or m2) there is a discrete cost paid PiD(m1)= 30 and PiD(m2)= 10 and the cost for staying in this mode is PiC(m1) = 10 and PiC(m2) = 20 while there is no cost for switich off PiD(m0) = PiC(m0) = 0.
The modes parameter (A) are as follows: A(m1)=4/3, A(m2)=2 and A(m0)=-4
For example, the temperature in the room needs 3 hours to reach Vmax using (m1) and 2 hours to reach Vmax using (m2) while just 1 hour to be cooled from Vmax to Vmin.
I am trying to create a loop that generates safe scedules (alpha) with the shape of alpha=<(m0,t0),(m1,t1), (m2,t2),(m3,t3),...(mi-1,ti-1),(mi,ti)>
with the following constraints in order to calculate the the cost of alpha, Pi(alpha)= sumPiD+ sumPiC*ti
% mi Not equal mi+1
% run(alpha)=<v0,v1,v2,v3,...,vi-1,v0)> within T(alpha)=<t0,t1,t2,t3,...,ti-1,ti>
% % Vmin <= V(i) <= Vmax
% 0 < ti <=Tmax
% sum(ti)= Tmax
%
% V(t0) = V(0) = V0 = 18
% V(i) not equal V(i+1), either greater or lower depending on the mode.
% V(i)= V(i-1)+(A(m i)*[((sum(from i=0 to t(i)) ti))-(sum(from i=0 to t(i-1)) ti))]
% V(t) = V(i-1)+A(m i)*(t-(sum(from i=1 to t(i-1)) ti)) , the temperature at any point of time
% t = (V(i-1)/A(m i))-t(i-1)
Can someone help me please with creating a foor loop that generates 50 safe shedules (alpha), and schedule that does not meet the previous features is considered irrelevnt. To calculate the cost Pi(alpha). Here is my units definition
%------------------------------------------------------------------------%
clear variables;
close all;
clc;
%------------------------------------------------------------------------%%
%% Define units
%---------------------------------------------------------------------------------------------------------------------%
Vmax = 22; % The highest temperature we can reach [°C]
Vmin = 18; % The lowest temperature we can reach [°C]
V0 = 18; % Inetial temperature at time = 0
K = 2; % Number of heaters
Tmax = 7; % Total time [h]
PiC = [10 20]; % Continuous cost [$/h]
PiD = [30 10]; % Discrete cost [$]
A = [4/3 2]; % Heating parameters for mode 1,2 [°C/h]
A0 = -4; % Cooling parameters for mode 0, when the heaters are off [°C/h]
%---------------------------------------------------------------------------------------------------------------------%
  3 commentaires
Hamzah Faraj
Hamzah Faraj le 19 Avr 2020
darova
darova le 19 Avr 2020
Do you have any specific t1 t2 t3...?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by