Process Simulation using MATLAB

advertisement
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
9
9
h1
8
h2
8
7
7
6
6
0
10
20
30
40
50
60
70
80
90
5
100
0
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
h
h1
2
h2
16
1
h
9
height
height
8
14
12
7
6
10
5
8
6
4
0
20
40
60
80
100
time
120
140
160
180
200
3
0
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)
M
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
Download