elseif statement wont execute
Show older comments
The code is to determine outflow from a tank with variable input (hydrograph). The method is usually called chainsaw routing. There are two outlets in the tank, one at 0 elevation, the other at 2 ft. Outlets have different sizes. Naturally I used if and elseif statements to calculate outflow from the two orifices, as the top one does not engage until at least 2 feet of head is reached. However, the elseif statement is not executing; it appears everything just gets calculated from the if statement. One might think that 2 feet of head is never reached, but plot(x,h) shows that head gets to be nearly 8 ft. I am relatively new to coding, and cannot see whats wrong. Please help me find the error
Z = load('routing data.txt') ;
x = Z(:,1) ;
I = Z(:,2) ;
r1 = 1.75;
r2 = 2.25;
Aclarifier= 1800;
Aoutlet1 = pi*(r1/12)^2;
Aoutlet2 = pi*(r2/12)^2;
for i = 2:length(x)
h(1) = 0;
O(1) = 0;
dh(1) = 0;
I(1) = 0;
O1(1) = 0;
O2(1) = 0;
dh(i) = (I(i-1)*60*2)/Aclarifier - (O(i-1)*60*2)/Aclarifier;
h(i) = dh(i-1)+h(i-1);
if ( 0 < (h(i)) <= 2)
O(i) = (.6)*Aoutlet1*sqrt(64.4*h(i)) ;
elseif (h(i) > 2)
O2(i) = (.6)*(Aoutlet2)*sqrt(64.4*(h(i)-2));
O1(i) = (.6)*(Aoutlet1)*sqrt(64.4*h(i));
O(i) = O1(i)+O2(i);
else
O(i) = 0 ;
dh(i) = 0;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on GNC and Avionics 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!