Sie sind auf Seite 1von 29

Unit I : Numerical Methods Prepared by Dr. M.

Sankar, SCE, Bangalore

Unit 1: Numerical Methods


Numerical Solution of First Order and First Degree Ordinary
Differential Equations
Motivation:
The fundamental laws of physics, mechanics, electricity and thermodynamics are
usually based on empirical observations that explain variations in physical properties and
states of the systems. Rather than describing the state of physical system directly, the
laws are usually couched in terms of spatial and temporal changes. The following table
gives a few examples of such fundamental laws that are written in terms of the rate of
change of variables (t = time and x = position)

Physical Law

Mathematical Expression

Variables and Parameters

Newtons second law of


motion
Fouriers Law of Heat
Conduction

dv F

dt m
dT
q k
dx

Faradays Law (Voltage


drop across an inductor)

VL L

Velocity(v), force (F) and


mass (M)
Heat flux (q), thermal
conductivity(k)
and
temperature (T)
Voltage
drop
( VL ),
inductance4 (L) and current
(i)

di
dt

The above laws define mechanism of change. When combined with continuity laws for
energy, mass or momentum, differential equation arises. The mathematical expression in
the above table is an example of the Conversion of a Fundamental law to an Ordinary
Differential Equation. Subsequent integration of these differential equations results in
mathematical functions that describe the spatial and temporal state of a system in terms of
energy, mass or velocity variations. In fact, such mathematical relationships are the basis
of the solution for a great number of engineering problems. But, many ordinary
differential equations arising in real-world applications and having lot of practical
significance cannot be solved exactly using the classical analytical methods. These ode
can be analyized qualitatively. However, qualitative analysis may not be able to give
accurate answers. A numerical method can be used to get an accurate approximate
solution to a differential equation. There are many programs and packages available for
solving these differential equations. With today's computer, an accurate solution can be
obtained rapidly. In this chapter we focus on basic numerical methods for solving initial
value problems.
Analytical methods, when available, generally enable to find the value of y for all
values of x. Numerical methods, on the other hand, lead to the values of y corresponding
only to some finite set of values of x. That is the solution is obtained as a table of values,

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

rather than as continuous function. Moreover, analytical solution, if it can be found, is


exact, whereas a numerical solution inevitably involves an error which should be small
but may, if it is not controlled, swamp the true solution. Therefore we must be concerned
with two aspects of numerical solutions of ODEs: both the method itself and its accuracy.
In this chapter some methods for the numerical solution of ODEs are described.
The general form of first order differential equation, in implicit form, is
dy
f ( x, y ) . An Initial Value Problem (IVP)
F ( x, y, y / ) 0 and in the explicit form is
dx
consists of a differential equation and a condition which the solution much satisfies (or
several conditions referring to the same value of x if the differential equation is of higher
order). In this chapter we shall consider IVPs of the form
dy
(1)
f ( x, y ), y ( x0 ) y0 .
dx
Assuming f to be such that the problem has a unique solution in some interval containing
x0, we shall discuss the methods for computing numerical values of the solution. These
methods are step-by-step methods. That is, we start from y0 y ( x0 ) and proceed
stepwise. In the first step, we compute an approximate value y1 of the solution y of (1) at
x = x1 = x0 + h. In the second step we compute an approximate value y2 of the solution y
at x = x2 = x0 + 2h, etc. Here h is fixed number for example 0.1 or 0.001 or 0.5 depends
on the requirement of the problem. In each step the computations are done by the same
formula.
The following methods are used to solve the IVP (1).
1.
2.
3.
4.
5.

1.

Taylors Series Method


Euler and Modified Euler Method
Runge Kutta Method
Milnes Method
Adams Bashforth Method

Taylors Series Method

dy
f ( x, y ), y ( x0 ) y0 . Let us approximate the exact solution y(x)
dx
to a power series in ( x x0 ) using Taylors series. The Taylors series expansion of y(x)

Consider an IVP

about the point x x0 is

( x x0 ) /
( x x0 ) 2 //
( x x0 ) 3 ///
( x x0 ) 4 / V
y ( x0 )
y ( x0 )
y ( x0 )
y ( x0 )
1!
2!
3!
4!
(1)
dy
From the differential equation, we have y / ( x)
f ( x, y ) . Differentiating this
dx
successively, we can get y // ( x), y /// ( x), y / V ( x), etc. Putting x x0 and y y 0 , the values
y ( x) y ( x0 )

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

of y // ( x0 ), y /// ( x0 ), y / V ( x0 ), etc. can be obtained. Hence the Taylors series (1) gives the
values of y for every value of x for which (1) converges.
On finding the value of y1 for x x1 from (1), y // ( x), y /// ( x), y / V ( x), etc. can be evaluated
at x x1 from the differential equation
Problems:
1. Find by Taylors series method the value of y at x = 0.1 and 0.2 five places of decimals
dy
for the IVP
x 2 y 1, y (0) 1 .
dx
Solution:
Given x0 0, y 0 1 and f ( x, y ) x 2 y 1
Taylors series expansion about the point x 0( x0 ) is
( x 0) /
( x 0) 2 //
( x 0) 3 ///
( x 0) 4 / V
y ( 0)
y ( 0)
y ( 0)
y (0)
1!
2!
3!
4!
x 2 //
x 3 ///
x 4 /V
y ( x) y (0) xy / (0)
y ( 0)
y ( 0)
y (0)
2
6
24

y ( x ) y ( 0)

i.e.

It is given that
dy
y / ( x) x 2 y 1
dx

(1)

y ( 0) 1

y / (0) 1

