Professional Documents
Culture Documents
Semester 1 2016
Assignment 2
Group 2
Name
Wong Chiew Wee
Lim Mingjing
Syarifah Nurliza Wan Drahman
Lecturer
Program
Date Due
Date Submitted
Student ID
7E2B1284/16530807
7E2B1207/16529177
7E3B2651/18022940
We hereby declare that this assignment is solely our own work and has not previously been
submitted for assessment. This work complies with Curtin University of Technology rules
concerning plagiarism.
ii) Constants : -Hr1, -Hr2, -E1f, -E1b, -E2, k01f, k01b, k02, R, , CP, Astm, Bstm, Cstm, Mstm, stm
iii) Parameters : Tmin, Tmax, S, a, Ga, BC, KC, a, CV, U, V, A, pstmi
iv) Algebraics : F, CAi, CBi, Ti, TSP, TSP, CA, CB, CC, CD, OC, r1f, r1b, r2, Tt, , Q, Fstm, stm, pstm,
stm, Tstm
9
10
11
12
13
14
15
18
20
21
22
28
29
30
31
32
33
Based on the performed incidence matrix above, it can be seen that the assignment is fine as
there is only one circled variable in each row and column in which the rows represent the
algorithm equations while the columns represent the unknown algorithm variables. Moreover,
the DAE index for this assignment is equals to 1 since this assignment can be solved. Therefore,
it can be deduced that this assignment is not a high index problem and it can be solved by using
the Matlabs DAE solver. As for precaution, if the value of the DAE index is higher than 1, it
is essential to recheck whether the number of variables, constants, parameters, and algebraic
equations are correct or not.
The nodes g(28), g(30), g(31), g(32) and g(33) are a loop and therefore the nodes are merged.
The nodes g(29) and g(28, 30, 31, 32, 33) are a loop and therefore the nodes are merged.
The nodes g(12), g(13), g(14), g(15), g(22) and g(28, 29, 30, 31, 32, 33) have no output. The
nodes are added to the list and deleted from the digraph.
List: g(12), g(13), g(14), g(15), g(22), g(28, 29, 30, 31, 32, 33)
The nodes g(9), g(10), g(11) and g(21) have no output. The nodes are added to the list and
deleted from the digraph.
List: g(12), g(13), g(14), g(15), g(22), g(28, 29, 30, 31, 32, 33), g(9), g(10), g(11), g(21)
The nodes g(18) and g(20) have no output. The nodes are added to the list and deleted from the
digraph.
3
List: g(12), g(13), g(14), g(15), g(22), g(28, 29, 30, 31, 32, 33), g(9), g(10), g(11), g(21), g(18),
g(20)
There are no more nodes and therefore the algorithm is finished.
Based on the performed S-W algorithm, the order of solving the equations is g(20), g(18),
g(21), g(11), g(10), g(9), g(28, 29, 30, 31, 32, 33), g(22), g(15), g(14), g(13), g(12)
Equation(s) Used
20
18
21
11
10
9
28, 29, 30, 31, 32, 33
22
15
14
13
12
Variable(s) Calculated
Tt
TSP
CC
CB
CA
Tstm, Fstm, pstm, stm, stm, Q
OC
r2
r1b
r1f
CD
The equations of 28, 29, 30, 31, 32 and 33 are the only six equations that needed to be solved
simultaneously. Then, the remaining equations are solved accordingly.
9
10
11
12
13
14
15
18
20
21
22
28
29
30
31
32
33
The nodes g(29), g(30), g(31) and g(32) are a loop and therefore the nodes are merged.
The nodes g(28), g(29, 30, 31, 32) and g(33) are a loop and therefore the nodes are merged.
The nodes g(12), g(13), g(14), g(15), g(22) and g(28, 29, 30, 31, 32, 33) have no output. The
nodes are added to the list and deleted from the digraph.
List: g(12), g(13), g(14), g(15), g(22), g(28, 29, 30, 31, 32, 33)
The nodes g(9), g(10), g(11) and g(21) have no output. The nodes are added to the list and
deleted from the digraph.
List: g(12), g(13), g(14), g(15), g(22), g(28, 29, 30, 31, 32, 33), g(9), g(10), g(11), g(21)
The nodes g(18) and g(20) have no output. The nodes are added to the list and deleted from the
digraph.
List: g(12), g(13), g(14), g(15), g(22), g(28, 29, 30, 31, 32, 33), g(9), g(10), g(11), g(21), g(18),
g(20)
There are no more nodes and therefore the algorithm is finished.
Based on the performed SW algorithm, the order of solving the equations is g(20), g(18), g(21),
g(11), g(10), g(9), g(28, 29, 30, 31, 32, 33), g(22), g(15), g(14), g(13), g(12)
Based on the S-W algorithm shown above, it is proven that all the alternative ways to solve
this assignment will result in the same equation ordering solution. Moreover, although there
are six algebraic equations that are needed to be solved simultaneously, there are only six
unknown variables in the six algebraic equations which mean the DOF of the equations is zero.
In other word, the unknown variables are solvable. Therefore, it can be deduced that the
solution steps can be interpreted in terms of coding in Matlab software in order to calculate the
unknown variables. Besides, the equation ordering solution makes sense because the unknown
variables can be solved step by step according to the equation ordering without encountering
any difficulties. The detailed calculation steps of the algebraic equation ordering are shown in
Table 2 below.
Table 2 Detailed Calculation Steps of the Algebraic Equation Ordering
Equations
Algebraic Equations
Variables
20
18
21
11
10
9
Tt
TSP
CC
CB
CA
22
15
14
13
12
Variables
Calculated
Tt
TSP
CC
CB
CA
Tstm, Fstm,
pstm, stm,
stm, Q
OC
r2
r1b
r1f
CD
OC
r2
r1b
r1f
CD
Based on the table above, it can be seen that the values of Tt and Tsp are first calculated in
Equation 20 and Equation 18 respectively. The variables that are already calculated are bold
in the following equations for the ease of interpretation. Following that, is the only unknown
variable in Equation 21 and hence, the value can then be easily calculated. Nevertheless, the
solution is not optimal as there are six equations that are needed to be solved simultaneously.
Furthermore, there is better equation ordering solution for this assignment. The detailed of the
improved ordering solution is discussed as presented below:
1) Since the value of can only be calculated after calculating the Tt and Tsp, the ordering
solution remained unchanged as g(20), g(18) and g(21). After obtaining the value of , the
value of OC can then be calculated. Thus, the ordering solution becomes g(20), g(18), g(21)
and g(22).
2) For g(11), g(10), g(9) and g(12), the values of CC, CB, CA and CD can be calculated entirely.
There is no need to calculate them sequentially as there is the values are independent of each
other.
3) For g(15), g(14) and g(13), the values of r2, r1b and r1f are calculated entirely after obtaining
the values CC, CB, CA. Thus, the equations are located after the g(11), g(10), g(9) and g(12).
4) Lastly, the six simultaneous equations are rearranged as the last equations to be solved as
mistakes often arisen from the substitution process. It is advantageous to locate them as the last
part of the algebraic equations because if there is any wrong substitution or calculation in the
equations, we only have to recheck the last part of the entire algebraic equations. This will
result in less time consuming and high efficiency. Hence, the better equation ordering solution
is g(20), g(18), g(21), g(22), g(11), g(10), g(9), g(12), g(15), g(14), g(13), g(28, 29, 30, 31, 32,
33).
By referring to Tutorial 6, there are four methods that are applicable in Matlab to solve DAE
problem. The first method is substituting all the algebraic equations into the ordinary
differential equations (ODEs) to form a pure ODE system and followed by solving it using the
ODE solver. This often will result in high probability of making mistakes during the
substitution process. The second method is solving the algebraic equations numerically. The
algebraic equations are solved simultaneously and followed by evaluating the derivatives.
Then, solve it using the ODE solver. As for third method, the algebraic equations are rearranged
in order. After that, the derivatives are evaluated and followed by solving it using the ODE
solver. This method allowed the algebraic equations to be solved sequentially. The fourth
method is writing all the algebraic equations in mass matrix DAE form so that it can be solved
using the DAE solver. Among all the methods, the third method is the most optimal method
because it allows easy recognition of error in Matlab coding as the algebraic equations are
typed out individually. Besides, this method also lowers the possibility of making mistakes as
the algebraic equations are not required to be substituted into the ODEs. However, an additional
work is needed to prepare the algebraic model equations for solutions. The model variables
have to be first classified into states, constants, parameters and algebraics, and followed by
identifying the values for constants and parameters. Sequentially, DOF analysis, incidence
matrix and S-W algorithm have to be performed in order to identify the solution order. Lastly,
the algebraic equations are rearranged according to the solution in order to solve it sequentially
as there is impossible to solve all the algebraic equations entirely.
ii) Constants
: , , H1, H2, L
iii) Parameters
v) Specified Algebraics
: WLi, WLo, BLi, BLo, Li, Lo, xBLi, xBLo, xWLo, MT, QLo,
VT, Li, Lo, Vbot, Vtop, h, ht, hsp, , Oc
WLi
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20
21
22
23
26
WLo
BLi
X
BLo
Li
Lo
X
X
Lo
xBLi
xBLo
xWLo
MT
QLo
VT
Vbot
Vtop
X
X
ht
hsp
Oc
X
X
X
X
Li
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
10
Sargent-Westerberg Algorithm
The initial digraph is constructed:
The nodes g(4), g(5) and g(6) are a loop and therefore the nodes are merged.
The nodes g(7), g(8), g(9), g(18) and g(23) have no output. The nodes are added to the list and
deleted from the digraph.
List: g(7), g(8), g(9), g(18), g(23)
The merged node g(4, 5, 6), nodes g(12), g(13), g(17) and g(22) have no output. The nodes are
added to the list and deleted from the digraph.
List: g(7), g(8), g(9), g(18), g(23), g(4, 5, 6), g(12), g(13), g(17), g(22)
11
The nodes g(3), g(15), g(16), g(20), g(21) and g(26) have no output. The nodes are added to the
list and deleted from the digraph.
List: g(7), g(8), g(9), g(18), g(23), g(4, 5, 6), g(12), g(13), g(17), g(22), g(3), g(15), g(16), g(20),
g(21), g(26)
The node g(10) has no output. The node is added to the list and deleted from the digraph.
List: g(7), g(8), g(9), g(18), g(23), g(4, 5, 6), g(12), g(13), g(17), g(22), g(3), g(15), g(16), g(20),
g(21), g(26), g(10)
The node g(11) has no output. The node is added to the list and deleted from the digraph.
List: g(7), g(8), g(9), g(18), g(23), g(4, 5, 6), g(12), g(13), g(17), g(22), g(3), g(15), g(16), g(20),
g(21), g(26), g(10), g(11)
The node g(14) has no output. The node is added to the list and deleted from the digraph.
List: g(7), g(8), g(9), g(18), g(23), g(4, 5, 6), g(12), g(13), g(17), g(22), g(3), g(15), g(16), g(20),
g(21), g(26), g(10), g(11), g(14)
There are no more nodes and therefore the algorithm is finished.
12
Based on the performed S-W algorithm, the order of solving the equations is g(14), g(11), g(10),
g(26), g(21), g(20), g(16), g(15), g(3), g(22), g(17), g(13), g(12), g(4, 5, 6), g(23), g(18), g(9), g(8),
g(7)
a) Printout of m-files
Based on the Sargent-Westerberg algorithm performed, the sequence of the equations can be
developed. Hence, the DAE model system can be solved by using method 3. For this case, the
model seems to be a non-stiff system as the execution time is in matter of seconds, thus ode45
solver is suitable to solve the model. Three Matlab script m-file were developed to solve the model,
which named as bogctrl.m, bogfunc.m and bogsim.m respectively. After running the simulation
file (bogsim.m), the data is printed out which as shown as below.
13
% Inlet liquor conditions remain fixed for the duration of the simulation
QLi = 0.0565;
CBLi = 43;
% Introduce step change in level set-point at t = 5 minutes
if t < 300
hSP = 2.5;
else
hSP = 2.2;
end
% Introduce step change in solids stream feed rate at t = 20 minutes
if t < 1200
mdotBSi = 21.5;
else
mdotBSi = 21.5*0.7;
end
14
%
%
%
%
Equation
Equation
Equation
Equation
23
18
9
8
15
% Equation 7
% Evaluate derivatives
dMWdt = mdotWLi-mdotWLo;
dMBdt = mdotBLi+mdotBSi-mdotBLo;
dhsdt = (h-hs)/taus;
dwdt = ((Ga*Oc-S)/taua^2)-2*(xia/taua)*w;
dSdt = w;
%
%
%
%
%
Equation
Equation
Equation
Equation
Equation
1
2
19
24
25
16
% Model parameters
CV = 0.256;
% Outlet valve coefficient ((m^3/s)/(kPa/(kg/m^3))^0.5)
deltaP = 300;
% Pressure drop over control valve (kPa)
Bc = 0.5;
% Controller bias (-);
Kc = -5;
% Controller gain (-)
taus = 10;
% Level sensor time constant (s)
Ga = 1;
% Actuator gain (-)
taua = 20;
% Actuator time constant (s)
xia = 0.8;
% Actuator damping factor (-)
% Simulation time
tf = 2400;
% Final simulation time (s)
% Specify initial
MW0 = 16750;
%
MB0 = 7150;
%
hs0 = 2.5;
%
w0 = 0;
%
S0 = 0.5;
%
conditions
Initial mass of water in tank (kg)
Initial mass of boganite in tank (kg)
Initial level sensor reading (m)
Initial scaled valve stem velocity (1/s)
Initial dimensionless valve position (-)
17
Vbot = (1/2)*(H1-H2)*L^2;
Vtop = VT-Vbot;
h = H1-H2+(Vtop/L^2);
% Print out the maximum and minimum values
fprintf('\nThe maximum value:\n');
fprintf(' MW = %.2f kg\n MB = %.2f kg\n hs = %.2f m\n w = %.4f\n S =
%.4f\n',max(MW),max(MB),max(hs),max(w),max(S));
fprintf(' MT = %.2f kg\n xBLo = %.6f\n xWLo = %.6f\n h = %.2f
m\n',max(MT),max(xBLo),max(xWLo),max(h));
fprintf('\nThe minimum value:\n');
fprintf(' MW = %.2f kg\n MB = %.2f kg\n hs = %.2f m\n w = %.4f\n S =
%.4f\n',min(MW),min(MB),min(hs),min(w),min(S));
fprintf(' MT = %.2f kg\n xBLo = %.6f\n xWLo = %.6f\n h = %.2f
m\n',min(MT),min(xBLo),min(xWLo),min(h));
% Display the results and the maximum & minimum values in graph
% Figure 1
figure (1)
plot(t,MW);
title(['Solubilisation tank simulation: Mass of water (kg) vs Time
(min)\newline ']);
xlabel('Time (min)');
ylabel('MW (kg)');
legend('MW (kg)');
grid on;
indexmin = find(min(MW) == MW);
tmin = t(indexmin);
MWmin = MW(indexmin);
indexmax = find(max(MW) == MW);
tmax = t(indexmax);
MWmax = MW(indexmax);
strmin = ['Minimum = ',num2str(MWmin)];
text(tmin,MWmin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(MWmax)];
text(tmax,MWmax,strmax,'HorizontalAlignment','left');
% Figure 2
figure (2)
plot(t,MB)
title(['Solubilisation tank simulation: Mass of boganite (kg) vs Time
(min)\newline '])
xlabel('Time (min)');
ylabel('MB (kg)');
legend('MB (kg)');
grid on;
indexmin = find(min(MB) == MB);
tmin = t(indexmin);
MBmin = MB(indexmin);
indexmax = find(max(MB) == MB);
tmax = t(indexmax);
MBmax = MB(indexmax);
strmin = ['Minimum = ',num2str(MBmin)];
text(tmin,MBmin,strmin,'HorizontalAlignment','right');
strmax = ['Maximum = ',num2str(MBmax)];
text(tmax,MBmax,strmax,'HorizontalAlignment','left');
18
% Figure 3
figure (3)
plot(t,hs);
title(['Solubilisation tank simulation: hs (m) vs Time (min)\newline ']);
xlabel('Time (min)');
ylabel('hs (m)');
legend('hs (m)');
grid on;
indexmin = find(min(hs) == hs);
tmin = t(indexmin);
hsmin = hs(indexmin);
indexmax = find(max(hs) == hs);
tmax = t(indexmax);
hsmax = hs(indexmax);
strmin = ['Minimum = ',num2str(hsmin)];
text(tmin,hsmin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(hsmax)];
text(tmax,hsmax,strmax,'HorizontalAlignment','left');
% Figure 4
figure (4)
plot(t,w);
title(['Solubilisation tank simulation: w (1/s) vs Time (min)\newline ']);
xlabel('Time (min)');
ylabel('w (1/s)');
legend('w (1/s)');
grid on;
indexmin = find(min(w) == w);
tmin = t(indexmin);
wmin = w(indexmin);
indexmax = find(max(w) == w);
tmax = t(indexmax);
wmax = w(indexmax);
strmin = ['Minimum = ',num2str(wmin)];
text(tmin,wmin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(wmax)];
text(tmax,wmax,strmax,'HorizontalAlignment','left');
% Figure 5
figure (5)
plot(t,S);
title(['Solubilisation tank simulation: S vs Time (min)\newline ']);
xlabel('Time (min)');
ylabel('S');
legend('S');
grid on;
indexmin = find(min(S) == S);
tmin = t(indexmin);
Smin = S(indexmin);
indexmax = find(max(S) == S);
tmax = t(indexmax);
Smax = S(indexmax);
strmin = ['Minimum = ',num2str(Smin)];
text(tmin,Smin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(Smax)];
text(tmax,Smax,strmax,'HorizontalAlignment','left');
19
% Figure 6
figure (6)
plot(t,MT);
title(['Solubilisation tank simulation: Total mass (kg) vs Time (min)\newline
']);
xlabel('Time (min)');
ylabel('MT (kg)');
legend('MT (kg)');
grid on;
indexmin = find(min(MT) == MT);
tmin = t(indexmin);
MTmin = MT(indexmin);
indexmax = find(max(MT) == MT);
tmax = t(indexmax);
MTmax = MT(indexmax);
strmin = ['Minimum = ',num2str(MTmin)];
text(tmin,MTmin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(MTmax)];
text(tmax,MTmax,strmax,'HorizontalAlignment','left');
% Figure 7
figure (7)
plot(t,xBLo,t,xWLo);
title(['Solubilisation tank simulation: xBLo & xWLo vs Time (min)\newline
']);
xlabel('Time (min)');
ylabel('xLo');
legend('xBLo','xWLo');
grid on;
indexmin = find(min(xBLo) == xBLo);
tmin = t(indexmin);
xBLomin = xBLo(indexmin);
indexmax = find(max(xBLo) == xBLo);
tmax = t(indexmax);
xBLomax = xBLo(indexmax);
strmin = ['Minimum = ',num2str(xBLomin)];
text(tmin,xBLomin,strmin,'HorizontalAlignment','right');
strmax = ['Maximum = ',num2str(xBLomax)];
text(tmax,xBLomax,strmax,'HorizontalAlignment','left');
indexmin = find(min(xWLo) == xWLo);
tmin = t(indexmin);
xWLomin = xWLo(indexmin);
indexmax = find(max(xWLo) == xWLo);
tmax = t(indexmax);
xWLomax = xWLo(indexmax);
strmin = ['Minimum = ',num2str(xWLomin)];
text(tmin,xWLomin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(xWLomax)];
text(tmax,xWLomax,strmax,'HorizontalAlignment','right');
% Figure 8
figure (8)
plot(t,h);
title(['Solubilisation tank simulation: h (m) vs Time (min)\newline ']);
xlabel('Time (min)');
ylabel('h (m)');
legend('h (m)');
20
grid on;
indexmin = find(min(h) == h);
tmin = t(indexmin);
hmin = h(indexmin);
indexmax = find(max(h) == h);
tmax = t(indexmax);
hmax = h(indexmax);
strmin = ['Minimum = ',num2str(hmin)];
text(tmin,hmin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(hmax)];
text(tmax,hmax,strmax,'HorizontalAlignment','left');
21
b) Matlab plots
By running the script m-file, the DAE model system can be solved and the solutions are plotted as
shown below. There are total of eight graphs will be plotted, which are the mass of water in tank
(MW), mass of boganite in tank (MB), total mass in tank (MT), mass fraction of the species in tank
(xBLo and xWLo), actual tank level (h), sensed tank level (hs), outlet control valve position (S), and
scaled valve stem velocity (w) over a period of 40 minutes.
Figure 4 Mass Fractions of Boganite Liquid Outlet and Water Outlet against Time (min)
23
24
25
c) Verification Practices
1) First Verification Practice Error Checking for Programming Mistakes
The Matlab code was evaluated through the line by line inspection method in order to check for
programming mistakes that may have occurred. Programming mistakes occur when the equations
entered in Matlab are incorrect. While this error may not be detected by the program, a slight
difference in the equations would affect the whole result. In this method, the codes would be
checked line by line by each member of the group in order to detect any mistake that may have
been overlooked. The equations entered in the code were compared with the given equations in
the assignment sheet.
The algebraic equations were entered according to the equations ordering solution which is g(14),
g(11), g(10), g(26), g(21), g(20), g(16), g(15), g(3), g(22), g(17), g(13), g(12), g(4, 5, 6), g(23),
g(18), g(9), g(8), g(7) as shown below.
MT = MW+MB;
xBLo = MB/MT;
rhoLo = alpha+beta*xBLo;
QLo = CV*S*(deltaP/rhoLo)^(0.5);
hSPprime = hSP/H1;
htprime = hs/H1;
Vbot = 0.5*(H1-H2)*L^2;
VT = MT/rhoLo;
mdotBLi = QLi*CBLi;
err = hSPprime-htprime;
Vtop = VT-Vbot;
mdotLo = rhoLo*QLo;
xWLo = 1-xBLo;
%
%
%
%
%
%
%
%
%
%
%
%
%
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
14
11
10
26
21
20
16
15
3
22
17
13
12
%
%
%
%
%
Equation
Equation
Equation
Equation
Equation
23
18
9
8
7
26
%
%
%
%
%
Equation
Equation
Equation
Equation
Equation
1
2
19
24
25
Equation 2
Equation 3
BLi = QLi.CBLi
Equation 4
Li.QLi = Li
Equation 5
Li = + .xBLi
Equation 6
xBLi = BLi / Li
Equation 7
Li = WLi + BLi
Equation 8
WLo = xWLo.Lo
Equation 9
BLo = xBLo.Lo
Equation 10
Lo = + .xBLo
Equation 11
xBLo = MB / MT
Equation 12
xWLo = 1 xBLo
Equation 13
Lo = Lo.QLo
Equation 14
MT = M W + MB
Equation 15
VT = MT / Lo
Equation 16
Equation 17
Vtop = VT Vbot
Equation 18
h = H1 H2 + Vtop / L2
Equation 19
dhs/dt = (h hs) / s
Equation 20
ht = hs / H1
Equation 21
hSP = hSP / H1
Equation 22
= hSP ht
27
Equation 23
Oc = Bc + Kc.
Equation 24
Equation 25
dS/dt = w
Equation 26
Furthermore, the Matlab script is checked for array operations. Array variables were identified for
the solution calculated from the solver as they are packed with a set of data. Hence, array operator
are required in order to define the equation correctly. An example is taken from the Matlab
simulation file (bogsim.m) as shown as below. Since MB and MW are both in array form, an array
operator (. /) should be used.
xBLo = MB/(MW+MB);
xBLo = MB./(MW+MB);
From these, it can be seen that the equations that were entered in the code are correct. Hence, the
model developed in Matlab is verified.
28
2) Second Verification Practice Execution Time and Number of Steps Taken of Other Ode
Solver
The behavior of the system is being inspected to determine whether the system is a non-stiff or
stiff model. The inspection is performed by recording the execution time and the number of time
steps taken for the Matlab to complete the calculation. The model is tested by using two ODE
solver available in Matlab, which are ode45 that suitable for non-stiff system, and ode15s that
suitable for stiff system. Additional Matlab script is written into the script m-file to perform the
inspection. The Matlab script added is written as shown as below.
% Solve the model
tic
After the calculation, additional Matlab script is written as shown as below to display the results.
% Report the solver performance results
disp(' ')
disp(['Number of time steps taken : ' num2str(nsteps)])
disp(['Execution time
: ' num2str(exectime) ' seconds'])
disp(' ')
In order to improve the data computed from the Matlab, 3 runs on the simulation are performed.
The execution time is averaged and compared between the ode45 and ode15s solver. The results
of the inspection are shown in Table 4.
Table 4 Comparison between ODE Solvers
ODE solver
Simulation run
Execution time (s)
Average execution time
(s)
Number of time steps
taken
st
1 run
0.26172
ode45
2nd run
0.25610
rd
st
3 run
1 run
0.27135 0.36726
ode15s
2nd run
0.38596
0.26306
0.38455
289
163
3rd run
0.40042
As shown in Table 4, the execution time for the case of using ode45 solver is much faster.
However, by observing the time taken, the model for both of the cases are able to be solved in
matter of deciseconds. Despite that, the number of time steps taken for the calculation by using
ode45 solver is larger, which should compute a more accurate result. Therefore, ode45 is a more
suitable ODE solver for this model.
29
Hence, for the three additional cases, the tolerances are set to be 10-4, 10-5, and 10-6 respectively.
Then, the comparisons are done by using the final values for the model objectives, which occurs
at 40 minutes. The results for the checking of the tolerance is shown in Table 5 below.
Table 5 Comparison among Different Tolerances Inserted
Tolerance
MW (kg)
MB (kg)
hs (m)
w
S
MT (kg)
xBLo
xWLo
h (kg)
10-3
14570.30
4512.76
2.18
0.0000
0.4711
19083.06
0.236480
0.763520
2.18
10-4
14570.27
4512.87
2.18
0.0000
0.4711
19083.14
0.236485
0.763515
2.18
10-5
14570.29
4512.78
2.18
0.0000
0.4711
19083.07
0.236481
0.763519
2.18
10-6
14570.29
4512.80
2.18
0.0000
0.4711
19083.08
0.236481
0.763519
2.18
From the checking result as shown in Table 5 above, it is apparently that the errors among the
cases with different tolerance are very insignificant. Hence, the default tolerance (10-3) is sufficient
to have an accurate result.
30
Equations given:
dMB
= mBLi + mBSi mBLo
dt
Equation (2)
Equation (3)
Equation (9)
Lo = + xBLo
Equation (10)
QLo
P 1/2
= CV S ( )
Lo
mLo = Lo QLo
Equation (26)
Equation (13)
P 1/2
= Lo CV S ( )
Lo
Since at the initial and final condition, there are no changes on the level set point and influent
composition, the system should be in steady state, where dMB/dt equals to zero.
mBLi + mBSi mBLo = 0
31
QLi = 0.0565 m3 /s
P = 300kPa
CBLi = 43kg/m3
= 1000kg/m3
= 1100kg/m3
xBLo = 0.5253
xBLo = 0.2964
xBLo > 0
xBLo = 0.2964
xBLo = 0.3063
xBLo = 0.2234
32
xBLo > 0
xBLo = 0.2234
Manual Calculation
0.2964
0.2234
Matlab Result
0.2992
0.2365
Percentage error
0.94%
5.86%
A comparison is made between the manual calculation and Matlab result for x BLo as shown in
Table 6 above. As calculated, the percentage error at the initial condition and final condition,
is very small. Hence, the model developed in Matlab is verified.
33
34
35
37
38
39
ASSIGNMENT 2 RESPONSIBILITIES
Lim Mingjing
Syarifah Nurliza
Wan Drahman
O D R F
+
+
Person
Problem 1
Part (a) Variable classification
Part (b) DOF & specification
Part (c) Incidence &
assignment
Part (d) Sargent-Westerberg
Part (e) Outcome of S-W
Part (f) S-W practicalities
Problem 2
Part (a) Matlab coding, printout
Part (b) Matlab plots
Part (c) Solution verification
O
*
*
D
*
*
R
*
*
F
*
*
*
*
*
O
*
*
*
*
*
D
*
*
*
*
*
R
*
*
*
*
*
*
F
*
*
*
*
+
O
+
+
+
D
+
+
+
R
+
+
+
F
+
+
+
O
+
40