2021 09 24 - Solvers

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Solvers in

Simulink

Mads Høi Rasmussen


Associate Professor
SDU Mechanical Engineering, Department of Mechanical and Electrical Engineering
Given an Ordinary Differential Equation (ODE):
𝑑𝑑𝑑𝑑
= sin 𝑡𝑡 , 𝑥𝑥 0 = 0
𝑑𝑑𝑑𝑑

Solution:
� 𝑑𝑑𝑑𝑑 = � sin 𝑡𝑡 𝑑𝑑𝑑𝑑
⇔ 𝑥𝑥 𝑡𝑡 = − cos 𝑡𝑡 + 𝑐𝑐

𝑥𝑥 0 = 0

⇒ 0 = cos 0 + 𝑐𝑐
⇔ 𝑐𝑐 = 1

⇒ 𝑥𝑥(𝑡𝑡) = −cos 𝑡𝑡 + 1

2
Numeric method for solving ODE’s: Euler Explicit
ODE:
𝑥𝑥̇ = 𝑓𝑓(𝑡𝑡), 𝑥𝑥 𝑡𝑡0 = 𝑥𝑥0

Time step:
𝑡𝑡1 = 𝑡𝑡0 + ∆𝑡𝑡

First step:
𝑥𝑥1 = 𝑥𝑥0 + ∆𝑡𝑡 � 𝑥𝑥(𝑡𝑡
̇ 0)

Second step:
𝑥𝑥2 = 𝑥𝑥1 + ∆𝑡𝑡 � 𝑥𝑥(𝑡𝑡
̇ 1)

Third step:
𝑥𝑥3 = 𝑥𝑥2 + ∆𝑡𝑡 � 𝑥𝑥(𝑡𝑡
̇ 2)

Infinitely small time step:


∆𝑡𝑡 → 0

𝑥𝑥𝑖𝑖 → 𝑥𝑥(𝑡𝑡𝑖𝑖 )
3
Given ODE:
𝑥𝑥̇ = 𝑠𝑠𝑠𝑠𝑠𝑠(𝑡𝑡), 𝑥𝑥 0 = 0
Time step:
∆𝑡𝑡=0,2 s.
Euler Explicit:
𝑥𝑥0 = 0

𝑥𝑥1 = 𝑥𝑥0 + ∆𝑡𝑡 � 𝑥𝑥(𝑡𝑡


̇ 0)
⇒ 𝑥𝑥1 = 0 + 0,2 � 𝑠𝑠𝑠𝑠𝑠𝑠 0 = 0

𝑥𝑥2 = 𝑥𝑥1 + ∆𝑡𝑡 � 𝑥𝑥(𝑡𝑡


̇ 1)
⇒ 𝑥𝑥2 = 0 + 0,2 � 𝑠𝑠𝑠𝑠𝑠𝑠 0,2 ≈ 0,0397

𝑥𝑥3 = 𝑥𝑥2 + ∆𝑡𝑡 � 𝑥𝑥(𝑡𝑡


̇ 2)
⇒ 𝑥𝑥3 = 0,0397 + 0,2 � 𝑠𝑠𝑠𝑠𝑠𝑠 0,4 ≈ 0,1176

𝑥𝑥4 = 𝑥𝑥3 + ∆𝑡𝑡 � 𝑥𝑥(𝑡𝑡


̇ 3)
⇒ 𝑥𝑥4 = 0,1176 + 0,2 � 𝑠𝑠𝑠𝑠𝑠𝑠 0,6 ≈ 0,230

4
More steps following Euler Explicit and comparing with the analytical solution
to the ODE:

t x x (anal.) Error
(Euler Expl.) 𝑥𝑥(𝑡𝑡) = −cos 𝑡𝑡 + 1 Anal. – Euler expl.
0 0 0 0

0,2 0 0,01993 0,01993

0,4 0,0397 0,0789 0,0392

0,6 0,1176 0,1747 0,0571

