Unit Singlestep Methods Solving Initial Value Problems: Structure No
Unit Singlestep Methods Solving Initial Value Problems: Structure No
8.2 PRELIMINARIES
c We start with giving some of the basic definitions in thls section.
Consider the nth-order initial value problem (IVP)
y(I1'(x)= f(x, y, y',...,y("-")
y(xo) = yo,yl(xo) = y;,..., y(I1-I'(xo)= yr-"
where xo is the initial point.
The nth order IVP (1) is equivalent to the following system of n first order initial value
problems. We write y = yl and
Hence, it is sufficient to study numerical methods for solving the single first order IVP
yl(x)=f(x,y>, y(xo)= Yo (4)
and then extend these methods for solving the system of first order WP's (3) or, the
nth order IVP(1).
We assume that the solution of the IVP(4) exists and is unique and also f(x, y) has
continuous partial derivatives with respect to x and y of as high order as required for
all x in the interval [x, ,b], in which the solution of the IVP(4) is to be obtained.
We divide the interval [x,, b] into N subintervals by the points
X o <XI < X 2 . . . < X N= b
The points x, , x , , . .., x, are called the nodal point, grid points or the mesh-
points. We assume that the nodal points are equispaced with the spacing or the step
length
h = X N - X o , where x, = b (5)
N
We obtain
x i = x , + i h , i=1,2,...,N
In numerical methods, we determine y, which is an approximate value of the exact
solution y(x) at the nodal point x, , that is
Yl xi) (6)
The numerical methods for solving the initial value problems can be broadly classified
into two categories
(i) singlestep methods, (ii) multistep methods.
In singlestep methods, the solution value yi+,at the nodal point xi+,, is obtained by
using the solution value y; at only the previous point xi. Such a method is called an
explicit singlestep method and is written as
Y,+, = y I + h $ ( x i , y i , h ) , i=0,1,... (7)
where h is the step size and 4 is called the increment function. If the method also
uses the solution value yi+,,then the method is called an implicit singlestep method.
In multistep methods, the solution value yi+,at the nodal point xi+, is obtained by
using the previously calculated k-values yi-, at the previous k nodal points
xi-,, m=O,l,,.., (k-1).
If the error in the numerical method (truncation error)
TE = xi+^ 1- YI+I
\
can be written as
TE = c hP+lY ( ~ + ' )(c), xi-, < 5 < x,+, (8)
where C is a constant independent ofh, then the method is said to be of order p.
With this background we shall now discuss singlestep methods of various orders. In
this unit we shall confine our discussion only to explicit singlestep methods.
The method (1 1) is called the Taylor's series method of order p. For different \
of D. we obtain different order methods.
p = 1: first order Taylor series method
Yi+l = Y i +hYf
C : and so on.
The higher order derivatives ylm),m = 1,2,. .. in Eqn.(l2) can be obtained by
differentiating the given differential equation repeatedly and evaluating them at the
nodal point xi.
System of first order IVP's
For the system of first order IVP's (3)
yl(x)=f(x,y), Y(x,,)=~
we write the method (12) as'
uA
Note that each term in Eqn.(l5) is a column vector having the same number of
elements as the number of first order differential equations.
Example I: Obtain the approximate value of y(1.4) for the initial value problem
yl=-2xy2, y(l)=l
using .
(a) Taylor series method of first order (Euler method)
(b) Taylor series method of second order with (i) h = 0.1, (il) h = 0.2. Compare the
1
results with the exact solution y(x) = -
x2'
Solution:
(a) Taylor series method of first order is given by
We have ,
y'=-2xy2, y; = -2 xi y;
2
y"=-2y2 - 4 x y y f , y;=-2yi - 4 x i y i y ;
(i) or h = 011, we obtain Siagbtep Methods
i=O : X, = l , y o = I , yb = - 2 , ~ ; = 6 for Solving IVPs
h2
y4 zy(1.4)=y3 + h y ; +-y; =0.514920
2
Actual error at x = 1.4 = y(1.4) - y 4 = -0.0047.
Remark: You may notice that the actual emor in\magnitude decreases when (i) h is
reduced or (ii) higher order method is used.
~ x a & l e 2: Solve the initial value problem yr = x 2 + y2, y(0) = 1 upto x = 0.4
using fourth order Taylor series method with h = 0.2.
Solution: The fourth order Taylor series method is given by
We have,
y ' = ~ 2+
y2 , y!I = x 2l + yzl
y"=2x+2yy1 3 y; = 2xi + 2yi y;
y" = 2 + 2(Y1)*+ 2y y" , y;= 2 + 2(y;)2 + 2yi y"
yiV= 6yry" + 2y y" , Yr 6yi yf + 2yi y:
=
For h = 0.2, we obtain
Numerical Solutions
of ODES
Example 4: Reduce the second order initial value problem Singlestep Methods
y"=yl+l for Solving IVPs
y(0) = 1, y1(0) = 1
to a system of first order initial value problems. Hence, find an approximate value of
y(0.4) and yr(0.4) using Taylor series second order method with h = 0.2.
Solution: Set y = yl, we get
YI = Y 2 y,(O)=l
9
Y; = l + y , y2(0)=1
9
we have
El) Obtain the approximate value y(1.2) for the initial value problem
y l = - y 2 , y(l)=l
using Euler method with h = 0.1 .
E2) Solve the initial value problem
yf = 2x + 3y, y(0) = 1
Numerical Solutions in the interval [O, 0.41 using (a) Taylor series second order method, (b) Taylor
of ODES series fourth order method. Take h = 0.2 in each case.
E3) Solve the initial value problem
y1= x + sin y, y(1) = 1
in the interval [I, 1.21 using (a) Taylor series second order method, (b) Taylor
series fourth order method. Take h = 0.1 in each case.
E4) Find the approximate value of y (0.4) and u (0.4) for the system of
equations
y 1 = 2 y + u , y(O)=l
u 1 = 3 y + 4 u , u(O)=l
using Taylor series second order method with h = 0.2
E5) Write the second order initial value problem
y" = -2y y', y(0) = 1, yl(l) = 1
as a system of two first order initial value problems. Hence, obtain approximate
value of y(1.4) and y'(1.4) using second order Taylor series method with
h =0.2.
Taylor series method of any arbitrary order for solving the initial value problem (4)
can be easily obtained. However, from application point of view, Taylor series
method has a serious disadvantage. The method requires evaluation of derivatives of
higher order for the function f(x, y) of two variables x and y. These higher order
derivatives have to be obtained manually for each problem. Therefore, we need to
develop methods, which do not require the evaluation of higher order derivatives and
still compare with the Taylor series methods. One such class of methods is the Runge-
Kutta methods which we shall discuss in the next section.
Xltl
We note that f (x, y) is the slope of the solution curve and it changes continuously in
[xi ,x ,+,1.
Let the continuously varying slope f(x, y) in this interval be
approximated by the fixed slope at x = x i , that is, f(x,y) r; f ( x i , y i ) in [xi ,x,+,]
Then from Eqn.(l6), we obtain
Xi
Or, Yi+j = Y i + h f ( x , , ~ i )
where, K , = h f ( x i , y , )
(20)
K 2 = h f ( x i + h,yi + K , )
The philosophy behind the Runge-Kutta methods is to consider a weighted average of
slopes or approximate slopes at a number of points in [xi ,xi+,]. If we use v slopes,
then the method is written as
yi+,= y i + w , K I + w 2 K 2 wvKv,
+ . a * + (21)
where,
K, =hf(xi,yi)
K 2 = h f ( x i + a 2 h , y i+ P,, K , )
v-l
xi + a , h , y , + Z P , ~ ~
j=l I
w ' S,a i'S and Pi 's are parameters to be determined such that the method (21) agrees
with the Taylor series method of certain order.
\
We shall only discuss the cases v\= 2 and v = 4 which provide the methods of orders 2
and 4 respectively.
Second order Runge-Kutta method (two stage method)
Consider the following two-stage method
Yi+l = Y i + W I K I +w2 K2
where
K , - =h f ( x i , y i )
K 2 = h f ( x i + a 2 h , y i+ P 2 , K l )
Expanding KI and K2 in Taylor series about the point xi, we get
K, = h f ( x i , y i ) = h f i
:.K2= h f ( x i + a 2 h , y i + p , , h f i )
Numerical Solutions
of ODES
where the partial derivatives are evaluated at the point (xi , y i ) . Substituting the
expressions for KI and K2 in Eqn.(20), we get
Now, Taylor series method for solving the given differential equation is given by
h2 h3
Y ( x ~ + ~ ) = Y ( hyl(xi)+-yW(xi)+-ym(xi)+-..
x~)+
2! 3!
1
w2 P2l =- (25)
2
It is not possible to compare the coefficient of h3, as there are three terms in Eqn.(23)
and five terms in Eqn.(24).
The solution of the system of Eqn.(25) is obtained as
and a, # 0 is arbitrary. The method (22) becomes Singlestep Methods
for Solving lVPs
(26)
where
K, = h f ( x i , y i )
: K, = hF(xi + a 2 h , y i+ a , K , )
The truncation error associated with the method is given by
TE = ~ ( x i + - l )Y i + l
--(- ax + g]]+
+ laf
6 a ~
af
fi 0(h4)
Therefore, the two stage Runge-Kutta method (26) is a second order method for all
values of a,. For different values of a, we obtain different second order methods.
1
For a, = 1, we get, P,, = l,w, = w --and the method is
,-2
1
Yi+l = Y i +-('I
2
+',I
K, = h f ( x , , y , )
K, = h f ( x i + h , y i + K , )
which is the Euler-Cauchy method or the Heun method (18)
1 1
,
For a - -, we get p,, = -, w, = 0,w = 1 and the method is
2-2 2
Y i + l = Y i +K2
K, =hf(x,,y,)
K, = h f ( x i + h , y i + K , )
which is called the classical Runge-Kutta method and is of fourth order.
Remarks
1. Both Taylor series method and Runge-Kutta methods are singlestep methods.
2. We require two function evaluations per step for a second order Runge-Kutta
method and four function evaluations per step for a fourth order Runge-Kutta
method.
System of first order IVP's
For the system of n first order IVP's (3)
yl=f(x,y),y(x,)=a
we write the Runge-Kutta methods as follows:
Numerical Solutions Second order method (27)
of ODES
where
and
KJI =hfj(xi,Y1i,Y2i,'.',Yni) *
Kj2 = h f j ( x i + h , y l i + K I I , ~ +K2I,"',Yni
2i +Knl)
j = 1,2, ...,n.
Fourth order method (29)
where, K , = I K ; , K 2 = ~ K ; ; ] , K 3 = I K y ] 9 K 4 = I K 7 ]
and
Kjl =hfj(~~,~li~Y2i,...,Yni)
1 1
+-K12,y2i +- K22,...,yni
2 2
Kj4 = hf,(xi + h,yli + Ku9y2i+'K23,..-,yni + ~ n 3 )
j=1,2 ,...,n.
We shall now illustrate the methods discussed above through examples.
Example 5: Solve the initial value problem
Y'=x'+y2,y(l)=2
on the interval [1, 1.41 using the second order Runge-Kutta method (27) with h = 0.2.
Solution: We are given that f(x, y) = x 2 + y 2 and h = 0.2.
- We obtain from Eqn.(27) for
i=O: xo =l,yo = 2
K , = h f ( x 0 , y , ) = hf(l,2)=0.2[(1)~+ (2)']=1
K 2 = h f ( x o + h,yo + ~ , ) = h f ( 1 . 2 , 3 ) = 0 . 2 [ ( 1 . 2 )+3']=2.088
'
Example 6: Find an approximate value of y(0.8) for the initial value problem. Singlestep Methods
y1= fi, y(0.4) = 0.41
for Solving lVPs
Example 7: Find an approximate value of y(0.2) for the inltlal value problem
~ ' = l + y(O)=l
~ ~ ,
using the classical Runge-Kutta fourth order method (29) with h = 0.1.
Solution: We are given that f (x, y) = 1+ y2 and h = 0.1.
We obtain fiom Eqn.(29) for
Numerical Solutions
of ODES
E7) Find an approximate value of y(1.2) for the initial value problem
E8) Find an approximate value of y(2.4) for the initial value problem
y1= x(y - x), y(2) = 3
using classical fourth order Runge-Kutta method with h = 0.2.
We shall now find the interval of stability for various methods discussed above.
We discuss the stablllty of the single step methods by applying the method to the test
equation.
yl=Ay, y(x,) = Yo (32)
where A is a positlve or a negative constant. The exact solutlon of Eqn.(30) IS
obtained as
j.(\-x,,)
Y(X)= y(x,)e
Substltutlng x = x, and x = x,+,, we get
y(x,) = Y(Xo)e'.('l-\~' = Y(xo)e"'"
Hence, we obtain
y(x,+, = eA"y(x, (33)
and h is the step sue.
The exact solution of Eqn.(32) grows (when A > 0 ) or decays (when A < 0 ) by the
'growth-factor e'." .
When we apply a numerical method to solve Eqn.(32), we obtaln a relation of the form
Y,+l = E(Ah)y, (34)
where E(Ah) is some approximation to e"" . The numerical solution grows or decays
by the growth factor E(Ah) . The growth factor E(Ah).should behave similar to
e"" for meaningful results.
Substltutlng y, = y(x, )+ E , and y ,+, = y(x,+,)+ E,,, , we get
y(x,+,)+ € , + I = E ( ~ [ (x,
Y )+ E,]
Slnce y(x,+,) = y(x, ) e'" , we get
y(x,) e'.ll+ EITl = E(1l-l) [Y(x,) + E , ]
Numerical Solutions
of ODES
Thus the error Ei+r at the nodal point xi+, consists of two parts.
The first part E(hh) - eAhis the local truncation error and can be made as small as
we l ~ k eby increas~ngthe order of the numerical method or by reduc~ngthe step size h.
We find that this error -+ 0 as h -+ 0 .
, called the propagation error. We consider the following
The second part E ( h h ) ~ is
two cases
Case 1: h < 0
In this case the exact solution decreases. For meaningful numerical results, the growth
fictor E(hh) of the numerical solution should decay at least as fast as eAh, the growth
factor of the exact solution. sinceeLh< 1 for A < 0 , we obtain the condition
and the method in this case is called absolutely stable. In this case y i -+ 0 as i -+ a,.
The set of values of hh which satisfy Eqn.(36) give the interval of absolute stability
(hh, 0) for the given method. If the interval of absolute stability is ] - cn, 01, then the
method is called A-stable.
Case 2: h > 0
In this case the exact solution increases. For meaningful numerical results, the growth
factor E(hh) of the numerical solution should not increase faster than the growth
factor e" of the exact solution. Therefore, we obtain the condition
y(P) =~ ~ ( p - 1=) hP
Y
Applying the p th order Taylor series method
where
(39)
For h > 0, E (Ah) < eAhfor all hh and therefore, the Taylor series method is always
relatively stable.
For h <-0. we obtain the intervals of absolute stability for different values of p.
p=l: I~(hh)(<Il+hh(<l
We get,
- 1 < l + h h < l or, - 2 < h h < O
Hence, the interval of absolute stability is ] - 2, 0[
We get,
-1 < 1+ hh +-hZh2< l 1
or, - 1 <-[(l+hh)> + l ] < l
2 2
The left inequality is always satisfied. From the right inequality, we get
(1+ hh12 + 1 < 2 or, (1+ ~ h < )l ~
= [ l + ( w , + w , ) A h + w 2 P , , A2h2]Yl
Numerical Solutions
of ODES Using the conditions w, + w, = 1 and w, P2, = -1 (see Eqn.(25)), we get
2
k2h2
where E(Ah)=l+hh+-
2
For h > 0, E (Ah) < eAhfor all hh . Therefore, this method is relatively stable for all
Ah.
I
For h < 0, E (Ah) ( < 1 gives Ah E ] - 2,O[ . Hence, the interval of absolute stability
for second order Runge-Kutta method is ] - 2, 0[ .
Remark: The interval of absolute stability of all second order Runge-Kutta methods is
I-2,0[.
Fourth order method
Applyjng the method (29) to the test equation
Y' = LY, y(x0) = Yo
we get,
K, = h f ( x i , y i ) = h h yi
and
1
yi+,= y i +-(K, + 2K, + 2K3 + K,)
6
h2h2
where E(Ah) = 1+ kh + -2
I 1
The condition E ( ~ h <) 1gives the interval of absolute stability as ] - 2, O[.
Example 10: The second order Runge-Kutta method is applied to the IVP
y' = -1ooy, y(0) = 1
Find the values of h so that the method produces stable results.
Solution: Comparing the given problem with the test equation y' = hy ,we get
A = -100.
1
1 I<
Since for stability : Ah 2 , we get lOOh < 2 or, h < -.
50
1
Hence, for 0 c h c - ,the method will produce stable results.
50
***
And now some exercises for you.
E12) Find the interval of absolute stability of the two stage Runge-Kutta method
P given by
1
Y i + l = Y i +-(K, +3K,)
4
where K, = h f ( x i , y i )
E13) Fourth order classical Runge-Kutta method is used to solve the initial value
problem
y' = -2OOy. y(0) = 1
Determine the value of h so that the method produces stable results.
We now end this unit by giving a summary of what we have covered in it.
-
Numerical Solutions
01 ODES 8.6 SUMMARY
In this unit we have discussed the following points
1. In sieglestep methods for solving IVP(4) viz.,
Y ' ( x ) = ~ ( x , Y ) , ~ ( x o ) = Y o , X E [ X O , bl
the solution value yi+, at,the nodal point xi+, is obtained by using the solution
value y, at only the previous point xi . Such a method is called an explicit
singlestep method and is written as
Y , + ~= yi + h Q , ( x i ,yi,h), i =(),I,...
where h is the step size and Q, is called the increment function. If the method
also uses the solution value yi+,, then the method is called an implicit
singlestep method.
2. Taylor series method of order p for the solut~onof the IVP(4) is given by
T
where =[yli, Yzi,...,Yni I
T
(y(m))xi=[yi;), yF),..., y?'] , m = l , 2 ,... , P
1=1
where v slopes are used. These slopes are defined by
i-l
x i + a i h, y i + C p i j ~, , =
j=l
I , ,v ai *O
The unknowns a i,Pij and w are then obtained by expanding K i 's and y ,+, in
Taylor series about the point ( x i ,y ) and comparing the coefficients of
different powers of h .
6. Unlike Taylor series methods, Runge-Kutta methods do not need calculation
of higher order derivatives of f(x, y) but need only the evaluation of f(x, y) at
the off-step points.
7. The numerical solution y which is an approximation of y(xi ) contains
errors. The error at the nodal point x i is given by
Slnglestep Methods
Ei=Y(%)-Y; for Solving IVPs
and'is called numerical error. If this error remains bounded as
i -+ a (or h t0), then the numerical method is said to be stable.
8. When a numerical method is applied to the following linearised form
of IVP(4), (test equation)
= Yor X~[xo,bI
yl=&.Y, Y(XO)
with nodal points x, = x, + ih, i = O,1,. ..,N and x, = b = x, + Nh , a relation
of the form
Y i+l = E (Ah) Y
is obtained where E(hh) is some approximation to e" . The error ei+,at the
nodal point xi+, consists of two parts and is given by
The first part E(hh) - eAhis the local truncation error and the second part
E(Ah) ei is called the propagation error and the following results hold
i) numerical method is called absolutely stable if
IE(hh)l<l, h < O
In this case y, -+ 0 as i -+ a, . The set of values of Ah which satisfy
the above condition give the interval of absolute stability ]Ah, 0[ for the
given method. If this interval is ] - a,0 [ , then the method is called A-
stable.
ii) numerical method is called relatively stable if
E(Ah) < eA",h > 0
and the set of values of hh which satisfy the above condition give the
interval of relative stability.
8.7 SOLUTIONSIANSWERS
El) x , = l , y , = l , yb=-l
y, = y(l.I)= yo + h y b =1+(0.1) (-l)=0.9
x, = l . l , y, =0.9, yl =-0.81
x, =0.2,y, = 1 . 8 2 , ~=5.86,y:
;
-
y z = y ( 1 . 2 ) = ~ +, h y ; =0.9+(0.1) (-0.81)=0.819.
b) x, = 0, y, = 1, y i = 3, y: = 11, y: = 3 3 , ~ : = 99,
y, z y(0.2) = 1.8706.
x, = 0.2, y , = 1.8706, y; = 6.01 18, yy = 20.0354, y:= 60.1062,
yy = 180.3186, yz = y(0.4) = 3.5658.
E3) a) x,=1,yo=l,y~=1.841471,y~=1.540302,y,=y(l.l)=1.191849.
x , = l . y, =1.191849, y; =2.029055, yy=1.369943,
y2 5 y(1.2) = 1.401604
b)
-
x o = 1 , y o = 1 , y ~ = 1 . 8 4 1 4 7 1y%=1.540302,~:=-,841471,
y: = -0.540302, y, ~ ( 1 . 1=
I
) 1.191706.
,
1. Write a program using Euler's method to solve the initial value problem
y = f (x, y), y(xo) = yo . Input the step length h and the number of steps of
integration. Test your program on exercise El).
2. Write a program using Taylor series method of second order to solve the initial
value problem y' = f (x, y), y(x,) = yo . User shall give the expression for y" .
Input the step length h and the number of steps of integration. Test your program
on exercises E2) and E3).
3. Write a program using Runge-Kutta second order method to solve the initial value
problem y' = f(x, y), y(xo ) = yo . Input the step length h and the number of
steps o f mtegration. Test your program on exercises E6) and E7).
4. Write a program using fourth order classical Runge-Kutta method to solve the
,
initial value problem y ' = f (x, y) , y(x ) = yo . Input the step length h and the
number of steps of integration. Test your program on exercises E8) and E9). i