SlideShare a Scribd company logo
1 of 58
1
Programming, Computation, Simulation
Applications in Math & Physics
Euler and Runge-Kutta Methods
Ordinary Differential Equations & Initial Value Problems
Syeilendra Pramuditya
Department of Physics
Institut Teknologi Bandung
Grid-based Computation
 Euler-type Methods
 Differential equations
 Temporal domain (variation in time)
 Initial conditions
 Finite Difference Methods
 Differential equations
 Spatial domain (variation in space)
 Boundary conditions: Von Neumann VS
Dirichlet
3
Differential Equation
2
( ) ( , ) 1
( 0) 0
( ) ..?
dy
y x f x y x
dx
y x
y x
    
 

4
Differential Equation
2
( ) ( , ) 1
( 0) 0
dy
y x f x y x
dx
y x
    
 
2
3
3
Exact Solution
( 1)
1
3
( 0) 0 0
1
( ) ( , )
3
dy x dx
y x x C
y x C
y x f x y x x
 
  
   
  
 
5
Differential Equation
1
( ) ( , )
( 1) 0
( ) ..?
dy
y x f x y
dx x
y x
y x
   
 

6
Differential Equation
1
( ) ( , )
( 1) 0
dy
y x f x y
dx x
y x
   
 
Exact Solution
1
ln( )
( 1) 0 0
( ) ( , ) ln( )
dy dx
x
y x C
y x C
y x f x y x

 
   
 
 
7
Differential Equation
2 1
( ) ( , ) 1
( 0) 0
..???
dy
y x f x y x
dx y
y x
y
     
 

Euler Methods
 Linear approx. of Taylor series
 “Simple Euler”
0
x x
0
( )
f x
( )
f x  
0
0 0 0
0
0 0 0
0
0 0 0 0
0 0 0 0
0 0 0
( ) ( )
( ) ( , )
( ) ( ) ( )
( ) ( ) ( , )
( ) ( ) ( , ( ))
( )
y x y x
y x f x y
x x
y x y x x x y x
x x h
y x h y x hf x y
y x h y x hf x y x
y x h y hf

  


  
 
  
  
  
0 0 0
( ) ( , )
y
y x f x y
x

  

9
Ordinary Differential Equation (ODE)
0 0 0 0
0 0 0
( ) ( ) ( , )
( )
( , )
new old old old
y x h y x hf x y
y x h y hf
y y hf x y
  
  
 
 Solve the above ODE numerically (find y(x)) using Simple
Euler method (for 1<x<10), use h = 1.0 and h = 0.5
 How good the numerical solution is?
1
( ) ( , )
( 1) 0
dy
y x f x y
dx x
y x
   
 
Simple Euler Code
0 0 0 0
0 0 0
( ) ( ) ( , )
( )
( , )
new old old old
y x h y x hf x y
y x h y hf
y y hf x y
  
  
 
Solve the ODE numerically (find y(x)) using Simple
Euler method (for 1<x<10), use h = 1.0 and h = 0.5
1
( ) ( , )
( 1) 0
dy
y x f x y
dx x
y x
   
 
Exact VS Numeric
0
0.5
1
1.5
2
2.5
3
0 2 4 6 8 10
Exact
Euler, h = 1.0
Euler, h = 0.5
Euler Methods
 Linear approx. of Taylor series
 “Modified Euler” Use more correct gradient
0
x x
0
( )
f x
( )
f x
 
0 0
0 0
0
0
0 0
0 0
( ) ( ) ( )
( ) ( ) ( , )
2
( )
2
2
( )
mid
mid mid
mid
mid
mid
mid
y x y x x x y x
y x h y x hf x y
h
x x
h
y y x
h
y y f
y x h y hf

  
  
 
 
 
  
Modified Euler
 
0 0
0 0
0
0
0 0
0 0
( ) ( ) ( )
( ) ( ) ( , )
2
( )
2
2
( )
mid
mid mid
mid
mid
mid
mid
y x y x x x y x
y x h y x hf x y
h
x x
h
y y x
h
y y f
y x h y hf

  
  
 
 
 
  
Euler Methods
 Linear approx. of Taylor series
 “Improved Euler” Use more correct gradient
0
x x
0
( )
f x
( )
f x
0 0 0
0 0
0
0 0
0 0 0 0
0 0
( ) ( , )
( ) ( , )
( ) ( )
( )
2
( , ) ( , )
2
( , ) ( , ( , ))
( ) ( )
avg
avg
avg
y x f x y
y x f x y y hf
y x y x
y x
f x y f x y
f
f x y f x h y hf x y
y x h y x hf
 
   
 

 


  
  
Improved Euler
0 0 0
0 0
0
0 0
0 0 0 0
0 0
( ) ( , )
( ) ( , )
( ) ( )
( )
2
( , ) ( , )
2
( , ) ( , ( , ))
( ) ( )
avg
avg
avg
y x f x y
y x f x y y hf
y x y x
y x
f x y f x y
f
f x y f x h y hf x y
y x h y x hf
 
   
 

 


  
  
2nd Order Runge-Kutta (RK2)
1 0 0
1
2 0 0
0 0 2
( , )
( , )
( , )
2 2
( )
dy
y f x y
dx
k hf x y
k
h
k hf x y
y x h y k
  

  
  
4th Order Runge-Kutta (RK4)
 
1 0 0
2 0 0 1
3 0 0 2
4 0 0 3
0 0 1 2 3 4
4th Order Runge-Kutta
( , )
( , )
( , )
2 2
( , )
2 2
( , )
( ) 2 2
6
dy
y f x y
dx
k f x y
h h
k f x y k
h h
k f x y k
k f x h y hk
h
y x h y k k k k
  

  
  
  
     
Exact VS Numeric
 Simple Euler (h = 0.2)
