Numerical Integration: Presented By: Amir Patel PHD (Mechatronics) Cape Town
Numerical Integration: Presented By: Amir Patel PHD (Mechatronics) Cape Town
Numerical Integration: Presented By: Amir Patel PHD (Mechatronics) Cape Town
Numerical Integration
13 Feb 2023
Presented by:
Amir Patel
PhD (Mechatronics) Cape Town
Electrical Engineering Department EEE4119F
University of Cape Town Mechatronics II
Overview
• First Order
• Second Order
• Midpoint Method
• Runge-Kutta
Method
Autonomous drifting
Simple First-Order
Example:
• Integrate:
Simple First-Order
Position
Numerical
Integration
time
• Admin
• Runge-Kutta
• On computer, represent continuous
Method
function using discrete
Computer Implementation
• Admin
• →Slope @t=0 is -1
Extrapolation
• Extrapolation is
good for t <0.2
• But horrible
thereafter!
Car Analogy
𝑑𝑦
𝑦1 = 𝑦0 + ቤ ∆𝑡
𝑑𝑡 𝑡=0
𝑦1 = 𝑦0 − 𝑦0 ∆𝑡
Example (∆𝑡=0.5)
1. Start at y =1 with
slope = -1
2. Extrapolate to
(0.5), slope now
-0.5
3. Extrapolate to
(0.25), slope now
-0.25
4. …and so on!
Code
Taylor Series
Lecture 1:
Numerical
Integration
• Midpoint Method
• Solve for coefficients
• Runge-Kutta
• Simplest approximation would be to
Method
use derivative:
Taylor Series
exp(-t)
1-t
• Taylor series:
Euler method
Error term
• Only need to care about first term
• Why?
• Second Order
• Midpoint Method
• Convert to two 1st order equations:
• Runge-Kutta
Method
Euler (mass spring)
• Euler:
Euler (mass spring)
• Write as vector:
• Then:
• Admin
• First Order
• Second Order
• We want a better estimate of the slope
between samples
• Midpoint Method
• Euler assumed the initial derivative
• Runge-Kutta
was held throughout step
Method
• This caused instability!
Approximate derivatives (y=e-x)
• Plot derivatives:
• Initial
• Final
• Middle
• Extrapolation based on
midpoint gradient:
• Taylor series:
• Substitute:
∆𝒕
• Then using 𝒚𝑵+𝟏/𝟐 and , can calculate the derivative
𝟐
• Last step in algorithm is then:
𝒅𝒚
Exercise = −𝒚
𝒅𝒕
• Step1: Euler
• Step2: Deriv
time+dt/2,yH)
Compare (Mass-spring)
𝒅𝒚
Error Plot ( = −𝒚)
𝒅𝒕
Code
Runge-Kutta Method
Lecture 1:
Numerical
Integration
• Admin
• First Order
• Second Order
• Most popular method
• 4th Order Runge-Kutta Method
• Midpoint Method
• Instead of shooting to midpoint,
• Runge-Kutta
shoot to 4 specific points
Method
RK4 Algorithm
Assume:
Then:
𝒅𝒚
Error Analysis ( = −𝒚)
𝒅𝒕
t^4
The end.
• Next lecture