Professional Documents
Culture Documents
Dr. R. L. Herman
UNC Wilmington, Wilmington, NC
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 1/19
Outline
1 Simulink
2 Solution of ODEs
5 Linear Systems
6 Nonlinear Systems
7 Summary
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 2/19
Simulink
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 3/19
Solving a Differential Equation
Consider initial value problem:
dx
= f (x), x(0) = x0 .
dt
Solution Z t
x(t) = x0 + f (x(t)) dt.
0
Think of the solution as
Z
x(t) = x 0 (t) dt.
x0 R x
input output
Schematic
x0 R x
input output
Simulink Model
x0 1 x
f (x)
s
Integrator
Output
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 5/19
First Order Differential Equation - Example 1
Solve x 0 = −4x, x(0) = 1.
x0 1 x
s
Integrator
Scope
−4
Gain
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 6/19
Simulink Workspace
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 7/19
Scilab’s Xcos Workspace
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 8/19
First Order Differential Equation - Example 1
Solve x 0 = 2 sin 3t − 4x, x(0) = 0.
1
s
Sine Wave Integrator Scope
Function
4
Gain
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 9/19
First Order Differential Equation - Example 3
Solve y 0 = 2t y + t 2 , y (1) = 1.
t2 y
u2 dy/dt 1
s
t Math Integrator1 Scope1
Function2
Clock 2/t y
1 1/t 2/t 2
2 y' = 2/t y+t , y(1)=1
u
Math Gain1
Product1
Exact solution: y(t) = t3
Function1
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 10/19
Second Order ODEs
Solve ay 00 + by 0 + cy = 0, y (0) = y0 , y 0 (0) = v0 .
Z Z
y = y 0 dx, y 0 = y 00 dx,
b c
y 00 = − y 0 − y .
a a
Second Order Constant Coefficient ODE
y'' 1 y' 1 y
s s
Integrator Integrator1 Scope
b/a y'
5
b/a
c/a y
6
c/a
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 11/19
Linear Systems of Differential Equations
y
x 0 = ax + by 1
y 0 = cx + dy .
b
x
0
a
1 x
1 xo s
Integrator
x(0)
Scope XY Graph
1 y
2 xo s
Integrator1
y(0) Linear System of Differential Equations
y x'=ax+by
0 y'=cx+dy
d
x
-1
c
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 12/19
Coupled Oscillators
x 00 = −k1 x − b1 x 0 + k2 (y − x) + b2 (y 0 − x 0 )
y 00 = −k2 (y − x) − b2 (y 0 − x 0 ).
Damped Oscillator 1 m1 x'' = - k1 x - b1 x' + k2 (y-x) + b2 (y'-x')
x'' 1 x' 1 x
1/2
s s
1/m1 Integrator Integrator1
0
b1
5 Scope
k1
b2 (y'-x')
0
b2
5
k2 (y-x)
k2
y'' 1 y' 1 y
-1/2
s s
-1/m2 Integrator2 Integrator3 m2 y'' = - k2 (y-x) - b2 (y'-x')
Damped Oscillator 2
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 13/19
Coupled Oscillators - Solutions
5√ 1√ 3√ 5√ 1√
x(t) = cos 2t cos 10t − 5 sin 2t sin 10t
4 4 5 4 4
1√ 5√ 1√ 5√ 1√
y (t) = 5 sin 2t sin 10t − cos 2t cos 10t
5 4 4 4 4
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 14/19
Linear Systems - Matrix Form
0
x 0 1 x
=
y −1 0 y
[x';y']
1 [x;y]
xos
[1;2]
Integrator
IC x
y
Scope XY Graph
0 1
-1 0 * u
Linear System of Differential Equations
Gain
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 15/19
Applications - Lotka Volterra Predator-Prey Model
x 0 = x − axy y 0 = −y + bxy .
xy y
Product Scope
0.01 1
xos
y' y
b Foxes
XY Graph
10
IC1
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 16/19
Applications - SIR Epidemic Model
SI SI
S 0 = −β , I0 = β − γI , R 0 = γI .
N N
where N = S + I + R.
.5 -1 1
s
beta Gain
Product Integrator S
1
.33 s
Product1 Integrator2 R
gamma
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 17/19
Applications - Logistic Equation with Delay
Solve y 0 = ry (t)(1 − y (t − τ )) where τ > 0 provides a delayed response.
2
y' 1 y
Alpha >= 1
s
Integrator Scope
Clock
Switch to enter y=2
for t<=1
0
Solve y'=0
y
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 18/19
Summary
Thank You!
hermanr@uncw.edu
Solving ODEs with Simulink, ICTCM 2016 R. L. Herman Mar 11, 2016 19/19