Exact VS Numeric
 Modified Euler (h = 0.2)
Exact VS Numeric
 Improved Euler (h = 0.2)
Exact VS Numeric
 RK4 (h = 0.2)
22
Block-Spring System
( ) ( , ) ( )
( ) ( , ) ( )
F ma
dv F k
a x
dt m m
dv k k
x v t f x t x t
dt m m
dx
v x t f v t v t
dt


  
 

   

   
23
Block-Spring System
   
   
0 0 0
0 0 0 0
0
0 0 0
0 0 0 0
0
2 2
1 1
( ) ( ) ( ) ( ) ( , )
1 1
( ) ( ) ( ) ( ) ( , )
1 1
2 2
t
t
v v at v t v v t t v t v t v f v t
t t
dv k
v t v t v x
dt m
x x vt x t x x t t x t x t x f x t
t t
dx
x t x t x v
dt
E mv kx
  
  


 
        
    
 
        
    
 
0 0 0 0
0 0 0
( ) ( ) ( , )
( )
y x h y x hf x y
y x h y hf
  
  
24
Block-Spring System (Simplified)
1
2
0 0
0 0 1 0 0 0 0
0 0 2 0 0 0 0 0 0
2 2
( ) ( , ) ( )
( ) ( , ) ( )
( )
( ) ( , )
( ) ( , ) ( )
1 1
2 2
dv k
v t f t v x t
dt m
dx
x t f t x v t
dt
kx t kx
v t t v t f t v v t v t
m m
x t t x t f t x x tv t x tv
E mv kx

   
   
   
 
           
   
   
           
 
0 0 0 0
0 0 0 0
( ) ( ) ( , )
( )
y x h y x hf x y
dy
y x h y hf y h
dx
  
    
25
Block-Spring System (Simplified)
0 0
0 0 0 0 0
0 0 0 0 0 0 0
2 2
( ) ( )
( ) ( )
( )
( ) ( )
( ) ( ) ( )
1 1
2 2
dv k
v t x t
dt m
dx
x t v t
dt
kx t kx
v t t v t v t v t v t
m m
x t t x t x t x tv t x tv
E mv kx

  
  
   
 

           
   
   

           
 
0 0 0 0
0 0 0 0
( ) ( ) ( , )
( )
y x h y x hf x y
dy
y x h y hf y h
dx
  
    
26
Block-Spring System (Simplified)
0
0 0 0 0 0
0 0 0
0 0 0 0
2 2
( )
( )
( )
1 1
2 2
kx
dv F
v t t v t v a t v t v t
dt m m
k
v t t v x t
m
dx
x t t x t x v t
dt
E mv kx

             
    
       
 
0 0 0 0
0 0 0 0
( ) ( ) ( , )
( )
y x h y x hf x y
dy
y x h y hf y h
dx
  
    
27
Block-Spring System
1
0 0 0 0 0 0 0 0 0
2
0 0 0
0 0 0 0 0 0
Simple Euler
( , ) ( ) ( )
( ) ( , ) ( , )
( , ) ( ) ( )
( , )
( ) ( , )
new old old
new old
dx
x t x f t v t
dt
x t t x t x t x x tv t v x tv
x x tv
dv k
v t v f t x t
dt m
kx t x kx
v t t v t v t v v t v t
m m
v v t
   

           
  

   
   
 

           
   
   

  
2 2
1 1
2 2
old
kx
m
E mv kx
 
 
 
 
Block-Spring System
 Analytic Solution
( ) cos( )
( ) sin( )
m
m
x t x t
v t v t
 
 
 
  
29
Write a Simple Euler Code
 m = k = 1
 0 < t < 20 sec
 dt = 0.2
 x(t=0) = 1
 v(t=0) = 0
 Calculate x(t) and v(t) using Simple Euler
 Output: time,x(t),x_exact,v(t),v_exact,Em
0 0 0 0
0 0 0 0
( ) ( ) ( , )
( )
y x h y x hf x y
dy
y x h y hf y h
dx
  
    
0
0 0 0 0 0
0 0 0
0 0 0 0
2 2
( )
( )
( )
1 1
2 2
kx
dv F
v t t v t v a t v t v t
dt m m
k
v t t v x t
m
dx
x t t x t x v t
dt
E mv kx

             
    
       
 
Simple Euler Code
0 0 0
0 0 0
2 2
( )
( )
1 1
2 2
k
v t t v x t
m
x t t x v t
E mv kx
    
    
 
output.txt
Gnuplot Script
# Script to plot 1D dataset
reset
unset label
unset key
set key left top
set xrange [0:10]
set yrange [-3:3]
set title "Plot Image"
set xlabel "X Value"
set ylabel "Y Value"
set terminal wxt size 600,400 font "Verdana,10"
plot 'output.txt' using 2:3 title "Numeric" with linespoints pointtype 6 lw 1 lc 7, 
'output.txt' using 2:4 title "Analytic" with linespoints pointtype 6 lw 1 lc 6
33
Simple Euler: Position
34
Simple Euler: Velocity
Simple Euler: Energy
36
Block-Spring System
1
2
0 0 1 0 0 0
0 0 2 0 0 0
0 0 1
0 0 2
Modified Euler
( , ) ( ) ( )
( , ) ( ) ( )
( ) ( )
2 2 2
( ) ( )
2 2 2
( ) ( )
( ) ( )
mid
mid
mid
mid
dx
x t x f t v t
dt
dv k
v t v f t x t
dt m
t t t
x x t x f t x v
t t t k
v v t v f t v x
m
x t t x t f t
v t t v t f t
   

   
  
       
   
       
     
     
37
Modified Euler: Position
38
Modified Euler: Velocity
Modified Euler: Energy
Mass-Spring System
 2nd Order Runge-Kutta (RK2)
