Comp Phys6
Comp Phys6
December 5, 2016
h2 00
y (x) = y (x0 + h) = y (x0 ) + hy 0 (x0 ) + y (x0 ) + (2)
2
where h = x x0 .
Thus we need to provide the coefficients:
y 0 (x0 ) = y 0 (0) = 0 + 1 = 1
y 00 = 1 + y 0 = 1 + x + y = 1 + y 0
y 00 (x0 ) = 1 + y 0 (0) = 2
y 000 = 1 + y0
000
y (x0 ) = 1 + y 0 (0) = 2
y (4) = 1 + y0
y (4) (x0 ) = 1 + y 0 (0) = 2
Thus
h3 h4
y (0 + h) = 1 + h + h2 + + + (5)
3 12
and the error will be
y (5) () 5
E= h for 0<<h (6)
5!
Numerical Integration of ODEs
Taylor series : Example
yn+1 = yn + h (a + b) fn + h2 (A b fx + B b f fy )n (25)
1
yn+1 = yn + (k1 + k2 ) (27)
2
where
k1 = hf (xn , yn ) , k2 = hf (xn + h, yn + k1 ) (28)
which is Euler-Heuns method.
1
Here we use: f (xn + Ah, yn + Bhf (xn , yn )) (f + fx Ah + fy Bhf )x=xn
Numerical Integration of ODEs
4th order Runge - Kutta Method
If we repeat the same procedure for a Taylor series up to h4 , we will
create a system of 11 equations with 13 unknowns.
Then with the appropriate choice of two of them we come to a
recurrence relation of the form :
1
yn+1 = yn + (k1 + 2k2 + 2k3 + k4 ) (29)
6
where
k1 = hf (xn , yn ) (30)
1 1
k2 = hf xn + h, yn + k1 (31)
2 2
1 1
k3 = hf xn + h, yn + k2 (32)
2 2
k4 = hf (xn + h, yn + k3 ) (33)
This the 4th order Runge - Kutta with local error E O(h5 ) and global
error after n steps E O(h4 ).
Numerical Integration of ODEs
4th order Runge - Kutta - Merson Method
In this method the order is not given by the number of ks, but by the
global error:
k1 = hf (xn , yn ) (34)
1 1
k2 = hf xn + h, yn + k1 (35)
3 3
1 1 1
k3 = hf xn + h, yn + k1 + k2 (36)
2 6 6
1 1 3
k4 = hf xn + h, yn + k1 + k3 (37)
2 8 8
1 3
k5 = hf xn + h, yn + k1 k3 + 2k4 (38)
2 3
1
yn+1 = yn + (k1 + 4k4 + k5 ) + O(h5 ) (39)
6
ERROR:
1
E= (2k1 9k3 + 8k4 k5 ) (40)
30
Numerical Integration of ODEs
Runge - Kutta - Fehlberg Method
k1 = hf (xn , yn ) (41)
1 1
k2 = hf xn + h, yn + k1 (42)
4 4
3 3 9
k3 = hf xn + h, yn + k1 + k2 (43)
8 32 32
12 1932 7200 7296
k4 = hf xn + h, yn + k1 k2 + k3 (44)
13 2197 2197 2197
439 3680 845
k5 = hf xn + h, yn + k1 8k2 + k3 k4 (45)
216 513 4104
1 8 3544 1859 11
k6 = hf xn + h, yn k1 + 2k2 k3 + k4 k5(46)
2 27 2565 4104 40
Then a first estimation for yn+1 is:
25 1408 2197 1
y n+1 = yn + k1 + k3 + k4 k5 (47)
216 2565 4104 5
here the local error is h5 .
Numerical Integration of ODEs
The next step will include k6 and gives:
16 6656 28561 9 2
yn+1 = yn + k1 + k3 + k4 k5 + k6 (48)
135 12825 56430 50 55
1 h3
yn+1 = yn + hyn0 + yn00 h2 + y 000 ()
2 6
0
yn0 h3
0 1 y n+1 h 000
= yn + hyn + y () h2 + y 000 ()
2 h 2 6
3
1 0 0
h 000
= yn + yn + yn+1 y () (54)
2 12
Did you ever met this relation again?
Numerical Integration of ODEs
NOTE: Can you prove the following expression?
h 0
h4 (4)
yn+1 = yn + 5yn+1 + 8yn0 + yn1
0
y (55)
12 24
or
h h4
yn+1 = yn + (5fn+1 + 8fn + fn1 ) y (4) (56)
12 24
HINT
The previous relations suggest that we can use (appropriately) the
methods that we developed for the numerical evaluation of integrals in
order to derive more accurate relations.
The typical way was to integrate the term on the right of (51) by using an
approximate form of f (x, y ) e.g. using an interpolating polynomial in x.
NOTE: In deriving this we have to use several past points.
4h
(2fn fn1 + 2fn2 ) + O h5
yn+1 = yn3 + (62)
3
ERROR TERM
28 5 (5)
E h y () , xn3 xn+1 (63)
90
This 2nd step can be repeated a few times until the two corrected
values converge i.e. until
(j) (j+1)
yk+1 yk+1 < E
h 251 5 (5)
yk+1 = yk + (55fk 59fk1 + 37fk2 9fk3 ) + h y (1 ) (71)
24 720
CORRECTION (xk2 < 2 < xk+1 )
h 19 5 (5)
yk+1 = yk + (9fk+1 + 19fk 5fk1 + fk2 ) h y (2 ) (72)
24 720
Hamming Method
PREDICTION (xk3 < 1 < xk+1 )
4h 28
yk+1 = yk3 + (2fk2 fk1 + 2fk ) + h5 y (5) (1 ) (73)
3 90
CORRECTION (xk2 < 2 < xk+1 )
1 3h
yk+1 = (9yk yk2 ) + (fk1 + 2fk + fk+1 ) (74)
8 8
l1 = h g (xn , yn , zn ) (81)
1 1 1
l2 = h g (xn + h, yn + k1 , z n + l1 ) (82)
2 2 2
1 1 1
l3 = h g xn + h, yn + k2 , zn + l2 (83)
2 2 2
l4 = h g (xn + h, yn + k3 , zn + l3 ) (84)
yn = c1 Z1n + c2 Z2n
24/9
h<
|fy (xn , yn )|
If we wish to have yc and y the same to within one in the Nth decimal
places, then
D rD
y yc = yp + (yp + D) = < 10N
1r 1r
The previous criteria were derived for the Adams - Moulton method.
Similar criteria can be found for the Milne method :
1st convergence criterion :
3
h<
|fy (xn , yn )|
NOTE: These criteria are for a single 1st order ODE only. A similar
analysis for a system is much more complicated.
The previous error analysis examined the error of a single step only,
the so called local truncation error.
The accumulation of these errors, termed as the global truncation
error is important.
There are other sources of error in addition to the truncation error.
Original data errors : If the initial conditions are not known exactly
or exressed inexactly as terminated decimal number, the solution will be
affected to a greater or lesser degree depending on the sensitivity of the
equation.
Round-off errors : Both floating-point and fixed-point calculations
in computers are subject to round off errors.
Truncation errors of the method: These are the types of error
due to the use of truncated series for approximation in our work, when
infinite series is needed for exactness.
0 = 0
1 1
1 (1 + hk)0 + h2 y 00 (0 ) = h2 y 00 (0 )
2 2
1 2 00 1 2 00 1
2 (1 + hk) h y (0 ) + h y (1 ) = h2 [(1 + hk)y 00 (0 ) + y 00 (1 )]
2 2 2
1 2
h (1 + hk)2 y 00 (0 ) + (1 + hk)y 00 (1 ) + y 00 (2 )
3
2
1 2
h (1 + hk)n1 y 00 (0 ) + (1 + hk)n2 y 00 (1 ) + ... + y 00 (n1 )
n
2
If k 0 the truncation error at every step is propagated to the next
step after beingamplified by the factor (1 + hk). Finally, for h 0 the
error at any point is the sum of all previous errors.
If the fy is negative and of magnitude such that kh 2 the errors are
propagated with diminishing effect.
1
|n+1 | (1 + hk)|n | + h2 M
2
which is a difference equations of the form:
1
Zn+1 = (1 + hk)Zn + h2 M with Z0 = 0
2
With obvious solution
hM hM
Zn = (1 + hk)n
2k 2k
since 1 + hk < e hk for k > 0 we get
hM hk n hM hM nhk hM (xn x0 )k
Zn < e = e 1 = e 1 = O(h)
2k 2k 2k 2k
It follows that the global error n is O(h)
Numerical Integration of ODEs