How should I make this for loop

1 view (last 30 days)
Yuxing Zhang
Yuxing Zhang on 21 May 2019
Commented: Yuxing Zhang on 22 May 2019
I have a dam problem which asks the dam reservior is a cylinder withinflow Q (in Q_data.mat), turbine flow rate (Q_turbine) is always 60 m^3/s in operation, initial volume of water is 4x10^8 m^3.
If water level in reservior is higher than 30 m, then all excess inflow is discharged over a spillway. (Q_spill)
If reservoir water depth drops below 17 m, water level drops below the penstock entrance and the turbines cannot be operated.
And Q_outflow is equal to Q_turbine + Q_spill.
Given V(i)=V(i-1)+(Q_in(i) -Q_out (i))*dt
But my curve get wrong that volume of water goes to negative, can anyone tell me what's wrong? It should be an up and down cycle plot
Thank you very much for helpping!
data_file = 'Q_data.mat';
%reservoir operating properties
V0 =4*10^8; %initial reservoir volume [m^3]
D_res =5000; %reservoir diameter [m]
H_max = 30; %maximum water depth in reservoir [m]
H_min = 17; %minimum water depth in reservoir [m]
%water and air properties
rho =1000; %density [kg/m^3]
g =9.81; %gravity [m/s^2]
p_atm = 101.3; %kPa
Q_discharge = 60; %discharge through turbines [m3/s]
%% Load data
load(data_file)
dt =15*60; % seconds*
A_res = pi*D_res^2/4; %calculate reservoir area, in m2
%initialize return values
V_res = zeros(size(t)); %reservoir volume
H_res = zeros(size(t)); %reservoir water depth
Q_out = zeros(size(t)); %total outflow
Q_turbine = zeros(size(t)); %flow through turbines
Q_spill = zeros(size(t)); %flow over spillway
x=zeros(size(t));
%initial conditions
V_res(1) = V0;
H_res(1) = V_res(1)/A_res;
Q_in=Q;
%for each time step - calculate Q_turbine, Q_spillway, H_res, V_res
for i = 2:length(t)
Q_turbine(i)=Q_discharge;
Q_out(i)=Q_turbine(i)+Q_spill(i);
V_res(i)=V_res(i-1)+(Q_in(i)-Q_out(i))*dt;
H_res(i) = V_res(i)/A_res;
if H_res(i)<H_min;
Q_turbine(i)=0;
end
if H_res(i)>H_max
Q_spill(i)= Q(i)-Q_turbine(i);
end
end
plot(t,V_res,'-')
  2 Comments
dpb
dpb on 22 May 2019
Didn't spend a lot of time, but you calculate a turbine flow regardless of height first; need to check the level is between H_min and H_spill first before calculate either actual flow...
Yuxing Zhang
Yuxing Zhang on 22 May 2019
Thany you, I find my issue and get the answer

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!