1 0 0
1
2 0 0
0 0 2
( ) ?
( , )
( , )
( , )
2 2
( )
q t
dq
q f t q
dt
k dt f t q
k
dt
k dt f t q
q t dt q k

  
 
   
  
1 0 0
1
2 0 0
0 0 2
( ) ?
( , )
( , )
( , )
2 2
( )
y x
dy
y f x y
dx
k hf x y
k
h
k hf x y
y x h y k

  

  
  
y(x)
x
q(t)
t
Mass-Spring System
 2nd Order Runge-Kutta (RK2)
1
( ) ?
( , ) ( )
x t
dx
x f t x v t
dt

   
x(t)
t
v(t)
t
2
( ) ?
( , ) ( )
v t
dv k
v f t v x t
dt m


   
Mass-Spring System
 2nd Order Runge-Kutta (RK2)
1 0 0
1
2 0 0
0 0 2
( ) ?
( , )
( , )
( , )
2 2
( )
q t
dq
q f t q
dt
k dt f t q
k
dt
k dt f t q
q t dt q k

  
 
   
  
1
1 1
2 1
2
2
( ) ( )
( ) ( )
( ) ( )
2 2
( ) ( ) ( ) ( )
2 2 2
( ) ( )
2
( ) ( ) ( ) ( ) ( )
2
dx
x f t v t
dt
k t f t t v t
t t
k t f t t v t
t t t k
v t v t v v t x t
m
t k
k t v t x t
m
t k
x t t x t k x t t v t x t
m
   
     
 
       
   

     
 
 
    
 
 
 
 
         
 
 
Mass-Spring System
 2nd Order Runge-Kutta (RK2)
1 0 0
1
2 0 0
0 0 2
( ) ?
( , )
( , )
( , )
2 2
( )
q t
dq
q f t q
dt
k dt f t q
k
dt
k dt f t q
q t dt q k

  
 
   
  
2
1 2
2 2
2
2
( ) ( )
( ) ( )
( ) ( )
2 2
( ) ( ) ( ) ( )
2 2 2
( ) ( )
2
( ) ( ) ( ) ( ) ( )
2
dv k
v f t x t
dt m
k
k t f t t x t
m
t k t
k t f t t x t
m
t t t
x t x t x x t v t
k t
k t x t v t
m
k t
v t t v t k v t t x t v t
m

   

     
  
       
  

    
 
 
   
 
 
 
 
        
 
 
RK2: Position x(t)
RK2: Velocity v(t)
RK2: Mechanical Energy Em(t)
4th Order Runge-Kutta (RK4)
 
1 0 0
2 0 0 1
3 0 0 2
4 0 0 3
0 0 1 2 3 4
( , )
( , )
( , )
2 2
( , )
2 2
( , )
( ) 2 2
6
dy
y f x y
dx
k f x y
h h
k f x y k
h h
k f x y k
k f x h y hk
h
y x h y k k k k
  

  
  
  
     
1
2
( ) ( )
( ) ( )
( ) ?
( ) ?
dx
x f t v t
dt
dv k
v f t x t
dt m
x t dt
v t dt
   

   
 
 
RK4: Position x(t)
49
Damped Mass-Spring System
F ma kx cv
dv F kx cv
a
dt m m
dv k c
x v
dt m m
dx
v
dt
   
 
  

 

50
Damped Mass-Spring System
     
   
0 0 0
0 0 0 0
0
0 0 0
0 0 0 0
0
2 2
1 1
( ) ( ) ( ) ( ) ( , )
1 1
( ) ( ) ( ) ( ) ( , )
1 1
2 2
t
t
v v at v t v v t t v t v t v f v t
t t
dv
v t v t v x cv
dt
x x vt x t x x t t x t x t x f x t
t t
dx
x t x t x v
dt
E mv kx
  
  


 
        
     
 
        
    
 
51
Damped Oscillation
 m = k = 1
 0 < t < 20 sec
 dt = 0.2
 x(t=0) = 1
 v(t=0) = 0
 c = 0.15
 Calculate x(t) and v(t) using Euler Method
 Output: time,x(t),x_exact,v(t),v_exact,Em
0 0 0 0
0 0 0 0
( ) ( ) ( , )
( )
y x h y x hf x y
dy
y x h y hf y h
dx
  
    
0 0
0 0 0 0 0
0 0
0 0
0 0 0 0
2 2
( )
( )
( )
1 1
2 2
kx cv
dv F
v t t v t v a t v t v t
dt m m
kx cv
v t t v t
m
dx
x t t x t x v t
dt
E mv kx
 
             
 
    
       
 
52
Damped Oscillation (Mod. Euler)
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
1.2
0 5 10 15 20
TIme
Position
Damped Oscillation: Analytical Solution
 Halliday-Resnick, Chapter 15
Type of Damped Oscillation
Type of Damped Oscillation
LC Oscillation
2
2
0
d x k
x
dt m
 
Damped LC Oscillation (RLC Circuit)
 The RLC Circuit
2
2
0
d x c dx k
x
dx m dt m
  
Self-Practice for Interested Students
 Ideal/undamped oscillating systems
 Mass-spring systems
 RLC systems
 Modified / Improved Euler Methods
 RK2 / RK4 Methods
 Damped oscillating systems
 Mass-spring systems
 RLC systems
 Modified / Improved Euler Methods
 RK2 / RK4 Methods
 Underdamped / Overdamped / Critically damped

More Related Content

What's hot

First Order Differential Equations
First Order Differential EquationsFirst Order Differential Equations
First Order Differential EquationsItishree Dash
 
Euler and improved euler method
Euler and improved euler methodEuler and improved euler method
Euler and improved euler methodSohaib Butt
 
