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

Fuzzylogic application aircraft landing
Fuzzylogic application aircraft landingFuzzylogic application aircraft landing
Fuzzylogic application aircraft landingSubin Subair C P
 
Newton’s Forward & backward interpolation
Newton’s Forward &  backward interpolation Newton’s Forward &  backward interpolation
Newton’s Forward & backward interpolation Meet Patel
 
APPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATIONAPPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATIONDhrupal Patel
 
Runge Kutta Method
Runge Kutta Method Runge Kutta Method
Runge Kutta Method Bhavik Vashi
 
Fourier Series - Engineering Mathematics
Fourier Series -  Engineering MathematicsFourier Series -  Engineering Mathematics
Fourier Series - Engineering MathematicsMd Sadequl Islam
 
Partial Differentiation & Application
Partial Differentiation & Application Partial Differentiation & Application
Partial Differentiation & Application Yana Qlah
 
Euler's Method
Euler's MethodEuler's Method
Euler's Methoddmidgette
 
Partial Differential Equation - Notes
Partial Differential Equation - NotesPartial Differential Equation - Notes
Partial Differential Equation - NotesDr. Nirav Vyas
 
presentation on Euler and Modified Euler method ,and Fitting of curve
presentation on Euler and Modified Euler method ,and Fitting of curve presentation on Euler and Modified Euler method ,and Fitting of curve
presentation on Euler and Modified Euler method ,and Fitting of curve Mukuldev Khunte
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functionsTarun Gehlot
 
Partial differential equation &amp; its application.
Partial differential equation &amp; its application.Partial differential equation &amp; its application.
Partial differential equation &amp; its application.isratzerin6
 
Numerical Analysis (Solution of Non-Linear Equations)
Numerical Analysis (Solution of Non-Linear Equations)Numerical Analysis (Solution of Non-Linear Equations)
Numerical Analysis (Solution of Non-Linear Equations)Asad Ali
 

What's hot (20)

Fuzzylogic application aircraft landing
Fuzzylogic application aircraft landingFuzzylogic application aircraft landing
Fuzzylogic application aircraft landing
 
1532 fourier series
1532 fourier series1532 fourier series
1532 fourier series
 
Newton’s Forward & backward interpolation
Newton’s Forward &  backward interpolation Newton’s Forward &  backward interpolation
Newton’s Forward & backward interpolation
 
APPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATIONAPPLICATION OF PARTIAL DIFFERENTIATION
APPLICATION OF PARTIAL DIFFERENTIATION
 
Runge kutta
Runge kuttaRunge kutta
Runge kutta
 
Calculus of variations
Calculus of variationsCalculus of variations
Calculus of variations
 
Runge Kutta Method
Runge Kutta Method Runge Kutta Method
Runge Kutta Method
 
Legendre functions
Legendre functionsLegendre functions
Legendre functions
 
Lagrangian formulation 1
Lagrangian formulation 1Lagrangian formulation 1
Lagrangian formulation 1
 
Z transfrm ppt
Z transfrm pptZ transfrm ppt
Z transfrm ppt
 
Fourier Series - Engineering Mathematics
Fourier Series -  Engineering MathematicsFourier Series -  Engineering Mathematics
Fourier Series - Engineering Mathematics
 
Partial Differentiation & Application
Partial Differentiation & Application Partial Differentiation & Application
Partial Differentiation & Application
 
Euler's Method
Euler's MethodEuler's Method
Euler's Method
 
Jacobi method
Jacobi methodJacobi method
Jacobi method
 
Partial Differential Equation - Notes
Partial Differential Equation - NotesPartial Differential Equation - Notes
Partial Differential Equation - Notes
 
presentation on Euler and Modified Euler method ,and Fitting of curve
presentation on Euler and Modified Euler method ,and Fitting of curve presentation on Euler and Modified Euler method ,and Fitting of curve
presentation on Euler and Modified Euler method ,and Fitting of curve
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functions
 
Partial differential equation &amp; its application.
Partial differential equation &amp; its application.Partial differential equation &amp; its application.
Partial differential equation &amp; its application.
 
Numerical Analysis (Solution of Non-Linear Equations)
Numerical Analysis (Solution of Non-Linear Equations)Numerical Analysis (Solution of Non-Linear Equations)
Numerical Analysis (Solution of Non-Linear Equations)
 
Lyapunov stability
Lyapunov stability Lyapunov stability
Lyapunov stability
 

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

Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxAleenaTreesaSaji
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxAArockiyaNisha
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfnehabiju2046
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 sciencefloriejanemacaya1
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzohaibmir069
 

Recently uploaded (20)

Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptx
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdf
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 science
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
 
The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistan
 

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