Process Control-Lecture 09
Process Control-Lecture 09
CE 560 / MT 580
Process control
Lecture 10
Controller tuning
C. Botha (Mr.)
Contacts: Chemical Engineering Department
Email: [email protected]
Alt. Email: [email protected]
January, 2023
Solution of ordinary differential equations in MATLAB
o 𝑓 ′ (𝑥𝑖 , 𝑦𝑖 ) is the suitable slope over the interval 𝑥𝑖 to 𝑥𝑖+1 used for extrapolating
𝑦𝑖+1 from 𝑦𝑖 .
o Number of points used in the interval [𝑥𝑖 , 𝑥𝑖+1 ] to determine the slope determines
the order of the Runge-Kutta method.
Solution of ordinary differential equations in MATLAB
o Thus, second-order Runge-Kutta methods uses two points to estimate the gradient.
o Fifth-order uses five points to estimate the slope.
o The more points are used to estimate the slope, the better the solution accuracy.
o Ode45 is based on fifth-order Runge-Kutta method.
o Ode23 is based on second- and third-order Runge-Kutta methods.
o E.g., the classical third-order Runge-Kutta method is
1
yi 1 yi h(k1 4k2 k3 ) ...........................................(9.0)
6
o Where
h 1
k1 f ( xi , yi ), k2 f ( xi , , yi k1h) and k3 f ( xi , h, yi k1h 2k 2h)....(9.0)
2 2
Solution of ordinary differential equations in MATLAB
o Stiff differential equations contain terms that vary at considerably different rates.
E.g., solution containing the terms 𝑒 −𝑎𝑡 and 𝑒 −𝑏𝑡 with 𝑎 much larger that 𝑏.
Then the first term decays to zero much faster than the second term.
Some numerical methods such as ode45 in this case becomes unstable, and
require an unreasonably small time step for the method to be stable.
Using ode45
o Can be used for both first-order and higher-order differential equations.
o Higher-order differential equations requires transformation to a system of first-order
ODEs.
o Done using state variables and resulting equations are state-variable equations.
Solution of ordinary differential equations in MATLAB
o Number of state variables is the same as the number of initial conditions required or
specified.
o Hence, state variables are selected as those variables for which the initial conditions
are required.
o In example above, three initial conditions are specified, thus there must be three state
variables.
o Let these variables be u1 y, u2 y, and u3 y.................................(9.3)
Solution of ordinary differential equations in MATLAB
3 3
o The equation can also be written in vector matrix form
u1 y
u f ( x, u ), u u2 y .....................................(9.7)
u y
3
Solution of ordinary differential equations in MATLAB
o And
u2 0 u1 (0)
f u3 and u 0 1
2 ..............................(9.8)
u (0)
1 1 u (0)
[u3 5u2 3u1 e ]
x /2 3
3
o Where 𝑢0 is a matrix vector containing initial conditions, since 𝑢1 0 = 𝑦 0 = 0,
𝑢2 0 = 𝑦 ′ (0) = 0 and 𝑢3 0 = 𝑦 ′′ (0) = 1
Using ode45 or other ODE solvers to solve above equation.
o MATLAB code for the ODE(s) can be written using a script file or
o Function file and a script file to run the code in the function file.
o Either way creates a .mfile, alternately code can be executed in command window.
o Inline method may be used in either case.
Solution of ordinary differential equations in MATLAB
o For inline method, the MATLAB code for Eq. 9.8 is as below
o First line specifies the initial conditions and must include all initial conditions for the
state variables.
o The second line specifies the time span over which the differential equations must
be solved (integrated).
o The third line is the function definition, f is a function handle.
o The procedure for defining a function in MATLAB using inline method is as follows:
Solution of ordinary differential equations in MATLAB
o Ode45 requires the three inputs in this case: the function, time span and the initial
conditions.
o Time span is the provides the evaluation points for the numerical method.
o The time step size is defined by the time interval used.
o The ode45 returns t as a column matrix (n x 1).
o 𝑦 is the numerical solution array returned as a column vector for each state variable.
o Thus, if there are 𝑚 state variables, then the solution array is an 𝑛 × 𝑚 array.
o Each row in 𝑦 is a solution at a corresponding row in 𝑡.
Solution of ordinary differential equations in MATLAB
o The complete code in Fig. 9.2 can be typed in the command window to execute it.
o It can also be created as a .mfile.
o Done by using “new – scrip” below the home tab.
Effect of integral time on response
Example
o Consider the system of differential equations for the stirred tank heater
dx 1 1 y dy K
(Ti Ti ,s ) x and C x...................(9.17)
dt Vc p dt I
o Where
x T Ts , Ts - T , x and y Q Qs ..............(9.18)
1 1 1 KC
a (Ti Ti ,s ), b , c and d ............(9.22)
Vc p I
du1 du2
a bu1 cu2 and du1.........................(9.23)
dt dt
(a) (b)
Fig. 9.4 Response of STH temperature (a) no control and (b) Integral control
Effect of integral time on response
du3 du4
a bu3 cu4 and d 2u3 .........................(9.26)
dt dt
du5 du6
a bu5 cu6 and d3u5 .........................(9.27)
dt dt
o The code in Fig. 9.3 then modifies to that shown in Fig. 9.4.
o Note that, three values of 𝜏𝐼 = 1, 5 𝑎𝑛𝑑 20 are defined.
o Three corresponding values of the parameter 𝑐 are also defined (lines 24 to 26).
Effect of integral time on response
o Six initial conditions corresponding to the six state variables are specified in line 30.
o The function definition contains the expressions for the six ODEs, line 32.
o 𝑢1 , 𝑢3 and 𝑢5 corresponds to 𝑥1 , 𝑥3 and 𝑥5 where 𝑥 = 𝑇 − 𝑇𝑠 .
o Thus 𝑢1 = 𝑥1 = 𝑇1 − 𝑇𝑠 or 𝑇1 = 𝑇𝑠 + 𝑢1 , line 37.
o 𝑇1 is the temperature of the STH liquid when 𝜏𝐼 = 1.
o The temperatures when 𝜏𝐼 = 5 and 20 are defined in a similar manner in lines 38
and 39.
o 𝑢2 = 𝑦 = 𝑄 − 𝑄𝑠 and its plot represents how heat supply varies with temperature.
o Note: Eqs are solved for 𝐾𝑐 = 0.5.
Effect of integral time on response
o The results after running the code in Fig. 9.4 are shown in Fig. 9.5
Fig. 9.5 Effect of integral time on the response of the liquid temperature for Kc = 0.5
Using function file and a script file to solve ODEs
o ODEs for the STH will be solved to determine the effect of integral time when PI control
is used.
o Method of creating a function file and running the code in the function file will be
employed.
o For PI control, the resulting system of equations is
t
dx
a bx cy and y Q Qs K C x d xdt ............(9.28)
dt 0
o Where
1 1 1 KC
a (Ti Ti ,s ), b , c and d ............(9.29)
Vc p I
o The second Eq. of 9.28 can be expressed in derivative form
dx dy dx
a bx cy and KC dx.................(9.30)
dt dt dt
Using function file and a script file to solve ODEs
o RHS of second Eq. in 9.30 can be written as algebraic expression
dx dy
a bx cy and K C a bx cy dx.................(9.31)
dt dt
o Or
dx dy
a bx cy and aK C bK C x cK C y dx.................(9.32)
dt dt
o Eq. 9.32 consists the system of first-order ODEs that can be solved in MATLAB.
o Effect of 𝜏𝐼 can be by defining three values of 𝜏𝐼 so that constant 𝑑 becomes
KC KC KC
d1 , d2 and d3 .......................................(9.33)
I ,1 I ,2 I ,3
o The different values of 𝑑 changes second Eq. in 9.32, in turn first Eq. also changes.
o Result is a system containing a set of six ODEs, Eqs. 9.34, 9.35 and 9.36
Using function file and a script file to solve ODEs
dx1 dy1
a bx1 cy1 and aK C bK C x1 cK C y1 d1 x1........(9.34)
dt dt
dx2 dy2
a bx2 cy2 and aK C bK C x2 cK C y2 d 2 x2 .....(9.35)
dt dt
dx3 dy3
a bx3 cy3 and aK C bK C x3 cK C y3 d 2 x3 .....(9.36)
dt dt
o The output f contains six outputs for each of the ODE and is a column vector.
o Outputs contained in f are defined as in line 41.
o The values of 𝜏𝐼 used are indicated in lines 16 to 18 and the corresponding values of 𝑑
in lines 27 to 29.
o Right hand of each differential eq. is written in terms 𝑑𝑥𝑑𝑡 and 𝑑𝑦𝑑𝑡 and is the output.
o Note: any letter can be used to define these outputs.
o However, the letter(s) used must be the same as the outputs defined in f.
o The Eqs are solved for K C = 1 and the corresponding script file to run the code in Fig.
9.7 is shown in Fig. 9.8.
Using function file and a script file to solve ODEs
o Script file contains time span, initial conditions and the ODE solver, ode45 in this case.
o Six initial conditions are specified corresponding to the six state variables.
o Function handle in the ODE solver must have same name as function in the function
file or name under which function file is saved.
o The result of running the script file is shown in Fig. 9.9.
o Fig. 9.9, as 𝜏𝐼 decreases, response becomes more oscillatory with longer settling time.
o The overshoot decreases as 𝜏𝐼 decreases.
o However, generally observed behaviour is that overshoot increases as 𝜏𝐼 decreases.
o Discrepancy could be due to dynamics of other neglected elements.
Using function file and a script file to solve ODEs
Fig. 9.9 Effect of integral time on the response under PI control with Kc = 1