Eigen values and eigen vectors engineering
Eigen values and eigen vectors engineeringEigen values and eigen vectors engineering
Eigen values and eigen vectors engineeringshubham211
 
first order ode with its application
 first order ode with its application first order ode with its application
first order ode with its applicationKrishna Peshivadiya
 
First order linear differential equation
First order linear differential equationFirst order linear differential equation
First order linear differential equationNofal Umair
 
3 bessel's functions
3 bessel's functions3 bessel's functions
3 bessel's functionsMayank Maruka
 
Orthogonal Vector Spaces
Orthogonal Vector Spaces Orthogonal Vector Spaces
Orthogonal Vector Spaces Sohaib H. Khan
 
Methods of solving ODE
Methods of solving ODEMethods of solving ODE
Methods of solving ODEkishor pokar
 
Ordinary differential equation
Ordinary differential equationOrdinary differential equation
Ordinary differential equationJUGAL BORAH
 
Differential equations of first order
Differential equations of first orderDifferential equations of first order
Differential equations of first ordervishalgohel12195
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problemsMake Mannan
 
formulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equationformulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equationMahaswari Jogia
 
Finite difference method
Finite difference methodFinite difference method
Finite difference methodDivyansh Verma
 
Partial Differential Equations, 3 simple examples
Partial Differential Equations, 3 simple examplesPartial Differential Equations, 3 simple examples
Partial Differential Equations, 3 simple examplesEnrique Valderrama
 
Gaussian quadratures
Gaussian quadraturesGaussian quadratures
Gaussian quadraturesTarun Gehlot
 
Tensor analysis EFE
Tensor analysis  EFETensor analysis  EFE
Tensor analysis EFEBAIJU V
 

What's hot (20)

First Order Differential Equations
First Order Differential EquationsFirst Order Differential Equations
First Order Differential Equations
 
Euler and improved euler method
Euler and improved euler methodEuler and improved euler method
Euler and improved euler method
 
Eigen values and eigen vectors engineering
Eigen values and eigen vectors engineeringEigen values and eigen vectors engineering
Eigen values and eigen vectors engineering
 
Legendre functions
Legendre functionsLegendre functions
Legendre functions
 
first order ode with its application
 first order ode with its application first order ode with its application
first order ode with its application
 
First order linear differential equation
First order linear differential equationFirst order linear differential equation
First order linear differential equation
 
3 bessel's functions
3 bessel's functions3 bessel's functions
3 bessel's functions
 
Orthogonal Vector Spaces
Orthogonal Vector Spaces Orthogonal Vector Spaces
Orthogonal Vector Spaces
 
Methods of solving ODE
Methods of solving ODEMethods of solving ODE
Methods of solving ODE
 
Ordinary differential equation
Ordinary differential equationOrdinary differential equation
Ordinary differential equation
 
Differential equations of first order
Differential equations of first orderDifferential equations of first order
Differential equations of first order
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
 
Higher order differential equations
Higher order differential equationsHigher order differential equations
Higher order differential equations
 
formulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equationformulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equation
 
Finite difference method
Finite difference methodFinite difference method
Finite difference method
 
GAUSS ELIMINATION METHOD
 GAUSS ELIMINATION METHOD GAUSS ELIMINATION METHOD
GAUSS ELIMINATION METHOD
 
Partial Differential Equations, 3 simple examples
Partial Differential Equations, 3 simple examplesPartial Differential Equations, 3 simple examples
Partial Differential Equations, 3 simple examples
 
Gaussian quadratures
Gaussian quadraturesGaussian quadratures
Gaussian quadratures
 
DIFFERENTIAL EQUATIONS
DIFFERENTIAL EQUATIONSDIFFERENTIAL EQUATIONS
DIFFERENTIAL EQUATIONS
 
Tensor analysis EFE
Tensor analysis  EFETensor analysis  EFE
Tensor analysis EFE
 

Similar to SPSF04 - Euler and Runge-Kutta Methods

Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...
Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...
Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...IOSR Journals
 
A Convergence Theorem Associated With a Pair of Second Order Differential Equ...
A Convergence Theorem Associated With a Pair of Second Order Differential Equ...A Convergence Theorem Associated With a Pair of Second Order Differential Equ...
A Convergence Theorem Associated With a Pair of Second Order Differential Equ...IOSR Journals
 
Ah unit 1 differentiation
Ah unit 1 differentiationAh unit 1 differentiation
Ah unit 1 differentiationsjamaths
 
Linear transformations-thestuffpoint.com
Linear transformations-thestuffpoint.comLinear transformations-thestuffpoint.com
Linear transformations-thestuffpoint.comAbu Bakar Soomro
 
Controllability of Linear Dynamical System
Controllability of  Linear Dynamical SystemControllability of  Linear Dynamical System
Controllability of Linear Dynamical SystemPurnima Pandit
 
The Study of the Wiener Processes Base on Haar Wavelet
The Study of the Wiener Processes Base on Haar WaveletThe Study of the Wiener Processes Base on Haar Wavelet
The Study of the Wiener Processes Base on Haar WaveletScientific Review SR
 
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and SystemsDSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and SystemsAmr E. Mohamed
 
Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology Amro Elfeki
 
two degree of freddom system
two degree of freddom systemtwo degree of freddom system
two degree of freddom systemYash Patel
 
Circuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace TransformCircuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace TransformSimen Li
 
STate Space Analysis
STate Space AnalysisSTate Space Analysis
STate Space AnalysisHussain K
 
Lecture -Earthquake Engineering (2).pdf
Lecture -Earthquake Engineering (2).pdfLecture -Earthquake Engineering (2).pdf
Lecture -Earthquake Engineering (2).pdfRayRabara
 
