You are on page 1of 18

Ordinary

Differential
Equations
Ordinary Differential Equations
• Example:
x – independent variable
dy
 kx y – dependent variable
dx
First order ODE, dependent variable
y '  kx function of one independent variable
• Other examples:
Pendulum: Vibrating mass on spring:
l ' ' g sin   0 my ' 'ky  0
• ODEs can be used to “model” behavior
• Higher order ODEs can always be expressed as 1st order
y '  f( x, y )
Numerical Solution of ODE
Initial Value Problems
 Basic Concepts
– Explicit - Implicit (iterative)
– One-step (self starting) - Multi-step (non self-starting)
– Order
– Stability

 Basic methods to know


– Euler (simplest explicit)
– Runge-Kutta 4 (most often used RK method)
– Heun
– Iterated Heun (simplest predictor-corrector)
Solutions y
• General solutions or level curves
e.g. y ' cos x x

• Particular solution specified by initial value


y ( xo )  y0
• In general: y '  f( x, y )
x
 y   f( x, y )dx  y0
x0
• Separable ODEs

f( x, y )  h( x)
y x

g( y ) So: 
y0
g( y )dy   h( x)dx
x0
Solutions
• Closed form solutions:y  f(x)
e.g. y '  y where: y (0)  1
Not a closed form
gives: y  e  1  x  ...
x
solution
• What should we do when no suitable closed form solution exists?
Answer: form a numerical model of the ODE to give approximate
y values at a number of x points.
• Advantages of a numerical model:
Can handle any ODE, quickly generate solutions without
extensive math, good for solving on computers.
• Disadvantages of a numerical model:
Stability (solution can be badly behaved – thus, inaccurate),
accuracy (can be well-behaved but inaccurate).
Numerical Solutions
• Initial value problems: y ( x0 )  y0
• Step by step methods:
Use information from
current position, not future
• General solution stepping from x0 to x1  x0  h is:
x1
y ( x1 )  y ( x0 )   f( x, y )dx
x0
don’t know know ?
• Modelling challenge:
x1
Represent or approximate: x0
f( x, y )dx
Euler’s Method
• Assume that from x0 to x1
f( x, y )  f( x0 , y0 )
• Integration becomes:
x1 x1
x0
f( x, y )dx   f( x0 , y0 )dx
x0
x1
 f( x0 , y0 )  dx  h f( x0 , y0 )
x0

so that:
y ( x1 )  y ( x0 )  h f( x0 , y0 )
Euler’s Method
• Geometric interpretation:
f(x,y)
y

polygon approx to y and


x constant approximation to f(x,y)

• Reasonable model/approximation if y is smooth and not


varying fast.
• A sequence of steps gives the solution at discrete points.
Euler’s Method
y
xi 1  xi  h
yi 1  yi  f ( xi , yi )h f ( xi , yi )h

Explicit x
One-step
First Order
Stability (depends very much on f and the step size)
Heun (without iteration)
xi 1  xi  h
h
yi 1  yi  [ f ( xi , yi )  f ( xi  h, y 0i1 )]
2
where
y 0i1  yi  hf ( xi , yi )
Predictor - Corrector (but still explicit)

One-step

Second order

Stability (depends on the step size, better than Euler)


xi 1  xi  h
Iterated
h
Heun  yi  [ f ( xi , yi )  f ( xi  h, y ik11 )]
k
y i 1
2
k  1,2...
where
y 0i1  yi  hf ( xi , yi )

Predictor - Corrector (implicit, iterative)


Needs a stopping criterion
One-step
Second order
Stability is good
xi 1  xi  h
Runge-Kutta 4 h
yi 1  yi  (k1  2k 2  2k3  k 4 )
6
where
(RK4) k1  f ( xi , yi )
h h
k 2  f ( xi  , yi  k1 )
2 2
h h
k3  f ( xi  , yi  k 2 )
2 2
Explicit
k 4  f ( xi  h, yi  k3h)
One-step
Fourth Order !!!
Stability depends somewhat on f and step size)
Final comment

 Using smaller values of h and using Euler’s


or Heun’s methods probably gives better
accuracy than using RK4 with larger values
of h

You might also like