0,8 0,230 0,303 0,0730

1,0 0,374 0,460 0,0860

5
Change the time step and see how it influences on the result:

𝑥𝑥̇ = 𝑠𝑠𝑠𝑠𝑠𝑠(𝑡𝑡), 𝑥𝑥 0 = 0

Duration of simulation:
𝑡𝑡 = 1 𝑠𝑠.

Time step, size x 𝑥𝑥 ∆𝑡𝑡𝑛𝑛+1 − 𝑥𝑥 ∆𝑡𝑡𝑛𝑛


(Euler Expl.)
∆𝑡𝑡1 =0,2 s. 0,374017 N/A

∆𝑡𝑡2 =0,1 s. 0,417241 0,043224

∆𝑡𝑡3 =0,01 s. 0,455487 0,038246

∆𝑡𝑡4 =0,005 s. 0,457593 0,002106

∆𝑡𝑡5 =0,001 s. 0,459277 0,001684

⇒ 𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶!

6
Error check on Euler expl.:

∆𝒕𝒕 Error
0,2 s. 0,0857

0,1 s. 0,0425

0,01 s. 0,0042

0,001 s. 0,00042

7
Numeric method for solving ODE’s: Runge-Kutta 4th order
ODE:
𝑥𝑥̇ = 𝑓𝑓(𝑡𝑡), 𝑥𝑥 𝑡𝑡0 = 𝑥𝑥0

Since x depends only on t, Runge-Kutta 4th model reduces to Simpson’s Rule


of Integration:
1
𝑥𝑥𝑛𝑛+1 = 𝑥𝑥𝑛𝑛 + (𝑘𝑘1 +2𝑘𝑘2 + 3𝑘𝑘3 + 𝑘𝑘4 )
6

Where:
𝑘𝑘1 = ∆𝑡𝑡𝑥𝑥(𝑡𝑡
̇ 𝑛𝑛 )

1
𝑘𝑘2 = ∆𝑡𝑡𝑥𝑥(𝑡𝑡
̇ 𝑛𝑛 + ∆𝑡𝑡)
2

1
𝑘𝑘3 = ∆𝑡𝑡𝑥𝑥(𝑡𝑡
̇ 𝑛𝑛 + ∆𝑡𝑡)
2

𝑘𝑘4 = ∆𝑡𝑡𝑥𝑥(𝑡𝑡
̇ 𝑛𝑛 + ∆𝑡𝑡)

Note: 𝑘𝑘2 and 𝑘𝑘3 are the same since x depends only on t.

8
Change the time step and see how it influences on the result:

𝑥𝑥̇ = 𝑠𝑠𝑠𝑠𝑠𝑠(𝑡𝑡), 𝑥𝑥 0 = 0

Duration of simulation:
𝑡𝑡 = 1 𝑠𝑠.

Time step, size x 𝑥𝑥 ∆𝑡𝑡𝑛𝑛+1 − 𝑥𝑥 ∆𝑡𝑡𝑛𝑛


(R-K 4th)
∆𝑡𝑡1 =0,2 s. 0,45969795 N/A

∆𝑡𝑡2 =0,1 s. 0,45969771 2,4 � 10−7

∆𝑡𝑡3 =0,01 s. 0,45969769 2 � 10−8

∆𝑡𝑡4 =0,005 s. 0,45969769 ≈0

∆𝑡𝑡5 =0,001 s. 0,45969769 ≈0

⇒ 𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶 𝑖𝑖𝑖𝑖 𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 𝑚𝑚𝑚𝑚𝑚𝑚𝑚 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 𝑡𝑡𝑡𝑡 𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸 𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒. !

9
Error check on R-K 4th order

∆𝒕𝒕 Error
0,2 s. 2,5 � 10−7

0,1 s. 1,6 � 10−8

0,01 s. 1,6 � 10−12

0,005 s. 1 � 10−13

0,001 s. 2,8 � 10−16

10

You might also like