A common random fixed point theorem for rational ineqality in hilbert space ...
 A common random fixed point theorem for rational ineqality in hilbert space ... A common random fixed point theorem for rational ineqality in hilbert space ...
A common random fixed point theorem for rational ineqality in hilbert space ...Alexander Decker
 
Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...journal ijrtem
 
Solution of simplified neutron diffusion equation by FDM
Solution of simplified neutron diffusion equation by FDMSolution of simplified neutron diffusion equation by FDM
Solution of simplified neutron diffusion equation by FDMSyeilendra Pramuditya
 
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...nutkoon
 
discrete_state_spaceeeeeerrrrrrrrrrrrrrrr
discrete_state_spaceeeeeerrrrrrrrrrrrrrrrdiscrete_state_spaceeeeeerrrrrrrrrrrrrrrr
discrete_state_spaceeeeeerrrrrrrrrrrrrrrrManhHoangVan
 
2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...
2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...
2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...NUI Galway
 

Similar to SPSF04 - Euler and Runge-Kutta Methods (20)

Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...
Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...
Asymptotic Behavior of Solutions of Nonlinear Neutral Delay Forced Impulsive ...
 
A Convergence Theorem Associated With a Pair of Second Order Differential Equ...
A Convergence Theorem Associated With a Pair of Second Order Differential Equ...A Convergence Theorem Associated With a Pair of Second Order Differential Equ...
A Convergence Theorem Associated With a Pair of Second Order Differential Equ...
 
Ah unit 1 differentiation
Ah unit 1 differentiationAh unit 1 differentiation
Ah unit 1 differentiation
 
Linear transformations-thestuffpoint.com
Linear transformations-thestuffpoint.comLinear transformations-thestuffpoint.com
Linear transformations-thestuffpoint.com
 
Controllability of Linear Dynamical System
Controllability of  Linear Dynamical SystemControllability of  Linear Dynamical System
Controllability of Linear Dynamical System
 
The Study of the Wiener Processes Base on Haar Wavelet
The Study of the Wiener Processes Base on Haar WaveletThe Study of the Wiener Processes Base on Haar Wavelet
The Study of the Wiener Processes Base on Haar Wavelet
 
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and SystemsDSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
 
Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology
 
two degree of freddom system
two degree of freddom systemtwo degree of freddom system
two degree of freddom system
 
Circuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace TransformCircuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace Transform
 
STate Space Analysis
STate Space AnalysisSTate Space Analysis
STate Space Analysis
 
Lecture -Earthquake Engineering (2).pdf
Lecture -Earthquake Engineering (2).pdfLecture -Earthquake Engineering (2).pdf
Lecture -Earthquake Engineering (2).pdf
 
A common random fixed point theorem for rational ineqality in hilbert space ...
 A common random fixed point theorem for rational ineqality in hilbert space ... A common random fixed point theorem for rational ineqality in hilbert space ...
A common random fixed point theorem for rational ineqality in hilbert space ...
 
D028036046
D028036046D028036046
D028036046
 
Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...Positive and negative solutions of a boundary value problem for a fractional ...
Positive and negative solutions of a boundary value problem for a fractional ...
 
Solution of simplified neutron diffusion equation by FDM
Solution of simplified neutron diffusion equation by FDMSolution of simplified neutron diffusion equation by FDM
Solution of simplified neutron diffusion equation by FDM
 
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
 
discrete_state_spaceeeeeerrrrrrrrrrrrrrrr
discrete_state_spaceeeeeerrrrrrrrrrrrrrrrdiscrete_state_spaceeeeeerrrrrrrrrrrrrrrr
discrete_state_spaceeeeeerrrrrrrrrrrrrrrr
 
Intro Class.ppt
Intro Class.pptIntro Class.ppt
Intro Class.ppt
 
2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...
2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...
2013.06.17 Time Series Analysis Workshop ..Applications in Physiology, Climat...
 

Recently uploaded

Pests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdfPests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdfPirithiRaju
 
Pests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPirithiRaju
 
Base editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editingBase editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editingNetHelix
 
Citronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyayCitronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyayupadhyaymani499
 
Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...
Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...
Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...D. B. S. College Kanpur
 
Thermodynamics ,types of system,formulae ,gibbs free energy .pptx
Thermodynamics ,types of system,formulae ,gibbs free energy .pptxThermodynamics ,types of system,formulae ,gibbs free energy .pptx
Thermodynamics ,types of system,formulae ,gibbs free energy .pptxuniversity
 
User Guide: Magellan MX™ Weather Station
User Guide: Magellan MX™ Weather StationUser Guide: Magellan MX™ Weather Station
User Guide: Magellan MX™ Weather StationColumbia Weather Systems
 
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests GlycosidesGLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests GlycosidesNandakishor Bhaurao Deshmukh
 
Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxpriyankatabhane
 
Microteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical EngineeringMicroteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical EngineeringPrajakta Shinde
 
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In DubaiDubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubaikojalkojal131
 
Introduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxIntroduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxMedical College
 
Servosystem Theory / Cybernetic Theory by Petrovic
Servosystem Theory / Cybernetic Theory by PetrovicServosystem Theory / Cybernetic Theory by Petrovic
Servosystem Theory / Cybernetic Theory by PetrovicAditi Jain
 
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...Universidade Federal de Sergipe - UFS
 
OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024innovationoecd
 
Pests of castor_Binomics_Identification_Dr.UPR.pdf
Pests of castor_Binomics_Identification_Dr.UPR.pdfPests of castor_Binomics_Identification_Dr.UPR.pdf
Pests of castor_Binomics_Identification_Dr.UPR.pdfPirithiRaju
 
Environmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial BiosensorEnvironmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial Biosensorsonawaneprad
 
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxmaryFF1
 
Topic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxTopic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxJorenAcuavera1
 
GENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptx
GENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptxGENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptx
GENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptxRitchAndruAgustin
 

Recently uploaded (20)

Pests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdfPests of Blackgram, greengram, cowpea_Dr.UPR.pdf
Pests of Blackgram, greengram, cowpea_Dr.UPR.pdf
 
Pests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdfPests of Bengal gram_Identification_Dr.UPR.pdf
Pests of Bengal gram_Identification_Dr.UPR.pdf
 
Base editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editingBase editing, prime editing, Cas13 & RNA editing and organelle base editing
Base editing, prime editing, Cas13 & RNA editing and organelle base editing
 
Citronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyayCitronella presentation SlideShare mani upadhyay
Citronella presentation SlideShare mani upadhyay
 
Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...
Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...
Fertilization: Sperm and the egg—collectively called the gametes—fuse togethe...
 
Thermodynamics ,types of system,formulae ,gibbs free energy .pptx
Thermodynamics ,types of system,formulae ,gibbs free energy .pptxThermodynamics ,types of system,formulae ,gibbs free energy .pptx
Thermodynamics ,types of system,formulae ,gibbs free energy .pptx
 
User Guide: Magellan MX™ Weather Station
User Guide: Magellan MX™ Weather StationUser Guide: Magellan MX™ Weather Station
User Guide: Magellan MX™ Weather Station
 
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests GlycosidesGLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
 
Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptx
 
Microteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical EngineeringMicroteaching on terms used in filtration .Pharmaceutical Engineering
Microteaching on terms used in filtration .Pharmaceutical Engineering
 
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In DubaiDubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
Dubai Calls Girl Lisa O525547819 Lexi Call Girls In Dubai
 
Introduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxIntroduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptx
 
Servosystem Theory / Cybernetic Theory by Petrovic
Servosystem Theory / Cybernetic Theory by PetrovicServosystem Theory / Cybernetic Theory by Petrovic
Servosystem Theory / Cybernetic Theory by Petrovic
 
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
REVISTA DE BIOLOGIA E CIÊNCIAS DA TERRA ISSN 1519-5228 - Artigo_Bioterra_V24_...
 
OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024OECD bibliometric indicators: Selected highlights, April 2024
OECD bibliometric indicators: Selected highlights, April 2024
 
Pests of castor_Binomics_Identification_Dr.UPR.pdf
Pests of castor_Binomics_Identification_Dr.UPR.pdfPests of castor_Binomics_Identification_Dr.UPR.pdf
Pests of castor_Binomics_Identification_Dr.UPR.pdf
 
Environmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial BiosensorEnvironmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial Biosensor
 
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptxECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
ECG Graph Monitoring with AD8232 ECG Sensor & Arduino.pptx
 
Topic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptxTopic 9- General Principles of International Law.pptx
Topic 9- General Principles of International Law.pptx
 
GENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptx
GENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptxGENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptx
GENERAL PHYSICS 2 REFRACTION OF LIGHT SENIOR HIGH SCHOOL GENPHYS2.pptx
 

