-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulateDeterministic.m
43 lines (36 loc) · 1.16 KB
/
simulateDeterministic.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [T, H, Qout] = simulateDeterministic(F, p)
% input F [cm3/s] Flow rate from pump i
t0 = 0.0; % [s] Initial time
tf = 20*60; % [s] Final time
m10 = 0.0; % [g] Liquid mass in tank 1 at time t0
m20 = 0.0; % [g] Liquid mass in tank 2 at time t0
m30 = 0.0; % [g] Liquid mass in tank 3 at time t0
m40 = 0.0; % [g] Liquid mass in tank 4 at time t0
x0 = [m10; m20; m30; m40];
u = [F(1); F(2)];
% --------------------------------------------------------------
d = [F(3); F(4)];
% --------------------------------------------------------------
% Compute the solution / Simulate
% --------------------------------------------------------------
% Solve the system of differential equations
[T,X] = ode45(@ModifiedFourTankSystem,[t0 tf],x0,[], u,d,p);
% --------------------------------------------------------------
% help variables
[nT,nX] = size(X);
a = p(1:4,1)';
A = p(5:8,1)';
rho = p(12);
g = p(11);
% Compute the measured variables
H = zeros(nT,nX);
for i=1:nT
H(i,:) = X(i,:)./(rho*A);
end
% Compute the flows out of each tank
Qout = zeros(nT,nX);
for i=1:nT
Qout(i,:) = a.*sqrt(2*g*H(i,:));
end
% --------------------------------------------------------------
end