Professional Documents
Culture Documents
yn+1 = yn + hf (xn , yn )
xn+1 = xn + h = x0 + (n + 1)h, n = 0, 1, 2, . . . .
(a) As the truncation is performed after the first term of the Taylor series of y(x), Eulers method is
a first order method with TE = O(h2 ). This error is a local error as it applies at each and every
step as the solution develops.
(b) The global error , which applies to the final solution is O(h), since the number of operations
1
would be proportional to .
h
36
Example 30. Consider the IVP
y 0 = x + y, y(0) = 1.
(a) Use Eulers method to obtain a five-decimal approximation to y(0.5) using the step size h = 0.1.
(b) (i) Estimate the truncation error in your approximation to y(0.1) using the next two terms in
the corresponding Taylor series.
(ii) The exact value for y(0.1) is 1.11034 (to 5 decimal places) . Calculate the error between
the actual value y(0.1) and your approximation y1 . How does this error compare with the
truncation error you obtained in (i)?
(c) The exact value for y(0.5) is 1.79744 (to 5 decimal places) . Calculate the absolute error between
the actual value y(0.5) and your approximation y5 .
37
Example 31. Given that the exact solution of the initial-value problem
y 0 = x + y, y(0) = 1
is y(x) = 2ex x 1. The following table shows
(a) the approximate values obtained by using Eulers method with step size h = 0.1
(b) the approximate values with h = 0.05, and the actual values of the solution at the points
x = 0.1, 0.2, 0.3, 0.4, 0.5 :
38
Example 32. Use Improved Eulers method with step size h = 0.1 to approximate the solution of the
IVP
y 0 = x + y, y(0) = 1
on the interval [0, 1]. The exact solution is y(x) = 2ex x 1. Make a table showing the approximate
values , the actual values together with the absolute errors.
39
7.1.3 Taylor Series Method of Order p
h2 00 h3 (3) hp
yn+1 = yn + hyn0 + yn + yn + + yn(p)
2! 3! p!
Example 33.
40
Example 34. Consider y 0 = x + y, y(0) = 1. Use Runge-Kutta method of order 4 to obtain an
approximation to y(0.2) using the step size h = 0.1.
41
7.1.5 Multi-step Methods
The methods of Euler, Heun, and RK are called one-step methods because the approximation for
the mesh point xn+1 involves information from only the previous mesh point, xn . That is, only the
initial point (x0 , y0 ) is used to compute (x1 , y1 ) and in general, yn is needed to compute yn+1 .
Methods which use more than one previous mesh points to find the next approximation are called
multi-step methods.
Example 35. Use the Adams-Bashforth/Adams-Moulton Method with h = 0.2 to obtain an approx-
imation to y(0.8) for the solution of
y 0 = x + y, y(0) = 1.
Answer . With h = 0.2, y(0.8) y4 . We use the RK4 method as the starter method, with x0 =
0, y0 = 1 to obtain
(a) y1 = 1.242800000
(b) y2 = 1.583635920
(c) y3 = 2.044212913
(d) fn = f (xn , yn ) = xn + yn
f0 = x0 + y0 = 0 + 1 = 1
f1 = x1 + y1 = 0.2 + 1.242800000 = 1.442800000
f2 = 0.4 + 1.583635920 = 1.983635920
f3 = 0.6 + 2.044212913 = 2.644212913
0.2 0.2
(e) y4 = y3 + (55f3 59f2 + 37f1 9f0 ) = 2.044212913 + (55(2.644212913) 59(1.983635920) +
24 24
37(1.442800000) 9(1)) = 2.650719504
(f) f4 = f (x4 , y4 ) = x4 + y4 = 0.8 + 2.650719504 = 3.450719504
0.2
(g) y4 = y3 + (9f4 + 19f3 5f2 + f1 ) = 2.651055757 y(0.8)
24
42
7.1.7 Summary:Orders Of Errors For Different Methods
Method order Local TE Global TE
Euler 1 O(h2 ) O(h)
Heun 2 O(h3 ) O(h2 )
Second-Order Taylor Series 2 O(h3 ) O(h2 )
Third-Order Taylor Series 3 O(h4 ) O(h3 )
Fourth-Order Runge-Kutta 4 O(h5 ) O(h4 )
Adams-Bashforth/Adams-Moulton 4 O(h5 ) O(h4 )
43
7.2 Higher-Order Initial Value Problems
The methods use to solve first order IVPs can be applied to higher order IVPs because a higher IVP
can be replaced by a system of first-order IVPs. For example, the second-order initial value problem
can be decomposed to a system of two first-order initial value problems by using the substitution
y0 = u :
y0 = u , y(x0 ) = y0
u = f (x, y, u) , u(x0 ) = y00
0
Each equation can be solved by the numerical techniques presented earlier. For example, the Euler
method for this system would be
yn+1 = yn + hun
un+1 = un + hf (xn , yn , un )
Remark. The Euler method for a general system of two first order differential equations,
u0 = f (x, y, u) , u(x0 ) = u0
y 0 = g(x, y, u) , y(x0 ) = y0
is given as follows
un+1 = un + hf (xn , yn , un )
yn+1 = yn + hg(xn , yn , un )
Reading Assignment 7.2.1. Use the Euler method to approximate y(0.2) and y 0 (0.2) in two steps,
where y(x) is the solution of the IVP
y 00 + xy 0 + y = 0, y(0) = 1, y 0 (0) = 2.
y0 = u
0
u = xu y
yn+1 = yn + 0.1un
un+1 = un + 0.1(xn un yn )
44
= h (zi+K'1/2)
= h (zi+K'2/2)
= h (zi+K'3/2)
-0.062
0.031
7.2.1 The Linear Shooting Method
Consider the linear second order BVP
with boundary conditions y(a) = , y(b) = . The shooting method replaces the BVP by two IVPs
in the following way:
(a) Let y1 be the solution of the IVP
Replace this second-order IVP by a system of two first-order IVPs. Then solve each of the two
first-order IVPs using, say, the fourth-order Runge-Kutta method to obtain y1 .
(b) Let y2 be the solution of the IVP
45
Example 36. Use the shooting method (together with the fourth-order Runge-Kutta method with
1
h = ) to solve the BVP
3
y 00 = 4(y x), 0 x 1, y(0) = 0, y(1) = 2.
Answer .
y0 =
00 0 u , y(0) = 0 [1]
(a) y = 4(y x), y(0) = 0, y (0) = 0 0
u = 4(y x) , u(0) = 0 [2]
(i) Use RK4 to solve [1] and [2] : we obtain
y1 ( 13 ) = 0.02469136, y1 ( 23 ) = 0.21439821 and y1 (1) = 0.80973178
y 0 = u , y(0) = 0 [3]
00 0
(b) y = 4y, y(0) = 0, y (0) = 1
u0 = 4y , u(0) = 1 [4]
(i) Use RK4 to solve [3] and [4] : we obtain
y2 ( 31 ) = 0.35802469, y2 ( 23 ) = 0.88106488 and y2 (1) = 1.80973178
2 y1 (1) 2 + 0.80973178
(c) y(x) = y1 (x) + y2 (x) = y1 (x) + y2 (x)
y2 (1) 1.80973178
y( 31 ) = 0.53116634, y( 23 ) = 1.15351499, y(1) = 2
Note 9:
An advantage of the shooting method is that the existing programs for initial value problems
may be used.
However, the shooting method is sensitive to round-off errors and it becomes rather difficult to
use when there are more than two boundary conditions. For these reasons, we may want to use
alternative methods. This brings us to the next topic.
46
7.2.2 Finite Difference Method
Consider a second order BVP
Suppose a = x0 < x1 < < xn1 < xn = b with xi xi1 = h for all i = 1, 2, . . . , n. Let
yi = y(xi ), Pi = P (xi ), Qi = Q(xi ), and fi = f (xi ). Then by replacing y 0 and y 00 with their central
difference approximations in the BVP, we get
yi+1 2yi + yi1 yi+1 yi1
2
+ Pi + Qi yi = fi , i = 1, 2, . . . , n 1.
h 2h
or, after simplifying
h h
1 + Pi yi+1 + (h2 Qi 2)yi + (1 Pi )yi1 = h2 fi .
2 2
The last equation, known as a finite difference equation, is an approximation to the DE. It enables
us to approximate the solution at x1 , . . . , xn1 ..
Notes : We can improve the accuracy by using smaller h. But for that we have to pay a price, i.e.
we have to solve a larger system of equations.
47
-----------
4.3.3 Finite Difference Method
Consider a second order boundary value problem (BVP)
Suppose a = x0 < x1 < < xn1 < xn = b with xi xi1 = h for all i = 1, 2, . . . , n. Let
yi = y(xi ), Pi = P (xi ), Qi = Q(xi ) and fi = f (xi ). Then by replacing y 0 and y 00 with their central
difference approximations in the BVP, we get
yi+1 2yi + yi1 yi+1 yi1
2
+ Pi + Qi yi = fi , i = 1, 2, . . . , n 1.
h 2h
or, after simplifying
h h
1 + Pi yi+1 + (h2 Qi 2)yi + (1 Pi )yi1 = h2 fi .
2 2
The last equation, known as a finite difference equation, is an approximation to the differential
equation. It enables us to approximate the solution at x1 , . . . , xn1 ..
y 00 4y = 0, y(0) = 0, y(1) = 5.
y2 2.25y1 = 0
y3 2.25y2 + y1 = 0
2.25y3 + y2 = 5
Notes : We can improve the accuracy by using smaller h. But for that we have to pay a price, i.e.
we have to solve a larger system of equations.
19