SPSF04 - Euler and Runge-Kutta Methods

  • 1. 1 Programming, Computation, Simulation Applications in Math & Physics Euler and Runge-Kutta Methods Ordinary Differential Equations & Initial Value Problems Syeilendra Pramuditya Department of Physics Institut Teknologi Bandung
  • 2. Grid-based Computation  Euler-type Methods  Differential equations  Temporal domain (variation in time)  Initial conditions  Finite Difference Methods  Differential equations  Spatial domain (variation in space)  Boundary conditions: Von Neumann VS Dirichlet
  • 3. 3 Differential Equation 2 ( ) ( , ) 1 ( 0) 0 ( ) ..? dy y x f x y x dx y x y x        
  • 4. 4 Differential Equation 2 ( ) ( , ) 1 ( 0) 0 dy y x f x y x dx y x        2 3 3 Exact Solution ( 1) 1 3 ( 0) 0 0 1 ( ) ( , ) 3 dy x dx y x x C y x C y x f x y x x              
  • 5. 5 Differential Equation 1 ( ) ( , ) ( 1) 0 ( ) ..? dy y x f x y dx x y x y x       
  • 6. 6 Differential Equation 1 ( ) ( , ) ( 1) 0 dy y x f x y dx x y x       Exact Solution 1 ln( ) ( 1) 0 0 ( ) ( , ) ln( ) dy dx x y x C y x C y x f x y x           
  • 7. 7 Differential Equation 2 1 ( ) ( , ) 1 ( 0) 0 ..??? dy y x f x y x dx y y x y         
  • 8. Euler Methods  Linear approx. of Taylor series  “Simple Euler” 0 x x 0 ( ) f x ( ) f x   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ( ) ( ) ( ) ( , ) ( ) ( ) ( ) ( ) ( ) ( , ) ( ) ( ) ( , ( )) ( ) y x y x y x f x y x x y x y x x x y x x x h y x h y x hf x y y x h y x hf x y x y x h y hf                     0 0 0 ( ) ( , ) y y x f x y x     
  • 9. 9 Ordinary Differential Equation (ODE) 0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) ( , ) new old old old y x h y x hf x y y x h y hf y y hf x y          Solve the above ODE numerically (find y(x)) using Simple Euler method (for 1<x<10), use h = 1.0 and h = 0.5  How good the numerical solution is? 1 ( ) ( , ) ( 1) 0 dy y x f x y dx x y x      
  • 10. Simple Euler Code 0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) ( , ) new old old old y x h y x hf x y y x h y hf y y hf x y         Solve the ODE numerically (find y(x)) using Simple Euler method (for 1<x<10), use h = 1.0 and h = 0.5 1 ( ) ( , ) ( 1) 0 dy y x f x y dx x y x      
  • 11. Exact VS Numeric 0 0.5 1 1.5 2 2.5 3 0 2 4 6 8 10 Exact Euler, h = 1.0 Euler, h = 0.5
  • 12. Euler Methods  Linear approx. of Taylor series  “Modified Euler” Use more correct gradient 0 x x 0 ( ) f x ( ) f x   0 0 0 0 0 0 0 0 0 0 ( ) ( ) ( ) ( ) ( ) ( , ) 2 ( ) 2 2 ( ) mid mid mid mid mid mid mid y x y x x x y x y x h y x hf x y h x x h y y x h y y f y x h y hf                
  • 13. Modified Euler   0 0 0 0 0 0 0 0 0 0 ( ) ( ) ( ) ( ) ( ) ( , ) 2 ( ) 2 2 ( ) mid mid mid mid mid mid mid y x y x x x y x y x h y x hf x y h x x h y y x h y y f y x h y hf                
  • 14. Euler Methods  Linear approx. of Taylor series  “Improved Euler” Use more correct gradient 0 x x 0 ( ) f x ( ) f x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ( ) ( , ) ( ) ( , ) ( ) ( ) ( ) 2 ( , ) ( , ) 2 ( , ) ( , ( , )) ( ) ( ) avg avg avg y x f x y y x f x y y hf y x y x y x f x y f x y f f x y f x h y hf x y y x h y x hf                   
  • 15. Improved Euler 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ( ) ( , ) ( ) ( , ) ( ) ( ) ( ) 2 ( , ) ( , ) 2 ( , ) ( , ( , )) ( ) ( ) avg avg avg y x f x y y x f x y y hf y x y x y x f x y f x y f f x y f x h y hf x y y x h y x hf                   
  • 16. 2nd Order Runge-Kutta (RK2) 1 0 0 1 2 0 0 0 0 2 ( , ) ( , ) ( , ) 2 2 ( ) dy y f x y dx k hf x y k h k hf x y y x h y k          
  • 17. 4th Order Runge-Kutta (RK4)   1 0 0 2 0 0 1 3 0 0 2 4 0 0 3 0 0 1 2 3 4 4th Order Runge-Kutta ( , ) ( , ) ( , ) 2 2 ( , ) 2 2 ( , ) ( ) 2 2 6 dy y f x y dx k f x y h h k f x y k h h k f x y k k f x h y hk h y x h y k k k k                   
  • 18. Exact VS Numeric  Simple Euler (h = 0.2)
  • 19. Exact VS Numeric  Modified Euler (h = 0.2)
  • 20. Exact VS Numeric  Improved Euler (h = 0.2)
  • 21. Exact VS Numeric  RK4 (h = 0.2)
  • 22. 22 Block-Spring System ( ) ( , ) ( ) ( ) ( , ) ( ) F ma dv F k a x dt m m dv k k x v t f x t x t dt m m dx v x t f v t v t dt                 
  • 23. 23 Block-Spring System         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 1 1 ( ) ( ) ( ) ( ) ( , ) 1 1 ( ) ( ) ( ) ( ) ( , ) 1 1 2 2 t t v v at v t v v t t v t v t v f v t t t dv k v t v t v x dt m x x vt x t x x t t x t x t x f x t t t dx x t x t x v dt E mv kx                                           0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) y x h y x hf x y y x h y hf      
  • 24. 24 Block-Spring System (Simplified) 1 2 0 0 0 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 2 2 ( ) ( , ) ( ) ( ) ( , ) ( ) ( ) ( ) ( , ) ( ) ( , ) ( ) 1 1 2 2 dv k v t f t v x t dt m dx x t f t x v t dt kx t kx v t t v t f t v v t v t m m x t t x t f t x x tv t x tv E mv kx                                                  0 0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) y x h y x hf x y dy y x h y hf y h dx        
  • 25. 25 Block-Spring System (Simplified) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) 1 1 2 2 dv k v t x t dt m dx x t v t dt kx t kx v t t v t v t v t v t m m x t t x t x t x tv t x tv E mv kx                                                  0 0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) y x h y x hf x y dy y x h y hf y h dx        
  • 26. 26 Block-Spring System (Simplified) 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 ( ) ( ) ( ) 1 1 2 2 kx dv F v t t v t v a t v t v t dt m m k v t t v x t m dx x t t x t x v t dt E mv kx                               0 0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) y x h y x hf x y dy y x h y hf y h dx        
  • 27. 27 Block-Spring System 1 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 Simple Euler ( , ) ( ) ( ) ( ) ( , ) ( , ) ( , ) ( ) ( ) ( , ) ( ) ( , ) new old old new old dx x t x f t v t dt x t t x t x t x x tv t v x tv x x tv dv k v t v f t x t dt m kx t x kx v t t v t v t v v t v t m m v v t                                                         2 2 1 1 2 2 old kx m E mv kx        
  • 28. Block-Spring System  Analytic Solution ( ) cos( ) ( ) sin( ) m m x t x t v t v t         
  • 29. 29 Write a Simple Euler Code  m = k = 1  0 < t < 20 sec  dt = 0.2  x(t=0) = 1  v(t=0) = 0  Calculate x(t) and v(t) using Simple Euler  Output: time,x(t),x_exact,v(t),v_exact,Em 0 0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) y x h y x hf x y dy y x h y hf y h dx         0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 ( ) ( ) ( ) 1 1 2 2 kx dv F v t t v t v a t v t v t dt m m k v t t v x t m dx x t t x t x v t dt E mv kx                              
  • 30. Simple Euler Code 0 0 0 0 0 0 2 2 ( ) ( ) 1 1 2 2 k v t t v x t m x t t x v t E mv kx            
  • 32. Gnuplot Script # Script to plot 1D dataset reset unset label unset key set key left top set xrange [0:10] set yrange [-3:3] set title "Plot Image" set xlabel "X Value" set ylabel "Y Value" set terminal wxt size 600,400 font "Verdana,10" plot 'output.txt' using 2:3 title "Numeric" with linespoints pointtype 6 lw 1 lc 7, 'output.txt' using 2:4 title "Analytic" with linespoints pointtype 6 lw 1 lc 6
  • 36. 36 Block-Spring System 1 2 0 0 1 0 0 0 0 0 2 0 0 0 0 0 1 0 0 2 Modified Euler ( , ) ( ) ( ) ( , ) ( ) ( ) ( ) ( ) 2 2 2 ( ) ( ) 2 2 2 ( ) ( ) ( ) ( ) mid mid mid mid dx x t x f t v t dt dv k v t v f t x t dt m t t t x x t x f t x v t t t k v v t v f t v x m x t t x t f t v t t v t f t                                            
  • 40. Mass-Spring System  2nd Order Runge-Kutta (RK2) 1 0 0 1 2 0 0 0 0 2 ( ) ? ( , ) ( , ) ( , ) 2 2 ( ) q t dq q f t q dt k dt f t q k dt k dt f t q q t dt q k              1 0 0 1 2 0 0 0 0 2 ( ) ? ( , ) ( , ) ( , ) 2 2 ( ) y x dy y f x y dx k hf x y k h k hf x y y x h y k            y(x) x q(t) t
  • 41. Mass-Spring System  2nd Order Runge-Kutta (RK2) 1 ( ) ? ( , ) ( ) x t dx x f t x v t dt      x(t) t v(t) t 2 ( ) ? ( , ) ( ) v t dv k v f t v x t dt m      
  • 42. Mass-Spring System  2nd Order Runge-Kutta (RK2) 1 0 0 1 2 0 0 0 0 2 ( ) ? ( , ) ( , ) ( , ) 2 2 ( ) q t dq q f t q dt k dt f t q k dt k dt f t q q t dt q k              1 1 1 2 1 2 2 ( ) ( ) ( ) ( ) ( ) ( ) 2 2 ( ) ( ) ( ) ( ) 2 2 2 ( ) ( ) 2 ( ) ( ) ( ) ( ) ( ) 2 dx x f t v t dt k t f t t v t t t k t f t t v t t t t k v t v t v v t x t m t k k t v t x t m t k x t t x t k x t t v t x t m                                                              
  • 43. Mass-Spring System  2nd Order Runge-Kutta (RK2) 1 0 0 1 2 0 0 0 0 2 ( ) ? ( , ) ( , ) ( , ) 2 2 ( ) q t dq q f t q dt k dt f t q k dt k dt f t q q t dt q k              2 1 2 2 2 2 2 ( ) ( ) ( ) ( ) ( ) ( ) 2 2 ( ) ( ) ( ) ( ) 2 2 2 ( ) ( ) 2 ( ) ( ) ( ) ( ) ( ) 2 dv k v f t x t dt m k k t f t t x t m t k t k t f t t x t m t t t x t x t x x t v t k t k t x t v t m k t v t t v t k v t t x t v t m                                                             
  • 47. 4th Order Runge-Kutta (RK4)   1 0 0 2 0 0 1 3 0 0 2 4 0 0 3 0 0 1 2 3 4 ( , ) ( , ) ( , ) 2 2 ( , ) 2 2 ( , ) ( ) 2 2 6 dy y f x y dx k f x y h h k f x y k h h k f x y k k f x h y hk h y x h y k k k k                    1 2 ( ) ( ) ( ) ( ) ( ) ? ( ) ? dx x f t v t dt dv k v f t x t dt m x t dt v t dt             
  • 49. 49 Damped Mass-Spring System F ma kx cv dv F kx cv a dt m m dv k c x v dt m m dx v dt             
  • 50. 50 Damped Mass-Spring System           0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 1 1 ( ) ( ) ( ) ( ) ( , ) 1 1 ( ) ( ) ( ) ( ) ( , ) 1 1 2 2 t t v v at v t v v t t v t v t v f v t t t dv v t v t v x cv dt x x vt x t x x t t x t x t x f x t t t dx x t x t x v dt E mv kx                                           
  • 51. 51 Damped Oscillation  m = k = 1  0 < t < 20 sec  dt = 0.2  x(t=0) = 1  v(t=0) = 0  c = 0.15  Calculate x(t) and v(t) using Euler Method  Output: time,x(t),x_exact,v(t),v_exact,Em 0 0 0 0 0 0 0 0 ( ) ( ) ( , ) ( ) y x h y x hf x y dy y x h y hf y h dx         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 ( ) ( ) ( ) 1 1 2 2 kx cv dv F v t t v t v a t v t v t dt m m kx cv v t t v t m dx x t t x t x v t dt E mv kx                                 
  • 52. 52 Damped Oscillation (Mod. Euler) -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 1.2 0 5 10 15 20 TIme Position
  • 53. Damped Oscillation: Analytical Solution  Halliday-Resnick, Chapter 15
  • 54. Type of Damped Oscillation
  • 55. Type of Damped Oscillation
  • 56. LC Oscillation 2 2 0 d x k x dt m  
  • 57. Damped LC Oscillation (RLC Circuit)  The RLC Circuit 2 2 0 d x c dx k x dx m dt m   
  • 58. Self-Practice for Interested Students  Ideal/undamped oscillating systems  Mass-spring systems  RLC systems  Modified / Improved Euler Methods  RK2 / RK4 Methods  Damped oscillating systems  Mass-spring systems  RLC systems  Modified / Improved Euler Methods  RK2 / RK4 Methods  Underdamped / Overdamped / Critically damped