1.
Part 7:
Ordinary Differential Equations
–
–
–
–
–
Runge-Kutta Methods
Euler’s Method
Heun’s Method
Midpoint method
Systems of Equations
2.
Runge-Kutta Methods
We want to solve an ordinary differential equation of the form:
y
'
dy
f ( x, y )
dx
The general approach of the solution is in the form of:
(new value)=(old value) + (slope) x (step size)
All of the one-step methods under this
general category are called RungeKutta methods.
> Euler’s method
> Heun’s method
> Midpoint method
The differences in these methods are
in the way (slope) is defined.
Slope=
yi
xi
xi
1
1
yi
h
3.
Euler’s Method
Simplest way of approximating the slope is in the form of first
derivative. Apply forward scheme finite difference for the starting
point:
y
yi
'
yi
1
h
predicted
f ( xi , yi )
yi
Then,
yi
1
yi
f ( xi , y i ) h
Euler’s
method
formula
where f(xi, yi) is calculated from
the initial condition.
1
true
yi
xi
xi
1
That is the slope at the beginning is approximated as the slope
over the entire interval.
As in the forward scheme finite difference method, error for this
approximation is O(h).
4.
EX: Use Euler’s method to solve
dy
2x
3
12 x
2
20 x
8 .5
dx
from x=0 to x=2 with a step size of 0.5. The initial condition at x=0 is y=1.
Differential equation: f ( x , y )
Using Euler’s formula:
y ( 0 .5 )
y (0)
f ( 0 ,1) 0 . 5
2x
3
12 x
5 . 25
2
20 x
t
8 .5
63 . 1 %
Second step:
y (1)
y ( 0 .5 )
f ( 0 . 5,5 . 25 ) 0 . 5
5 . 875
t
95 . 8 %
Other steps:
y (1 . 5 )
5 . 1250
y ( 2 .0 )
4 . 5000
t
t
131 %
125 . 0 %
Error can be reduced by using a smaller step size (h).
Considering that Euler’s method has an error O(h), halving the step size will
halve the error.
5.
Heun’s Method
It is an improvement of Euler’s method.
Improve the slope of the interval by averaging derivatives at the
starting and end points.
Slope=f(xi+1’ yi+10)
Slope=[f(xi’ yi)+f(xi+1’ yi+10)]/2
Slope=f(xi’ yi)
xi
Predictor
xi
1
xi
Corrector
xi
1
6.
Approximate the slope at the starting point using Euler’s method
y
'
f ( x, y )
Extrapolate linearly to find y at the end point:
0
yi
yi
1
f ( xi , y i ) h
standard Euler method stops here.
This intermediate solution (predictor) is used to calculate the slope
at the end point:
'
0
yi
f ( xi 1 , yi 1 )
1
Calculate average of the two slopes at the starting and end points:
'
'
yi
'
y
yi
1
2
Use this slope to re-calculate y value at the end point (corrector):
'
yi
1
yi
yh
7.
0
Predictor:
Corrector:
yi
yi
1
yi
1
yi
f ( xi , y i ) h
f ( xi , y i )
0
f ( xi 1 , y i 1 )
h
Heun’s
method
2
Corrector equation involves yi+1 on both sides, which means that it
can be applied iteratively for the end point (i.e., older
approximation can be used iteratively to calculate a new
approximation).
The iteration does not necessarily converge to the true solution
but approaches a solution with a finite truncation error.
The method is accurate to O(h2).(compare to O(h) accuracy of
Euler’s method).
8.
EX: Use Heun’s method to numerically solve the following ODE
y
'
4e
0 .8 x
0 .5 y
from x=0 to x=4 with a step size of h=1. Initial condition is (0,2).
Calculate the slope at the starting point (x=0):
'
y0
4e
0
0 .5 ( 2 )
3
Apply Euler’s (predictor) formula to evaluate y10
0
y1
2
3 (1)
5
t
25 . 3 %
Calculate slope at the end point (x=1)
'
0
y1
f ( x1 , y 1 )
4e
0 . 8 (1 )
0 .5 (5 )
Calculate average of the two slopes:
'
y
3
6 . 401164
2
4 . 701082
6 . 402164
Euler’s
method
9.
Use the corrector formula to calculate the new prediction at x=1:
y1
2
4 . 701082 (1)
6 . 701082
t
8 . 18 %
Above is based on a single iteration at y1. Apply another iteration to refine the
predictor:
y1
2
[3
4e
0 . 8 (1 )
0 . 5 ( 6 . 701082 )]
6 . 275811
t
1 . 31 %
6 . 382129
t
3 . 03 %
2
Further correction:
y1
2
[3
4e
0 . 8 (1 )
Results for all the
points from x=0 to x=4:
(15 iterations at each point)
0 . 5 ( 6 . 275811 )]
2
x
y (true)
y (Heun)
0
2.0000000
2.0000000
0.00
1
6.1946314
6.360866
2.68
2
14.843922
15.302237
3.09
3
33.677172
34.743276
3.17
4
75.338963
77.735096
3.18
t(%)
10.
Midpoint Method
It is another improvement of Euler’s method.
Approximate y at the midpoint of the interval, and use it for the
average slope of the entire interval.
Slope=f(xi+1/2’ yi+1/2)
Slope=f(xi+1/2’ yi+1/2)
xi
xi
yi
1/ 2
yi
f ( xi , yi )
Predictor
xi
1/ 2
h
2
yi
1
yi
f ( xi
1/ 2
Corrector
xi
, yi
1
1/ 2
)h
11.
No iteration can be made for the corrector.
Just as the centered difference is superior to forward or backward
difference schemes, midpoint is superior to Euler’s method in the
same manner.
Euler’s method
Midpoint method
O(h)
O(h2)
truncation error
Summary:
All the three methods, Euler’s, Heun’s (without iteration), and
midpoint methods, mentioned so far are under the general
category of one-step approaches called Runge-Kutta methods.
Heun’s and midpoint methods are generally superior to Euler’s
method, even though they require somewhat more calculations.
12.
Systems of Equations
Problems requiring the solution of a system of ODE’s are very
common in engineering applications.
dy 1
dx
dy 2
dx
f 1 ( x , y 1 , y 2 ,..., y n )
f 2 ( x , y 1 , y 2 ,..., y n )
....
dy n
dx
n- initial conditions
need to be known
at the starting
value of x
f n ( x , y 1 , y 2 ,..., y n )
Euler’s Method:
Simply apply Euler’s method for each equation at each step.
Strcictly apply the one-step Euler’s formula for every equation
before proceeding to the next-step (i.e., do not update any
variable during a single step).
13.
EX: Solve the following system of ODEs using Euler’s method.
dy 1
dy 2
0 .5 y1
dx
dx
4
0 .3 y 2
0 .1 y1
Assume that for x=0, y1=4, and y2=6. Integrate to x=2 with a step size h=0.5.
Apply Euler’s method:
y1 ( 0 . 5 )
4
y 2 ( 0 .5 )
6
0 .5 ( 4 ) 0 .5
4
0 .3( 6 )
3
0 . 1( 4 ) 0 . 5
6 .9
Other points are calculated in the same fashion. Results to x=2 are below:
x
y1
y2
0
4
6
0.5
3
6.9
1.0
2.25
7.715
1.5
1.6875
8.44525
2.0
1.265625
9.094087
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.
Be the first to comment