Modeling Simulation 20231
Modeling Simulation 20231
November 3, 2023
Definitions
Model classification
Applications
Model evaluation
Procedure for modeling
Methods for building mathematical model
Y (s)
Transfer function: G(s) = (2)
U(s)
State space model: ẋ = Ax + Bu (3)
Nonlinear model (CT/DT):
ẋ = f (x, u) (4)
1. Does the model agree sufficiently well with the observed data?
2. Is the model good enough for the application?
3. Does the model describe the ”’true system”?
2.1 Models
2.2 Mathematical model
2.3 Theoretical model
2.4 Practical model
2.5 HIL Simulation
Differential equation:
d ny d n−1 y dy d mu d m−1 u
+ a n−1 + ... + a1 + a0 y = + b m−1 + ...
dt n dt n−1 dt dt m dt m−1
du
+ b1 + b0 u
dt
(5)
m ≤ n, u : the input, y : output.
SISO nonlinear system:
d ny d n−1 y dy d m u d m−1 u du
= f , ..., , y, , , ..., ,u (6)
dt n dt n−1 dt dt m dt m−1 dt
Difference equation
y(n + k) =f (y(n − 1 + k), y(n − 2 + k, ..., y(k), u(m + k ), u(m − 1 + k), ..., u(k)). (7)
Transfer function
Y (s)
G(s) = (8)
U(s)
Laplace transform
Z ∞
Y (s) = y(t)e−st dt (9)
0
Y (z)
G(z) = (10)
U(z)
Z transfrom:
∞
X
Y (z) = y (k )z −k (11)
0
1 Problem is structured.
2 Formulate basic equations
3 Form state-space model
Kirchhoff’s current law (1st Law): The current flowing into a node
(or a junction) must be equal to the current flowing out of it
(consequence of charge conservation).
Kirchhoff’s voltage law (2nd Law): In any complete loop within a
circuit, the sum of all voltages across components which supply
electrical energy must equal the sum of all voltages across the
other components in the same loop (consequence of both charge
conservation and the conservation of energy).
1
LsI(s) + RI(s) + I(s) =Ei (s)
Cs (18)
1
I(s) =Eo (s)
Cs
Transfer function:
Eo 1
= 2
(19)
Ei LCs + RCs + 1
R 1 1
ëo + ėo + eo = ei (20)
L LC LC
R 1 1
ëo + ėo + eo = ei (21)
L LC LC
1 R 1
Define x1 = eo , x2 = ėo . Then, ẋ1 = x2 , ẋ2 = − LC x1 − L x2 + LC ei .
State-space model:
ẋ = Ax + Bu, y = Cx (22)
0 1 0
A= 1 R ,B = 1 , and C = [0 1].
− LC −L LC
Eo
Find Ei .
eo = K (e2 − e1 ) (23)
K ≈ 105 ÷ 106 for dc signals and ac signals with small frequencies
(≤ 10Hz).
ei − e′ e ′ − eo
i1 = , i2 = (24)
R1 R2
Since e′ ≈ 0 and only a negligible current flows into the amplifier,
i1 = i2 .
R2
eo = − ei (25)
R1
R2
eo = (1 + )ei (26)
R1
Eo R2 1
=− (27)
Ei R1 R2 Cs + 1
Eo Ts + 1 s + T1
= Kc α = Kc 1
(28)
Ei αTs + 1 s + αT
R4 C1 R2 R4
where T = R1 C1 , αT = R2 C2 , Kc = R3 C2 , Kc α = R1 R3 .
Eo Ti
= Kp (1 + + Td s) (29)
Ei s
R4 (R1 C1 +R2 C2 ) 1
Proportional gain: Kp = R3 R1 C2 . Integral time: Ti = R1 C1 +R2 C2 .
R1 C1 R2 C2
Derivative time: Td = R1 C1 +R2 C2 .
Mechanical systems:
Newton’s second law: X
ma = Fi (30)
P
m: mass, a: acceleration of the mass, Fi : the sum of forces Fi
acting on the mass.
F = k1 x + k2 x = keq x (31)
k1 , k2 > 0: spring constants (N/m)
F : spring force
keq = k1 + k2 (32)
F =k1 y = k2 (x − y ) (33)
k1 , k2 > 0: spring constants (N/m)
F : spring force
k1 k2
keq = (34)
k1 + k2
d 2y dy du
2
= −b(
m − ) − k (y − u). (40)
dt dt dt
Differential equation:
d 2y dy du
m +b + ky = b + ku. (41)
dt 2 dt dt
Transfer function:
Y (s) bs + k B(s)
G(s) = = 2
= (42)
U(s) ms + bs + k A(s)
U(s)
Denote X1 (s) = A(s) and X2 (s) = s U(s)
A(s) → ẋ1 = x2 .
k b 1
ms2 X1 + bsX1 + kX1 = U → ẋ2 = − m x1 − m x2 + m u.
Y (s) = (bs + k)X1 (s) → y = kx1 + bx2 .
State-space model (controllable canonical form):
ẋ = Ax + Bu, y = Cx (43)
0 1 0
where A = k b , B = 1 , C = [k b].
−m −m m
Liquid-level system:
The flow through a short pipe connecting two tanks.
Turbulent flow: √
Q=K H (48)
dH 2H
Rturbulent flow = = (49)
dQ Q
The inflow minus outflow during the small time interval is equal to the
additional amount stored in the tank.
h
qo = , by definition of resistance (51)
R
dh
RC + h = Rqi , R is constant (52)
dt
h1 − h2 dh1
= q1 , C1 = q − q1 (53)
R1 dt
h2 dh2
= q2 , C2 = q1 − q2 (54)
R2 dt
Assoc. Prof. Nguyen Hoai Nam November 3, 2023 47 / 73
2.3 Theoretical (physical) model
Q2 1
= 2
(55)
Q R1 C1 R2 C2 s + (R1 C1 + R2 C2 + R2 C1 )s + 1
Transient analysis
Linear regression
Y (s)
G(s) = (56)
U(s)
G(s)
Y (s) = or y(t) = L−1 {G(s)/s} (58)
s
R: Resistance, C: capacitance.
Vout 1
= (59)
Vin 1 + RCs
Θ R
= (60)
Hi RCs + 1
k
G(s) = (61)
Ts + 1
Unit-step response:
t
c(t) = k (1 − e− T ), for t ≥ 0. (62)
Unit-ramp response:
t
c(t) = k (t − T + Te− T ), for t ≥ 0. (63)
Unit-impulse response:
k −t
c(t) = e T, for t ≥ 0. (64)
T
k = c(∞) (66)
c(T ) = k (1 − e−1 ) = 0.6321k. (67)
J: moment of inertia referred to the output shaft, B: viscous-friction coefficient referred to the output shaft, K : controller gain.
ωn2
G(s) = (69)
s2 + 2ζωn s + ωn2
ωn : undamped natural frequency, ζ: damping ratio of the system.
ωn2
C(s) =
s(s2 + 2ζωn s + ωn2 )
1 s + 2ζωn p
= − 2 2
, ωd = ωn 1 − ζ 2 (damped nature frequency.).
s s + 2ζωn s + ωn
1 s + ζωn ζωn
= − 2
−
2
s (s + ζωn ) + ωd (s + ζωn )2 + ωd2
ζ
c(t) =1 − e−ζωn t cos(ωd t) + p sin(ωd t)
1 − ζ2
e−ζωn t p
=1 − p 1 − ζ 2 cos(ωd t) + ζsin(ωd t)
1 − ζ2
p
e−ζωn t −1 1 − ζ2
=1 − p sin(ωd t + θ), θ = tan .
1 − ζ2 ζ
(70)
Assoc. Prof. Nguyen Hoai Nam November 3, 2023 58 / 73
ζ=0
ωn2
C(s) = (72)
s(s + ωn )2
c(t) = 1 − e−ωn t (1 + ωn t) (73)
ωn2
C(s) = (74)
s(s2 + 2ζωn s + ωn2 )
ωn e−s1 t e−s2 t
c(t) = 1 + p − (75)
2 ζ 2 − 1 s1 s2
p p
s1 = (ζ + ζ 2 − 1)ωn , s2 = (ζ − ζ 2 − 1)ωn
∂c(t) e−ζωn t h i
=p ζωn sin(ωd t + θ) − ωd cos(ωd t + θ)
∂t 1 − ζ2
=0
p
1 − ζ2
→ tan(ωd t + θ) =
ζ
ωd Tk =k π, k = 0, 1, 2, ...
(76)
kπ
Tk = p
ωn 1 − ζ 2
π
tp = T1 = p → ωn
ωn 1 − ζ 2
Mp =c(tp ) − 1
√−πζ
=e 1−ζ 2 →ζ
Assoc. Prof. Nguyen Hoai Nam November 3, 2023 62 / 73
Linear regression
yi = bi,1 x + bi,2 .
Assoc. Prof. Nguyen Hoai Nam November 3, 2023 65 / 73
Fuzzy logic inference system
Sugeno model:
yi = ai x1 + bi x2 + ci .
Assoc. Prof. Nguyen Hoai Nam November 3, 2023 66 / 73
Neural network
R
X
n= w1,i pi + b, a = f (n) (84)
i=1
b1
w1,1 w1,2 . . . w1,R−1 w1,R
w2,1 w2,2 . . . w2,R−1 w2,R
b2
W= .
b=
..
(86)
. .. .. .. .
. . . .
bS−1
wS,1 wS,2 . . . wS,R−1 wS,R S×R
bS S×1
n =Wp + b
(87)
a =f(n)
Network’s output:
n1 =W1 p + b1
a1 =f1 (n1 )
(88)
n2 =W2 p + b2
a2 =f2 (n2 )
Assoc. Prof. Nguyen Hoai Nam November 3, 2023 73 / 73