Differentiating y / ( x) x 2 y 1 successively three times and putting x = 0 & y = 1, we get

y // ( x) 2 xy x 2 y /

y // (0) 0

y /// ( x) 2 y 4 xy / x 2 y //

y /// (0) 2

y iv ( x) 6 y / 6 xy // x 2 y ///

y iv (0) 6

Putting the values of y (0), y / (0), y // (0), y /// (0), y iv (0) in (1), we get
x2
x3
x4
( 0)
( 2)
(6)
2
6
24
x3 x4
y ( x) 1 x

3
4

y ( x) 1 x(1)

Hence y(0.1) = 0.90033 and y(0.2) = 0.80227.

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

2. Employ Taylors series method to obtain approximate value of y at x = 0.1 and 0.2 for
dy
the differential equation
2 y 3e x , y (0) 0. Compare the numerical solution
dx
obtained with the exact solution.
Solution:
Given x0 0, y 0 0 and f ( x, y ) 2 y 3e x
Taylors series expansion about the point x 0 is
y ( x) y (0) xy / (0)

x 2 //
x 3 ///
x 4 /V
y ( 0)
y ( 0)
y (0)
2
6
24

It is given that
dy
y / ( x) 2 y 3e x
dx

(2)

y ( 0) 0

y / (0) 2 y (0) 3e 0 3

Differentiating y / ( x) 2 y 3e x successively three times and putting x = y = 0, we get

y // ( x) 2 y / 3e x

y // (0) 2 y / (0) 3 9

y /// ( x) 2 y // 3e x

y /// (0) 2 y // (0) 3 21

y iv ( x) 2 y /// 3e x

y iv (0) 2 y /// (0) 3 45

Putting the values of y (0), y / (0), y // (0), y /// (0), y iv (0) in (2), we get
9 2 21 3 45 4
x
x
x
2
6
24
9
7
15
3x x 2 x 3 x 4
2
2
8

y ( x) 0 3x

Hence,
y(0.1) = 3(0.1)+4.5(0.1)2+3.5(0.1)3+1.875(0.1)4
= 0.3486875
and
y(0.2) = 3(0.2)+4.5(0.2)2+3.5(0.2)3+1.875(0.2)4
= 0.8110.

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Exact Solution:
The given differential equation can be written as

dy
2 y 3e x which is Leibnitzs linear
dx

differential equation.
2dx
Its I.F. is I.F = e e 2 x

Therefore the general solution is,


ye 2 x 3e x (e 2 x )dx c 3e x c

y 3e x ce 2 x

(3)

Using the given initial condition y = 0 when x = 0 in (3) we get c = 3.

Thus the exact solution is y 3 e 2 x e x

When x = 0.1, the exact solution is y(0.1) = 0.348695


When x = 0.2, the exact solution is y(0.2) = 0.811266
The above solutions are tabulated as follows:

Numerical

Exact

Absolute
Error Value

0.1

0.3486875

0.348695

0. 75x10 -5

0.2

0.8110

0.811266

0. 266x10 -3

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

3. Using Taylors series method solve

dy
x 2 y,
dx

y (0) 1 at 0.1 x 0.4. Compare

the values with the exact solution.


Solution:
Given x0 0, y 0 1 and f ( x, y ) x 2 y
Taylors series expansion about the point x 0 is
y ( x) y (0) xy / (0)

x 2 //
x 3 ///
x 4 /V
y ( 0)
y ( 0)
y (0)
2
6
24

y ( 0) 0

It is given that
dy
y / ( x) x 2 y
dx

y / (0) (0) 2 1 1

Differentiating y / ( x) x 2 y successively and putting x =0, y = 1, we get

y // ( x) 2 x y /

y // (0) 0 y / (0) 0 (1) 1

y /// ( x) 2 y //

y /// (0) 2 y // (0) 1

y iv ( x) y ///

y iv (0) y /// (0) 1

Putting the values of y (0), y / (0), y // (0), y /// (0), y iv (0) in (4), we get
y ( x) 1 x

x2 x3 x4

2
6 24

Hence,
y (0.1) 1 (0.1)

(0.1) 2 (0.1) 3 (0.1) 4

2
6
24

= 0.9051625
y ( 0 .2 ) 1 ( 0 .2 )

= 0.8212667.

( 0 .2 ) 2 ( 0 .2 ) 3 ( 0 .2 ) 4

2
6
24

(4)

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

y (0.3) 1 (0.3)

(0.3) 2 (0.3) 3 (0.3) 4

2
6
24

= 0.7491625.
y ( 0 .4 ) 1 ( 0 .4 )

( 0 .4 ) 2 ( 0 .4 ) 3 ( 0 .4 ) 4

2
6
24

= 0.6896.

Exact Solution:
The given differential equation can be written as

dy
y x 2 a linear differential
dx

equation.
dx
Its I.F. is I.F = e e x

Therefore the general solution is,


ye x e x ( x 2 )dx c ( x 2 2 x 2)e x c

y ( x 2 2 x 2) ce x

(5)

Using the given condition y(0) = 1 in (5) we get 1 = 2 + c or c = -1.


Hence the exact solution is y ( x 2 2 x 2) e x

The exact solution at x = 0.1, 0.2, 0.3 and 0.4 are

y(0.1) = 0.9051625,
y(0.2) = 0.8212692,
y(0.3) = 0.7491817 and
y(0.4) = 0.6896799

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

The above solutions are tabulated as follows:

Numerical

Exact

Absolute
Error Value

0.1

0.9051625

0.9051625,

0.2

0.8212667

0.8212692,

0. 25x10 -5

0.3

0.7491625

0.7491817

