% tanks_series.mdl
% class example with two tanks in series
% pulse external input flow into tank 1 

clc, close all, clear all

A1=4; % area of tank 1, (sq ft)
L1=20; % height of tank 1, (ft)
c1=2; % discharge coefficient for tank 1 flow out, (cu ft/min per ft^1/2)
H1_init=0; % initial level in tank 1, (ft)
t0=0; % time on for external flow into tank 1, (min)
t1=20; % time off for external flow into tank 1, (min)
A=10;  % amplitude of external flow into tank 1  (cu ft/min)
A=15; % amplitude of external flow into tank 1  (cu ft/min)
tfinal=50; % simulation final time,  (min)
sim('tanks') % calls simulation of tanks in series with pulse flow input to tank 1
t=t_H1(:,1); % extracts 1st column of array t_H1
H1=t_H1(:,2); % extracts 2nd column of array t_H1
f11=t_f11(:,2); % extracts 2nd column of array t_f11
f01=t_f01(:,2); % extracts 2nd column of array t_f01
plot(t,f11,t,f01,'k',t,H1,'r')
max_f11=max(f11);
max_f01=max(f01);
max_f=max(max_f11,max_f01);
max_f_L1=max(max_f,L1);
axis([0 tfinal -1 1.05*max_f_L1])
xlabel('t (min)')
ylabel('f_{1,1},  f_{0,1},  H_{1}')
title('External Flow In, Flow Out and Level of Tank 1 vs Time')
legend('f_{1,1}','f_{0,1}','H_{1}','Location','east')
hold 
plot([0 tfinal],[L1 L1],'k')
text(tfinal-15,L1-1,'L_{1} = 20 ft')





