Process Simulation using
MATLAB
Most chemical process models are nonlinear and
rarely have analytical solutions. However, numerical
solutions ca be easily obtained using MATLAB
Simulation of Nonlinear Models
Example: Two interacting tank in series with outlet flowrate
being function of the square root of tank height.
F
F2
F1
F1 = R1 h1 - h2
F2 = R2 h2
Parameter values
ft 2.5
R1 = 2.5
min
5 ft 2.5
R2 =
6 min
Input variable F = 5 ft3/min
A1 = 5ft 2
A2 = 10 ft 2
Modeling equations : material balance
d ( r A1h1 )
= r F - r F1
dt
d ( r A2 h2 )
= r F1 - r F2
dt
dh1 F - R1 h - h
2
f (h , h , F )
dt A1 A1 1
= 1 1 2
f
h
h
F
,
,
dh
R
R
(
)
2
1
2
2 1 2
h
h
h
1
2
2
dt A2
A2
Steady-state height values : solve algebraic equations
F R1
A1 A1
R1
A2
h1 - h2 = 0
h1 - h2 -
R2
A2
h2 = 0
Using MATLAB fsolve routine
h1s = 10, h2s = 6
Question
What are the responses of tank height if the initial heights are
h1(0)=12 ft and h2(0)=7 ft ?
Assume the system is at steady-state initially. What are the
responses of tank height if
F changes from 5 to 7 ft3/min at t = 0
F has periodic oscillation of F = 5 + sin(0.2t)
F changes from 5 to 4 ft3/min at t = 20
Solve differential equations using MATLAB ode45 routine or
Simulink dee
h1(0)=12 ft and h2(0)=7 ft
12
F = 5 + sin(0.2t)
12
h1
h2
11
11
10
height
height
10
h1
h2
8
7
7
10
20
30
40
50
60
70
80
90
100
50
100
time
150
time
F changes from 5 to 7 ft3/min at t = 0
F changes from 5 to 4 ft3/min at t = 20
20
11
18
10
h1
h2
16
height
height
8
14
12
7
6
10
20
40
60
80
100
time
120
140
160
180
200
20
40
60
80
time
100
120
140 150
Linear State-Space Model
General dynamic models consist of a set of ODEs
x& = f ( x, u )
A linear model is a subset of the general modeling equation.
The form of linear model is called as a state-space model.
x& = A x + Bu
x : state vector (its elements are referred to as state variables)
u : input vector of manipulated variables
Matrices A and B are constant matrices
Example: Consider two tanks in series where the flow out of the
first tank enters the second tank. Assume the flow out of each
tank is a linear function of the tank height
F
F1 = R1 h1
Objective: develop a model to
describe how h2 change with
time, given the input flowrate F
F1
F2 = R2 h2
F2
Material balance
dh1 F R1
=
- h1
dt
A1 A1
dh2 R1
R
=
h1 - 2 h2
dt
A2
A2
Write the modeling equations in matrix form
R1
&
A1
h1
=
&
h2 R1
A
2
0
1
h
1 + A1 F
R2 h2
-
0
A2
x& = A x + B u
Additional equation associated with a state-space model
y = C x + Du
y : vector of output variables
Output variables are typically a subset of x. They are variables
that can be measured or are of particular interest in a
simulation study
Ex: Both tank height are outputs
1 0 h1
y=
= Cx
0 1 h2
( D = 0)
General form of State-Space Model
General form
dx1
= a11 x1 + a12 x2 + L + a1n xn + b11u1 + L + b1m u m
dt
M
M
dxn
= an1 x1 + an 2 x2 + L + ann xn + bn1u1 + L + bnm um
dt
y1 = c11 x1 + c12 x2 + L + c1n xn + d11u1 + L + d1m u m
M
n state variables (x)
m input variables (u)
r output variables (y)
yr = cr1 x1 + cr 2 x2 + L + crn xn + d r1u1 + L + d rm um
Matrix form
x&1 a11 a12
M = M
M
x&n an1 an 2
y1 c11 c12
M = M
M
yr cr1 cr 2
L a1n x1 b11 b12
O M M + M
M
L ann xn bn1 bn 2
L c1n x1 d11 d12
O M M + M
M
L crn xn d r1 d r 2
L b1m u1
O M M
L bnm um
L d1m u1
O M M
L d rm um
x& = A x + Bu
y = Cx + Du
Simulation of State-Space Models
ODE(ode45)MATLAB
Step 1: sys = ss(A, B, C, D)
Step 2: (the following functions assume a deviation variable form)
[y,t,x] = initial(sys,x0)
sys ()
x0
[y,t,x] = step(sys)
sys
[y,t,x] = impulse(sys)
sys
dimension of y : T x r x m
T = length of t
r = number of outputs
m = number of inputs
[y,t,x] = lsim(sys,u,t,x0)
sys t u
x0
Simulation Using Simulink
Simulation of state-space models using Simulink
(assume a deviation variable form)
State-Space
(Continuous)
A, B, C, D
Mux ()
Demux () (Signal Routing)
Mux:
Demux:
Exercise
State-space model, zero initial condition
x&1 -0.5 -0.8 x1 1 -1 u1
+
x& = 0.8
u
x
0
0
2
2
2
2
y1 2 6 x1
y = 1 -1 x
2
2
Find the responses for
unit step input of u1
unit step input of u2
u1 = sin(t)
Using
MATLAB functions
Simulink