0. 192x10 -4

0.4

0.6896

0.6896799

0. 799x10 -4

Assignments:
1. Use Taylors series method to find an approximate value of y at x = 0.1 of the IVP
dy
Answer : 0.9138
x y 2 , y ( 0) 1
dx
2. Evaluate y(0.1) correct to six decimal places by Taylors series method if y(x) satisfies
Answer : 1.1053425
y / xy 1, y (0) 1
dy
x y2,
dx
and y(0.2)

3. Solve

y 1 at x 0 using Taylors series method and compute y(0.1)

4. Using Taylors series method, compute the solution of


point x = 0.2 correct to three decimal places.

2.

Answer : 1.1164 and 1.2725


dy
x y,
dx

y (0) 1 at the

Answer : 1.243

Modified Eulers Method

dy
f ( x, y ), y ( x0 ) y0 . The following two methods can be used to
dx
determine the solution at a point x x n x0 nh .

Consider the IVP

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Eulers Method :
y nE1 y n hf ( x n , y n ),

n 0,1,2,3,

(1)

Modified Eulers Method :


y n 1 y n

h
f ( x n , y n ) f ( x n 1 , y nE1 ) ,
2

n 0,1,2,3,

(2)

Remark:
1. The formulae (1) and (2) are also known as Eulers Predictor Corrector formula.
2. When Modified Eulers method is applied to find the solution at a give point, we
first find the solution at that point by using Eulers method and the same will be
used in the calculation of Modified Eulers method. Also Modified Eulers
method has to be applied repeatedly until the solution is stationary.
Problems :

dy
y2

, y (0) 1 by Eulers method by choosing h = 0.1 and h = 0.05.


dx
1 x
Also solve the same problem by modified Eulers method by choosing h = 0.05. Compare
the numerical solution with analytical solution.
1. Solve

Solution :
Analytical solution is : dy
dx

2
1 x
y

1
log(1 x) c
y

Using the condition y(0) = 1, we get c = 1.


1
Hence the analytical solution is y
y(0.2) = 0.84579
1 log(1 x)
y2
Now by Eulers method, we have y n 1 y n 0.1 n
1 xn
2
(1)
0.9
y1 y (0.1) 1 0.1
1 0

( 0 .9 ) 2
0.82636
y 2 y (0.2) 0.9 0.1
1 0 .1

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Error = 0.84579 0.82636 = 0.01943

y2
Now taking h = 0.05, Eulers method is y n 1 y n 0.05 n
1 xn

(1) 2
0.95
y1 y (0.05) 1.0 0.05
1 0
(0.95) 2
0.90702
y 2 y (0.1) 0.95 0.05
1 0.05
(0.90702) 2
0.86963
y 3 y (0.15) 0.90702 0.05
1 0 .1
(0.86963) 2
0.83675
y 4 y (0.2) 0.86963 0.05
1 0.15

Error = 0.84579 0.83675 = 0.00904


Note that when h = 0.1, Error was 0.01943, WHICH IS MORE.
Now we use modified Eulers method to find y(0.2) with h = 0.05

Eulers Formula is y n 1

y n2
y n 0.05
1 xn

Modified Euler Formula is y n 1

, n = 0,1,2 and 3

y2
yE
y n 0.025 n n 1 , n = 0,1,2 and 3
1 x n 1 x n 1

Stage I: Finding y1 = y(0.05)


From Eulers formula (for n = 0),

(1) 2
0.95
y1E y (0.05) 1.0 0.05
1 0
From Modified Eulers formula, we have
(1) 2 (0.95) 2
0.95351
y1(1) y (0.05) 1.0 0.025

1 0 1 0.05
(1) 2 (0.95351) 2
0.95335
y1( 2 ) y (0.05) 1.0 0.025

1 0.05
1 0

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

(1) 2 (0.95335) 2
0.95336
y1(3) y (0.05) 1.0 0.025

1 0.05
1 0
(1) 2 (0.95336) 2
0.95336
y1( 4 ) y (0.05) 1.0 0.025

0
1

0
.
05

Hence y1 y (0.05) 0.95336


Stage II: Finding y2 = y(0.1)
From Eulers formula (for n = 1), we get

(0.95336) 2
y y (0.1) 0.95336 0.05
1 0.05
From Modified Eulers formula, we have
E
2

0.91008

(0.95336) 2 (0.91008) 2
0.91286
y 2(1) y (0.1) 0.95336 0.025

1 0.1
1 0.05
(0.95336) 2 (0.91286) 2
0.91278
y 2( 2 ) y (0.1) 0.95336 0.025

1 0.1
1 0.05
(0.95336) 2 (0.91278) 2
y 2( 2 ) y (0.1) 0.95336 0.025

1 0 .1
1 0.05

0.91278

Hence y 2 y (0.1) 0.91278


Stage III: Finding y3 = y(0.15)
From Eulers formula (for n = 2), we get

(0.91278) 2
0.87491
y 3E y (0.15) 0.91278 0.05
1 0 .1
From Modified Eulers formula (for n = 2), we have
(0.91278) 2 (0.87491) 2
0.87720
y 3(1) y (0.15) 0.91278 0.025

1 0.15
1 0 .1
(0.91278) 2 (0.87720) 2
0.87712
y 3( 2 ) y (0.15) 0.91278 0.025

1 0.15
1 0 .1
(0.91278) 2 (0.87712) 2
y 3(3) y (0.15) 0.91278 0.025

1 0.15
1 0 .1

0.87712

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Hence y 3 y (0.15) 0.87712


Stage IV: Finding y4 = y(0.2)
From Eulers formula (for n = 3), we get
(0.87712) 2
0.84367
y 4E y (0.2) 0.87712 0.05
1 0.15
From Modified Eulers formula(for n = 3), we have

(0.87712) 2 (0.84367) 2
0.84557
y y (0.2) 0.87712 0.025

1 0.2
1 0.15
(0.87712) 2 (0.84557) 2
0.84550
y 4( 2 ) y (0.2) 0.87712 0.025

1 0.2
1 0.15
(1)
4

( 2)
4

(0.87712) 2 (0.84550) 2
y (0.2) 0.87712 0.025

1 0 .2
1 0.15

0.84550

Hence y 4 y (0.2) 0.84550

Error = 0.84579 0.84550 = 0.00029


Recall that the error from Eulers Method is 0.00904

2. Solve the following IVP by Eulers modified method at 0.2 x 0.8 with h = 0.2:
dy
log10 ( x y ), y (0) 2 .
dx

Solution:
Given Data is : x0 0, y 0 2, h 0.2 and f ( x, y ) log10 ( x y )

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

To Find:

y1 y ( x1 ) y (0.2), y 2 y ( x 2 ) y (0.4), y 3 y ( x3 ) y (0.6)

& y 4 y ( x 4 ) y (0.8)
Stage I: Finding y1 = y(0.2)
From Eulers formula (for n = 0),
y1E y (0.2) 2.0 0.2 log10 0 2 2.0602

Now from Modified Eulers formula (for n = 0), we have


y1(1) y (0.2) 2.0 0.1log10 (0 2) log10 (0.2 2.0602 2.0655
y1( 2 ) y (0.2) 2.0 0.1log10 (0 2) log10 (0.2 2.0655 2.0656
y1( 3) y (0.2) 2.0 0.1log10 (0 2) log10 (0.2 2.0656 2.0656

Hence y1 y (0.2) 2.0656


Stage II: Finding y2 = y(0.4)
From Eulers formula (for n = 1),
y 2E y (0.4) 2.0656 0.2 log10 0.2 2.0656 2.1366

Now from Modified Eulers formula (for n = 1), we have


y 2(1) y (0.4) 2.0656 0.1log10 (0.2 2.0656) log10 (0.4 2.1366 2.1415
y 2( 2 ) y (0.4) 2.0656 0.1log10 (0.2 2.0656) log10 (0.4 2.1415 2.1416
y 2( 3) y (0.4) 2.0656 0.1log10 (0.2 2.0656) log10 (0.4 2.1416 2.1416

Hence y 2 y (0.4) 2.1416


Stage III: Finding y3 = y(0.6)
From Eulers formula (for n = 2),

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

y 3E y (0.6) 2.1416 0.2 log10 0.4 2.1416 2.2226

Now from Modified Eulers formula (for n = 2), we have


y 3(1) y (0.6) 2.1416 0.1log10 (0.4 2.1416) log10 (0.6 2.2226 2.2272
y 3( 2 ) y (0.6) 2.1416 0.1log10 (0.4 2.1416) log10 (0.6 2.2272 2.2272

Hence y 3 y (0.6) 2.2272


Stage IV: Finding y4 = y(0.8)
From Eulers formula (for n = 3),
y 3E y (0.8) 2.2272 0.2 log10 0.6 2.2272 2.3175

Now from Modified Eulers formula (for n = 3), we have


y 4(1) y (0.8) 2.2272 0.1log10 (0.6 2.2272) log10 (0.8 2.3175 2.3217
y 4( 2 ) y (0.8) 2.2272 0.1log10 (0.6 2.2272) log10 (0.8 2.3217 2.3217

Hence y 4 y (0.8) 2.3217

The solutions at 0.2 x 0.8 are tabulated as follows:

xn

yn

0.2

y1 y (0.2) 2.0656

0.4

y 2 y (0.4) 2.1416

0.6

y 3 y (0.6) 2.2272

0.8

y 4 y (0.8) 2.3217

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

dy
sin x cos y, y (2.5) 0
dx
at x = 3.5 in two steps, modifying the solution thrice at each stages. Here x is in
radians.

3. Using modified Eulers method solve the IVP

Solution:
Given x0 2.5, y 0 0, h 0.5 and f ( x, y ) sin x cos y
To Find:

y1 y ( x1 ) y (3.0) and y 2 y ( x 2 ) y (3.5)

Stage I: Finding y1 = y(3.0)


From Eulers formula (for n = 0),

y1E y (3.0) 0.0 0.5sin( 2.5) cos(0) 0.7992


Now from Modified Eulers formula (for n = 0), we have

y1(1) y (3.0) 0.0 0.25sin( 2.5) cos(0) sin(3.0) cos(0.7992) 0.6092


y1( 2 ) y (3.0) 0.0 0.25sin( 2.5) cos(0) sin(3.0) cos(0.6092) 0.6399
y1( 3) y (3.0) 0.0 0.25sin( 2.5) cos(0) sin(3.0) cos(0.6399) 0.6354
Hence y1 y (3.0) 0.6354
Stage II: Finding y2 = y(3.5)
From Eulers formula (for n = 1),

y 2E y (3.5) 0.6354 0.5sin(3.0) cos(0.6354) 1.10837


Now from Modified Eulers formula (for n = 1), we have

y 2(1) y (3.5) 0.6354 0.25sin(3.0) cos(0.6354) sin(3.5) cos(1.10837) 0.89572


y 2( 2 ) y (3.5) 0.6354 0.25sin(3.0) cos(0.6354) sin(3.5) cos(0.89572) 0.94043
y 2( 3) y (3.5) 0.6354 0.25sin(3.0) cos(0.6354) sin(3.5) cos(0.94043) 0.93155

Hence y 2 y (3.5) 0.93155

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

4. Using modified Eulers method obtain the solution of the differential equation
dy
x y with the initial condition y = 1 at x = 0 for the range 0 < x 0.6 in
dx
steps of 0.2.
Solution:
Given x0 0, y 0 1, h 0.2 and f ( x, y ) x
To Find:

y1 y ( x1 ) y (0.2), y 2 y ( x 2 ) y (0.4) and y 3 y ( x3 ) y (0.6)

The Entire Calculations can be put in the following Tabular Form

y n hf ( x n , y n )

Y2 f ( x n 1 , y n 1 )

0.2 1

1.2

0.4 1.3094

1.4927

0.6 1.6350

1.8523

1.2954
1.3088
1.3094
1.6218
1.6345
1.6350
1.9610
1.9729
1.9734

Y1 f ( x n , y n )

The solution is:

y n 1 y n

h
Y1 Y2
2

1.2295
1.2309

1.2309
1.5240
1.5253

1.5253
1.8849
1.8861

1.8861

y(0.2) 1.2309, y(0.4) 1.5253 and y(0.6) 1.8861

Assignments :
1. Use Modified Eulers method to find an approximate value of y at x = 0.3, in three
dy
steps, of the IVP
Answer : 1.1105,1.2432,1.4004
x y , y ( 0) 1 .
dx
2. Evaluate y at x=1.2 and x=1.4 by Eulers modified method if y(x) satisfies
dy
y
1 , y (1) 2 . Compare the numerical solution with the analytical solution.
dx
x
Answer : 2.6182, 3.2699
dy
3. Compute y(0.2) for the IVP
xy 2 , y 2 at x 0 using Eulers modified method
dx
in two steps.
Answer : 1.9227

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

4. Using modified Eulers method, compute the solution of


point x = 2 with h = 0.2.
5. Using modified Eulers method, solve the IVP

3.

dy
2 xy , y (1) 1 at the
dx
Answer : 5.051

dy
x y 2 , y (0) 1 at the point x=0.5.
dx
Answer : 2.2352

Runge Kutta Method

The Taylors series method to solve IVPs is restricted by the difficulty in finding the
higher order derivatives. However, Runge Kutta method do not require the calculations
of higher order derivatives. Eulers method and modified Eulers method are
Runge Kutta methods of first and second order respectively.
dy
f ( x, y ), y ( x0 ) y0 . Let us find the approximate value of y at
dx
x x n 1 , n = 0,1,2,3,.. of this numerically, using Runge Kutta method, as follows:

Consider the IVP

First let us calculate the quantities k1 , k 2 , k 3 and k 4 using the following formulae.

k1 hf ( x n , y n )
k
h

k 2 hf x n , y n 1
2
2

k
h

k 3 hf x n , y n 2
2
2

k 4 hf x n h, y n k 3
Finally, the required solution y is given by
y n 1 y n

1
k1 2k 2 2k 3 k 4
6

Problems:
1. Apply Runge Kutta method, to find an approximate value of y when x = 0.2 given
dy
that
x y , y ( 0) 1 .
dx
Solution:
Given: x0 0, y 0 1, h 0.2 and f ( x, y ) x y

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

R K method (for n = 0) is: y1 y (0.2) y 0

1
k1 2k 2 2k 3 k 4
6

-------- (1)

Now

k1 hf ( x0 , y 0 ) 0.2 [0 1]

= 0.2

h
0 .2 0 .2

k 2 hf x0 , y 0 1 0.2 0
= 0.2400
1

2
2
2
2

h
0.2 0.24

k 3 hf x0 , y 0 2 0.2 0
1
= 0.2440
2
2
2
2

k 4 hf x0 h, y 0 k 3 0.2 0 0.2 1 0.2440

= 0.2888

Using the values of k1 , k 2 , k 3 and k 4 in (1), we get


1
0.2 0.24 0.244 0.2888 = 1.2468
6
Hence the required approximate value of y is 1.2468.
y1 y (0.2) 1

2. Using Runge Kutta method of fourth order, solve

dy y 2 x 2

,
dx y 2 x 2

y (0) 1 at x = 0.2

& 0.4.
Solution:
Given: x0 0, y 0 1, h 0.2 and f ( x, y )

y2 x2
y2 x2

Stage I: Finding y1 y (0.2)


R K method (for n = 0) is: y1 y (0.2) y 0

1
k1 2k 2 2k 3 k 4
6

k1 hf ( x0 , y 0 ) 0.2 f (0,1)
k
h

k 2 hf x0 , y 0 1 0.2 f 0.1,1.1
2
2

k
h

k 3 hf x0 , y 0 2 0.2 f 0.1,1.0936
2
2

= 0.2
= 0.19672
= 0.1967

-------- (2)

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

k 4 hf x0 h, y 0 k 3 0.2 f 0.2,1.1967

= 0.1891

Using the values of k1 , k 2 , k 3 and k 4 in (2), we get


y1 y (0.2) 1

1
0.2 2(0.19672) 2(0.1967) 0.1891
6

= 1+0.19599
= 1.19599
Hence the required approximate value of y is 1.19599.
Stage II: Finding y 2 y (0.4)
We have x1 0.1, y1 1.19599 and h 0.2
R K method (for n = 1) is: y 2 y (0.4) y1

1
k1 2k 2 2k 3 k 4
6

k1 hf ( x1 , y1 ) 0.2 f (0.2, 1.19599)


k
h

k 2 hf x1 , y1 1 0.2 f 0.3, 1.2906


2
2

k
h

k 3 hf x1 , y1 2 0.2 f 0.3, 1.2858


2
2

k 4 hf x1 h, y1 k 3 0.2 f 0.4, 1.3753

-------- (3)

= 0.1891
= 0.1795
= 0.1793
= 0.1688

Using the values of k1 , k 2 , k 3 and k 4 in (3), we get


1
0.1891 2(0.1795) 2(0.1793) 0.1688
6
= 1.19599 + 0.1792

y 2 y (0.4) 1.19599

= 1.37519
Hence the required approximate value of y is 1.37519.
3. Apply Runge Kutta method to find an approximate value of y when x = 0.2 with
dy
y
h = 0.1 for the IVP
3 x , y (0) 1 . Also find the Analytical solution and
dx
2
compare with the Numerical solution.

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Solution:
Given: x0 0, y 0 1, h 0.1 and f ( x, y ) 3 x
Stage I: Finding y1 y (0.1)
R K method (for n = 0) is: y1 y (0.1) y 0

y
2
1
k1 2k 2 2k 3 k 4
6

k1 hf ( x0 , y 0 ) 0.1 f (0,1)

-------- (4)

= 0.05

k
h

k 2 hf x0 , y 0 1 0.1 f 0.05, 1.025


2
2

k
h

k 3 hf x0 , y 0 1 0.1 f 0.05, 1.033125


2
2

k
h

k 4 hf x0 , y 0 1 0.1 f 0.1, 1.0666563


2
2

= 0.06625
= 0.0666563
= 0.0833328

Using the values of k1 , k 2 , k 3 and k 4 , we get


1
0.05 2(0.06625) 2(0.0666563) 0.0833328
6
= 1.0 + 0.0665242

y1 y (0.1) 1.0

= 1.0665242
Hence the required approximate value of y is 1.0665242.
Stage II: Finding y 2 y (0.2)
We have x1 0.1, y1 1.0665242 and h 0.1
R K method (for n = 1) is: y 2 y (0.2) y1

1
k1 2k 2 2k 3 k 4
6

k1 hf ( x1 , y1 ) 0.1 f (0.1, 1.0665242)


k
h

k 2 hf x1 , y1 1 0.1 f 0.15, 1.04


2
2

k
h

k 3 hf x1 , y1 2 0.1 f 0.15, 1.0485


2
2

k 4 hf x1 h, y1 k 3 0.1 f 0.2, 1.097425

= 0.0833262
= 0.1004094
= 0.1008364
= 0.1183680

-------- (5)

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Using the values of k1 , k 2 , k 3 and k 4 in (5), we get


1
y 2 y (0.2) 1.0665242 0.0833262 2(0.1004094) 2(0.1008364) 0.1006976
6
= 1.0665242 + 0.1006976
= 1.1672218
Hence the required approximate value of y is 1.1672218.
Exact Solution
The given DE can be written as

dy y
3 x which is a linear equation whose solution is:
dx 2

x
2

y 6 x 12 13e .
The Exact solution at x = 0.1 is y(0.1) = 1.0665242 and at x = 0.2 is y(0.2) = 1.1672218
Both the solutions and the error between them are tabulated as follows:

x
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0

xn

yn
(Exact)

yn
(Numerical)

Absolute
Error

0.1

1.0665243

1.0665242

0.0000001

0.2

1.1672219

1.1672218

0.0000001

y
y
(Exact)
(Numerical)
1.0665243 1.0665242
1.1672219 1.1672218
1.3038452 1.3038450
1.4782359 1.4782357
1.6923304 1.6923302
1.9481645 1.9481643
2.2478782 2.2478779
2.5937211 2.5937207
2.9880585 2.9880580
3.4333766 3.4333761

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Assignments:
1. Apply Runge Kutta method to compute an approximate value of y (0.2) and y(0.4), by
dy
taking h = 0.1 for the IVP 10
Answer: 1.0207, 1.0438
x 2 y 2 , y ( 0) 1 .
dx
2.Use Runge Kutta method to find y when x = 0.2 in steps of 0.1 for the differential
dy y x
equation
Answer: 1.0911278, 1.1678430

, y ( 0) 1
dx y x
dy
3. Solve
( y x) , y (0.4) 0.41 by Runge Kutta method at x = 0.8 in two steps.
dx
Answer: 0.6103476, 0.8489914
4.Using Runge Kutta method, find an approximate value of y for x = 0.2 in steps of 0.1
dy
if
Answer: 1.1165, 1.2736
x y 2 , given that y = 1 when x = 0,
dx

Multi-step Methods:
To solve a differential equation over an interval (xn, xn+1), using previous single-step
methods, only the values of y at the beginning of interval is required. However, in the
following methods, four prior values are needed for finding the value of yn+1 at a given
value of x. Also the solution at yn+1 is obtained in two stages. This method of refining an
initially crude estimate of yn+1 by means of a more accurate formula is known as
PredictorCorrector method. A Predictor Formula is used to predict the value of yn+1
and then a Corrector Formula is applied to calculate a still better approximation of yn+1.
Now we study two such methods namely (i) Milnes method and (ii) Adams Bashforth
method.

(I) Milnes Method:


dy
f ( x, y ), y ( x0 ) y 0 . To find an approximate value of y at x=x0+nh
dx
by Milnes method, we proceed as follows: Using the given value of y ( x0 ) y 0 , we

Given

compute y ( x1 ) y ( x0 h) y1 , y ( x 2 ) y ( x0 2h) y 2 and


using Taylors series method.

y ( x3 ) y ( x0 3h) y 3

Next, we calculate f1 f ( x1 , y1 ), f 2 f ( x 2 , y 2 ) and f 3 f ( x3 , y 3 ) . Then, the


value of y at x = x4 = x0+4h can be found in the following two stages.
I Stage : Predictor Method
y 4( P ) y 0

4h
2 f1 f 2 2 f 3
3

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Then we compute f 4 f ( x 4 , y 4( P ) )
II Stage : Corrector Method
h
f2 4 f3
3

4
f

y 4( C ) y 2

Then, an improved value of f4 is computed and again, corrector formula is applied to find
a better value of y4. We repeat the step until y4 remains unchanged.

(II) Adams Bashforth Method:


dy
f ( x, y ), y ( x0 ) y 0 . Using the given value of y ( x0 ) y 0 , we first compute
dx
y ( x 1 ) y ( x0 h) y 1 , y ( x 2 ) y ( x0 2h) y 2 and y ( x 3 ) y ( x0 3h) y 3 using
Taylors series method.

Given

Next, we calculate f 1 f ( x 1 , y 1 ), f 2 f ( x 2 , y 2 ) and


value of y at x = x1 (or y1) can be determined in two stages:

f 3 f ( x 3 , y 3 ) . Now, the

I Stage : Predictor Method


y1( P ) y 0

h
55 f 0 59 f 1 37 f 2 9 f 3
24

Next, we compute f1 f ( x1 , y1( P ) ) . To find a better approximation to y1, the following


corrector formula is used.
II Stage : Corrector Method
y1( C ) y 0

h
9 f1 19 f 0 5 f 1 f 2
24

Then, an improved value of f1 f ( x1 , y1(C ) ) is calculated and again, corrector formula is


applied to find a better value of y1. This step is repeated until y1 remains unchanged and
then proceeds to calculate y2 as above.
Problems:
1. Use Milnes method to find y(0.3) for the IVP
Solution:

dy
x2 y2 ,
dx

y ( 0) 1

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

First, let us find the values of y at the points x = -0.1, x = 0.1 and x = 0.2 by using
Taylors series method for the given IVP.
Taylors expansion of y(x) about the point x = 0( = x0) is
y ( x) y (0) xy / (0)

x 2 //
x 3 ///
y ( 0)
y ( 0)
2
6

-------- (1)

Given

y / ( x) x 2 y 2
y // ( x) 2 x 2 yy /
y /// ( x) 2 2 yy // 2( y / ) 2

y / ( 0) 0 1 1
y // (0) 2 1 1 2
y /// (0) 2 4 2 8

Using the values of y(0), y/(0), y//(0) and y///(0) in (1), we get
y ( x) 1 x x 2

4x 3
3

Putting x = -0.1, x = 0.1 and x = 0.2 in the above expression, we get


y(-0.1) = 0.9087, y(0.1) = 1.1113 and y(0.2) = 1.2507
Given:

x0 0.1, y 0 0.9087 and f 0 0.8357


x1 0, y1 1 and f1 1
x 2 0.1, y 2 1.1113 and f 2 1.2449
x3 0.2, y 3 1.2507 and f 3 1.6043
To Find :

y 4 y ( x 4 ) y (0.3)

I Stage : Predictor Method


4h
2 f1 f 2 2 f 3
3
4(0.1)
(2 1) 1.2449 2 1.6043
0.9087
3
= 1.4372
Now we compute f 4 f (0.3,1.4372) 2.1555
y 4( P ) y (0.3) y 0

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

II Stage : Corrector Method


h
f2 4 f3 f4
3
0 .1
1.2449 (4 1.6043) 2.1555
y 4( C ) y (0.3) 1.1113
3
= 1.4386
Now, we compute f 4 f (0.3,1.4386) 2.1596
y 4( C ) y (0.3) y 2

y 4( C ,1) y (0.3) 1.1113

0 .1
1.2449 (4 1.6043) 2.1596
3

y(0.3) = 1.43869
Hence, the approximate solution is y(0.3) = 1.43869
dy
x y 2 , y (0) 0 , y(0.2) = 0.02, y(0.4) = 0.0795 and y(0.6) = 0.1762.
dx
Compute y(1) using Milnes Method.

2. Given

Solution:

Stage - I : Finding y(0.8)


Given:

x0 0, y 0 0 and f 0 f ( x0 , y 0 ) 0

x1 0.2, y1 0.02 and f1 f ( x1 , y1 ) 0.1996


x 2 0.4, y 2 0.0795 and f 2 f ( x 2 , y 2 ) 0.3937
x3 0.6, y 3 0.1762 and f 3 f ( x3 , y 3 ) 0.56895
To Find :

y 4 y ( x 4 ) y (0.8)

I Stage : Predictor Method


y 4( P ) y (0.8) y 0

4h
2 f1 f 2 2 f 3
3

4 ( 0 .2 )
(2 0.1996) 0.3937 2 2 0.56895
3
= 0.30491
0

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Now we compute f 4 f (0.8,0.30491) 0.7070


II Stage : Corrector Method

4
f

f2 4 f3

3
0 .2
0.3937 4 0.56895 0.7070
y (0.8) 0.0795
3
= 0.3046

y 4( C ) y (0.8) y 2
y 4( C )

Now f 4 f (0.8,0.3046) 0.7072


Again applying corrector formula with new f4, we get
y 4( C ,1) y (0.8) 0.0795

0 .2
0.3937 4 0.56895 0.7072
3

y(0.8) = 0.3046

Stage - II : Finding y(1.0)


Given:

x1 0.2, y1 0.02 and f1 f ( x1 , y1 ) 0.1996


x 2 0.4, y 2 0.0795 and f 2 f ( x 2 , y 2 ) 0.3937
x3 0.6, y 3 0.1762 and f 3 f ( x3 , y 3 ) 0.56895
x 4 0.8, y 4 0.3046 and f 4 f ( x 4 , y 4 ) 0.7072
To Find :

y 5 y ( x5 ) y (1.0)

I Stage : Predictor Method


y 5( P ) y (1.0) y1

4h
2 f 2 f 3 2 f 4
3

4 ( 0 .2 )
(2 0.3937) 0.56895 2 0.7072
3
= 0.45544
Now we compute f 5 f (1.0,0.45544) 0.7926
0.02

II Stage : Corrector Method


y 5( C ) y (1.0) y 3

h
f3 4 f4 f5
3

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

y 5( C ) y (1.0) 0.56895

0 .2
0.56895 4 0.7072 0.7926
3

= 0.4556
Now f 5 f (1.0,0.4556) 0.7024
Again applying corrector formula with new f5, we get
0 .2
0.56895 4 0.7072 0.7924
y 5( C ,1) y (1.0) 0.56895
3

y(1.0) = 0.4556

dy
x 2 1 y , y (1) 1, y (1.1) 1.233, y (1.2) 1.548, y (1.3) 1.979 .Evaluate
dx
y(1.4) by Adams Bashforth method.

3. Given

Solution:

Given:

x 3 1, y 3 1 and f 3 2

x 2 1.1, y 2 1.233 and f 2 2.70193


x 1 1.2, y 1 1.548 and f 1 3.66912
x0 1.3, y 0 1.979 and f 0 5.03451
To Find :

y1 y ( x1 ) y (1.4)

I Stage : Predictor Method


y1( P ) y (1.4) y 0
1.979

h
55 f 0 59 f 1 37 f 2 9 f 3
24

(0.1)
(55 5.03451) (59 3.66912) (37 2.70193) (9 2)
24

= 2.57229
Now we compute f1 f (1.4,2.57229) 7.0017
II Stage : Corrector Method

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

y1( C ) y (1.4) y 0

h
9 f1 19 f 0 5 f 1 f 2
24

0 .1
(9 7.0017) (19 5.03451) (5 3.66912) 2.70193
24
y(1.4) = 2.57495
1.979

Now, let us compute f1 f (1.4,2.57495) 7.0069


0 .1
(9 7.0069) (19 5.03451) (5 3.66912) 2.70193
24
= 2.57514
Again f1 f (1.4, 2.57514) 7.0073
0 .1
(9 7.0073) (19 5.03451) (5 3.66912) 2.70193
y1( C , 2 ) 1.979
24
y1( C ,1) 1.979

y(1.4) = 2.57514
4. Given

dy
x 2 y,
dx

y (0) 1 . Find y(0.4) by Adams method.

Solution:

First, let us find the values of y at the points x = 0.1, x = 0.2 and x = 0.3 by using
Taylors series method for the given IVP.
Taylors expansion of y(x) about the point x = 0( = x0) is
y ( x) y (0) xy / (0)

x 2 //
x 3 ///
y ( 0)
y ( 0)
2
6

-------- (2)

Given

y / ( x) x 2 y
y // ( x) 2 x y /
y /// ( x) 2 2 y //

y / ( 0 ) 0 1 1
y // (0) 0 (1) 1
y /// (0) 2 1 1

Using the values of y(0), y/(0), y//(0) and y///(0) in (2), we get
y ( x) 1 x

x2 x3

2
3

Unit I : Numerical Methods Prepared by Dr. M. Sankar, SCE, Bangalore

Putting x = 0.1, x = 0.2 and x = 0.3 in the above expression, we get


y(0.1) = 0.9051, y(0.2) = 0.8212 and y(0.3) = 0.7492
Let

x 3 0, y 3 1 and f 3 1

x 2 0.1, y 2 0.9051 and f 2 0.8951


x 1 0.2, y 1 0.8212 and f 1 0.7812
x0 0.3, y 0 0.7492 and f 0 0.6592

y 1 y ( x1 ) y ( 0 . 4 )
To Find :
I Stage : Predictor Method
h
y1( P ) y (0.4) y 0 55 f 0 59 f 1 37 f 2 9 f 3
24
(0.1)
55 (0.6592) 59 (0.7812) 37 (0.8951) 9 (1)
0.7492
24
= 0.6896507
Now we compute f1 f (0.4,0.6896507) 0.5296507
II Stage : Corrector Method
y1( C ) y (0.4) y 0
0.7492

h
9 f1 19 f 0 5 f 1 f 2
24

0 .1
9 (0.5297) 19 (0.6592) 5 (0.7812) 0.895125
24

y(0.4) = 0.6896522
Assignments:
1. Using Adams method find y(1.4) for the IVP x2y/ + xy = 1; y(1) = 1, y(1.1) = 0.996,
y(1.2) = 0.986, y(1.3) = 0.972.
dy
2. Given
0.5 xy ; y (0) 1 . Find y(0.4) using Adams Bashforth predictor
dx
corrector formulae.
3. Solve by Milnes predictor corrector method, the differential equation
dy
y x 2 with the following starting values : y(0) = 1, y(0.2) = 1.12186,
dx
y(0.4) = 1.4682, y(0.6) = 1.7379 to find the value of y when x = 0.8.
4. Using
Milnes
method,
obtain
the
solution
of
the
equation
1
y / 1 x 2 y 2 ; y (0) 1 at x = 0.4.
2
Answers : (1) 0.94934, (2) 1.0408, (3) 2.0111 & (4) 1.2797

Das könnte Ihnen auch gefallen