Numerical Integration Techniques Guide
Numerical Integration Techniques Guide
Complied by
April, 2020
Jimma, Ethiopia
Chapter One
- Numerical Integration
- Trapezoidal Rule
- Weddle’s rule
This integral represents the area between y f (x) , the x –axis and the lines x a & x b .
This integration is possible as far as f (x ) is explicitly given and the function is integrable.
Now suppose set of (n+ 1) paired values are given. First as we did in the case of numerical
p x dx
b
differentiation, we find f (x ) by an interpolating polynomial Pn (x) and obtain a
n which
p x dx .
b
can approximate the value for a
n
u u 1 2 u u 1u 2 3
y x y0 uy0 y0 y0 ...1
2! 3!
2
x x0
Here, u , h is the interval of differencing.
h
x x0 x x0
Since xn x0 nh and u un
h h
x 0 nh
f x dx f x dx
xn
Thus, x0 x0
x 0 nh
Pn x dx . Where Pn (x) is interpolating polynomial of degree n.
x0
n u u 1 2 u 3 3u 2 2u 3
h y0 uy0
y0 y0 ... du
0
2! 3!
n
u3 u 2 u4
2 u3 u 2
u
h uy0 y0 3 2 2 y0 4 3 y0 ...
2 2! 3!
0
n2 1 n3 n 2 1 n4
h ny0 y0 2 y0 n3 n 2 3 y0 ...(2)
2 2 3 2 6 4
formula.
By taking different values for n we get a number of special formulas. Here we try to look for
some values of n for which their practical application is very important in different disciplines of
3
Trapezoidal Rule
x0 nh x0 h
f x dx f x dx h 1. y0 y0
1
x0 x0
2
h y0 y1 y0
1
2
h
y0 y1
2
x 0 nh
f x dx f x dx
xn
x0 x0
x 0 nh x0 2 h x 0 nh
f x dx f x dx ... f x dx
x0 x0 h x 0 n 1h
h
y0 y1 h y1 y2 ... h yn 1 yn
2 2 2
h
y0 yn 2 y1 y2 ... yn 1
2
Even though this method is very simple for calculation, the error in this case is significant.
That is,
yx y0 x x0 y
x x0 ''
2
y0 ...
'
1
0
2!
4
x1
ydx y0 x x0 y0
x1 x x0 ''
2
y0 ...dx
'
2!
x0 x0
x x0 ' x x0 ''
x1
2 3
y0 x y0 y0 ...
2! 3! x0
y0 x1 x0
x1 x0 2 y ' x1 x0 3 y '' ...
0 0
2! 3!
h 2 ' h3 ''
hy0 y0 y0 ... (2)
2! 3!
h
y0 y1 Area of the first trapezium = A0 say
x1
x0
ydx
2
yx1 y1 y0 x1 x0 y
x1 x0 ''
2
y0 ...
'
0
2!
h 2 ''
y0 hy0' y0 ...
2!
h h 2 ''
A0 y0 y1 y0 y0 hy0
h '
y0 ...
2 2 2!
h2 ' h3 ''
hy0 y0 y0 ...
2 2.2!
3 '' 1 1
x1
x0 ydx A0 h y0 ...
3! 2.2!
5
1
h3 y0'' ...
2
1 3 ''
The error made in the first interval ( x0 , x1 ) is h y0 ...
2
1
Similarly the error in the ith interval h yi 1
3 ''
1
E h3 y0'' y1'' y2'' ... yn'' 1
2
E
nh3
12
M
where M max y0'' , y1'' , y 2'' ,...
b a h 2 M ba
if the interval is (a, b) and h
12 n
The accuracy of the result can be improved by increasing the number of intervals and
18 4
f xdx h2 y
x2
0 4y0 2 y0 since the other terms vanish (become zero).
x 23 2
h2 y0 2 y1 y0 E 1 y0
1 2
3
h2 y0 2 y1 2 y0 y2 2 y1 y0
1
3
6
1 4 1
h y2 y1 y0
3 3 3
h
y2 4 y1 y0
3
f x dx
h
y n2 4 y n1 y n
xn
xn 2 3
Adding all these integrals, if n is even positive integer, then y 0 , y1 , y 2 , y3 ,..., y n are odd in
number; we have
h
y0 4 y1 y2 y2 4 y3 y4 ... yn 2 4 yn 1 yn
3
h
y0 yn 2 y2 y4 ... yn 2 4 y1 y3 ... yn 1
3
x 9 19 1 81
x03 f ( x)dx h3 y 0 y0 2 y0 27 9 3 y0
2 2 2 6 4
h3 y0 y1 y0 E 1 y0 E 1 y0
9 9 2 3 3
2 4 8
h3 y0 y1 y0 y2 2 y1 y0 y3 3 y2 3 y1 y0
9 9 9 3
2 2 4 8
3h
y3 3 y2 3 y1 y0
8
7
If n is a multiple of 3,
x nh x 3h x 6h x nh
x00 f ( x)dx 0 f ( x)dx 0 f x dx ... 0 f x dx
x0 x 3h x0 ( n3) h
0
3h
y0 3 y1 3 y2 y3 y3 3 y4 3 y5 y6 ... yn 3 3 yn 2 3 yn 1 yn
8
3h
y0 yn 3 y1 y2 y4 y5 ... yn 2 yn 1 2 y3 y6 yn
8
Weddle’s Rule
x0 6h
f ( x)dx h 6 y0 18y0 72 182 y 0 324 216 363 y0 ...
1 1
x0 2 6
123 4 33 41 6
h6 y0 18y0 272 y0 243 y0 y0 5 y0 y0
10 10 140
41 6 42 6 h 6
Now replace the term y0 by y0 , by doing this, the error introduced is only y0
140 140 140
we get
x0 6h
x0
f x dx
3h
y0 5 y1 y 2 6 y3 y 4 5 y5 y6
10
x 12h
x006h f x dx 10 y 5 y 7 y8 6 y 9 y10 5 y11 y12
3h
Similarly, 6
x nh
x00(n6)h f x dx 10 y 5 y n 5 y n 4 6 y n 3 y n 2 5 y n 1 y n
3h
and n 6
8
x nh
x00 f x dx
3h
y0 5 y1 y 2 6 y3 y 4 5 y5 2 y6 5 y7 y8 6 y9 y0 5 y11
10
... 2 y n 6 5 y n 5 y n 4 6 y n 3 y n 2 5 y n 1 y n
y y0 x x0 y0'
x x0 2 y '' x x0 3 y ''' ... ...1
0 0
2! 3!
y0 x2 x0
x2 x0 2 y ' x2 x0 3 y '' x2 x0 4 y ''' ...
0 0 0
2! 3! 4!
h
y0 4 y1 y 2 , by Simpson’s rule
x2
Now let A1 area x ydx
0 3
y1 y0 x1 x0 y0'
x1 x2 y '' ...
0
2!
h 2 '' h3 '''
y0 hy0' y0 y0 ...
2! 3!
9
4h 2 '' 8h3 '''
y2 y0 2hy '
0 y0 y0 ...
2! 3!
h
y0 y0 ... y0 2hy0' 2h 2 y0'' ...
h 2 '' h3 '''
A1 0
y 4
y0 hy0
'
3 2! 3!
4 5
ydx A1 h5 y04 ...
x2
x0
15 18
h 5 4
y0 ... Omitting the remaining terms involving h 6 and higher powers of h .
90
h 5 4
This means that the error made in x0 , x2 is y0 ...
90
h 5 4
Similarly, the error made in x2 , x4 is y2 and so on.
90
nh5
E M , where M is the maximum value of y04, y24 ..., y24n 2
90
Since x2 n , y2 n is the last paired value because we require odd number of ordinates to apply
E
b a h 4
M
180
Examples
10
7
1. Evaluate
1
x 2 dx by using
a) Trapezoidal rule
Solution
Here y ( x) x 2 and the interval length is 7-1 = 6 so we divide this interval into 6 equal parts
6
with h 1
6
x: 1 2 3 4 5 6 7
y: 1 4 9 16 25 36 49
a) By Trapezoidal rule
h
y1 y7 2 y2 y3 y4 y5 y6
7
1
x 2 dx
2
1
1 49 24 9 16 25 36 115
2
1
y1 y7 2 y3 y5 ) 4( y2 y4 y6
7
1
x 2 dx
3
1
1 49 29 25 44 16 36
3
= 114
3
y1 y7 3 y2 y3 y5 y6 2 y4
7
So
1
x 2 dx
8
3
1 49 34 9 25 36 216
8
11
= 114
7
7 x3 1 1 342
x dx 73 114
2
1 3 1 3 3 3
dx
h 0.2 , and hence
1
2. Evaluate 1 x
0 2
, using Trapezoidal rule with
Solution
yx
1
Let
1 x2
dx h
y0 y5 2 y1 y2 y3 y4
1
1 x
0 2
2
0.2
1 0.5 20.961538461 0.862068965 0.735294117 0.6097566097
2
= 0.783731528
1 dx
1 x tan 1 x 0
1
2
0 4
0.783731528
4
3.134926112
To compare this approximated value of with its actual value using calculator 3.141592654 ,
12
3. From the table below, find the area bounded by the curve and
Solution
i) By Trapezoidal rule
f x dx
0.01
1.93 2.08 21.95 1.98 2.01 2.03 2.06
7.53
7.47 2
= 0.12035
f x dx
0.01
1.93 2.08 21.98 2.03 4 41.95 2.01 2.06
7.53
7.47 3
0.120366667
f x dx
3(0.01)
1.93 2.08 31.95 1.98 2.03 2.06 22.01
7.53
7.47 8
0.1203375
f x dx
3(0.01)
1.93 51.951.98 62.01 2.03 5(2.06) 2.08
7.53
7.47 10
0.12039
As we can see from these rules the area is 0.1203 (correct to four decimal places)
13
5.2
4. Evaluate the integral I 4 nxdx using the rules so far developed.
Solution
1 .2
Since b a 5.2 4 1.2 let us divide the interval into 6 equal parts, i.e.; h 0 .2
6
x ln x x ln x
i) By Trapezoidal rule
0.2
1.386294361 1.648658626 2(1.435084525 1.481604541
5.2
nxdx
4 2
1.526056303 1.568615918 1.609437912)]
= 1.827655139
0.2
1.386294361 1.648658626 2(1.481604541 1.568615918) 4
5.2
nxdx
4 3
(1.435084525 1.526056303 1.609437912)]
1.827847258
0.2
1.386294361 1.648658626 3(1.435084525 1.481604541) 3
5.2
nxdx
4 3
(1.568615918 1.609437912) 2(1.526056303)
1.827847258
14
3(0.2)
1.386294361 51.435084525 1.481604541 61.526056303
5.2
4
nxdx
10
6 (1.526056303) 1.1.568615918 51.609437912 1.648658626
1.827847407
By actual integration,
nxdx xnx 1
5.2
1.827847409
5.2
4 4
1
e dx by Simpson’s one-third rule correct to five decimal places.
x
5. Evaluate 0
Solution
The interval b a 1
Since error E
b a h 4 M , where M = Max (e x ) in the range
180
1 4
h e
180
6
Now we require E 10
h 4e
10 6
180
1
180 10 6 4
h 0.090207886 0.1
e
15
1
e x dx
0
0.1
3
1 e 2 e0.2 e0.4 e0.6 e0.8 4 e0.1 e0.3 e0.5 e0.7 e0.9
1.718282782
1
1
e x dx e x e 1 1.718281828
0 0
1
e dx 1.71828 which is the same as the exact value.
x
Correct to five decimal places 0
and (4,2.1) . Obtain the area bounded by the curve, the x -axis, x 1 and x 4 .
b 4
Area = ydx
a 1
ydx
0.5
2 2.1 22.7 3 4(2.4 2.8 2.6)
3
1
4.1 11.4 31.2 7.7833 sq. units
6
b 4
Volume = a y dx 1 y dx
2 2
0.5 2
3
2 2
2 2
2 2.1 2 2.7 3 2 4 2.4 2.8 2.6
2
8.41 32.58 81.44 20.405 = 64.1041981 cubic units.
6
x: 0 10 20 30 40 50 60 70 80
d: 0 4 7 9 12 25 14 8 3
16
Solution
80
Area of cross-section =
0
ydx
10
0 3 2(7 12 14) 4(4 9 15 8) = 710 sq. meters
3
8. The table below gives the velocity v of a moving particle at time t second. Find the
distance (S) covered by the particle in 12 seconds and also the acceleration at t 2
seconds.
t: 0 2 4 6 8 10 12
v: 4 6 16 34 60 94 136
Solution
ds dv
We know that v and a
dt dt
To get S
2
4 136 216 60 46 34 94
12
S
0
vdt
3
= 552 meters
dv
To find a, a first form the difference table
dt t 2
t v v 2 v 3v
0 4
2
8
2 6
10 0
8
4 16
18 0
8
6 34
26
0
8 60 8
34
0
17
10 94
42 8
12 136
dv 1 1 2 1 3
v0 v0 v0
dt t 2 h 2 3
Taking v 0 = 6
1 1
10 8 3m / sec2
2 2
Exercise
2
dx
1. Evaluate 1 x
1
2
taking h 0.2 , using Trapezoidal rule. Can you use
1
2. Compute the value of
0
sin x cos x dx correct to four decimal places
taking h 0.8 .
1 1
x2
3. Find the value of log 2 from 3
0 1 x 3 dx using Simpson’s one-third rule
with h 0.25 .
4. When a train is moving at 30m / sec. steam is shut off and brakes are applied. The speed of the
Time t : 0 5 10 15 20 25 30 35 40
Using Simpson’s rule, determine the distance moved by the train in 40 seconds.
1
5. Evaluate e x dx a) dividing the range into four equal parts
2
18
b) dividing the range into ten equal parts by
2
6. Evaluate e dx taking h
sin x
.
0 6
7. Calculate sin 3 xdx taking h .
0
6
x
2
8. Evaluate log xdx taking four strips.
3
0 .7
e
x
9. Calculate x dx taking 5 ordinates by Simpson’s rule.
0 .5
0 .5
dx
10. Evaluate
0 1 x2
dx by Weddle’s rule, dividing the range into six
parts.
sin x
11. Evaluate
0
x
dx dividing into six equal parts using Simpson’s rule,
19
Chapter Two
Curve Fitting
This chapter covers how to fit a curve for a given set of data points using different methods and
it focuses on the following points:
Regression
- Linear regression
- quadratic regression
- polynomial regression
- multiple regression
In most of the fields of engineering and science, we come across experiments which
involve many variables, and most of the time data is collected or given for discrete values
along a continuum; the relation between these variables can be discussed so easily and for
many of these variables it is very difficult to identify the relation unless we can model the
20
mathematical rules, formulae if any, to determine the quantities of these variables. Actually
2. The quantities/ variables are given so that we will be interested in finding the
relationships between these variables. This process is a little bit difficult because to write
one variable in terms of the other variables (called empirical equation). Most of the time
we may not be able to get an exact relation between these variables and we may get only
This approximating curve is an empirical equation and the method of finding such an
Suppose xi , yi , i 1,2,3,..., n be n sets of observations and the law relating x and
y can be determined by different mathematical systems that clearly explains the relationship
between these sets of n observations xi , yi . Actually, here we may have different approaches to
fit the given data, and one system may approximate better than the other system on the same given
REGRESSION
1. LINEAR REGRESSION
Equation (1) represents a family of straight lines for different values of the arbitrary constants ' a '
and ' b '. The problem now is to determine ' a ' and ' b ' so that the line (1) is the line of "best fit".
The term best fit is interpreted in accordance with the Legendre's principle of least squares which
consists of the deviations of the actual values as given by the line of best fit. As a matter of
21
chance all the points may lie on a straight line and in this case the line is a 'perfect fit' and the
Let Pi ( xi , y i ) be any point in the scatter diagram. Draw Pi M perpendicular to the x-axis meeting
Pi H i Pi M H i M
yi (a bxi )
n n
E Pi H i ( yi a bxi ) 2 is the minimum.
2
i 1 i 1
Using the principle of maxima and minima what we have studied in calculus, the partial
E n
That is, 2 ( yi a bxi ) 0
a i 1
n n n
y i a b xi
i 1 i 1 i 1
n
na b xi i
i 1
22
E n
2 xi ( y i a bxi ) 0
b i 1
. n n n
xi y i a xi b xi
2
ii
i 1 i 1 i 1
Solving for a and b from (i) and (ii), we get the values of a and b , and with these values of a
and b so obtained, equation (1) is the line of best fit to the given set of points xi , y i ,
i 1,2,3,..., n .
x: 5 10 15 20 25
y: 15 19 23 26 30
Solution
n n
yi 5a b xi
i 1 i 1
n n n
xi yi a xi b xi
2
i 1 i 1 i 1
23
x y x2 xy
5 15 25 75
10 19 100 190
15 23 225 345
20 26 400 520
25 30 625 750
75 114 1375 1885
Using these values in the normal equations, we get
5a 75b 114
75a 1375b 1885
Solving for a and b we get a=12.3 and b=0.7 and thus the line of best fit is y 12.3 0.7 x
Example 2. Find the best fitting straight line to the data given below
x is 70.
x : 71 68 73 69 67 65 66 67
y : 69 72 70 70 68 67 68 64
Solution
b X 8a Y
b X 2 a X XY
Calculations:
x y X Y X2 XY
71 69 3 -1 9 -3
68 72 0 2 0 0
24
73 70 5 0 25 0
69 70 1 0 1 0
67 68 -1 -2 1 2
65 67 -3 -3 9 9
66 68 -2 -2 4 4
67 64 -1 -6 1 6
2 -12 50 18
2b 8a 12
50b 2a 18
35 16
Solving for a and b , we get b and a
99 99
35 16
Thus the line of best fit is of the form Y X
99 99
35 16
This implies y 70 ( x 68)
99 99
35 4566
y x
99 99
When x 70 y 70.87
Let y a bx cx 2 be the second degree parabola of best fit to set of n points xi , yi ,
i 1,2,3,..., n .
Using the principle of least squares, we have to determine a,b, and c so that
n
E yi a bxi cx 2
i is minimum.
i 1
25
Equating to zero the partial derivatives of E with respect to a,b, and c separately, we get the
E
2 yi a bxi cxi2 0
n
a i 1
n n n
yi na b xi c xi2 …………………. (1)
i 1 i 1 i 1
E
2 yi a bxi cxi2 xi 0
n
b i 1
n n n n
xi yi a xi b xi2 c xi3.......... .......... ....( 2)
i 1 i 1 i 1 i 1
E
2 yi a bxi cxi2 xi2 0
n
c i 1
n n n n
xi2 yi a xi2 b xi3 c xi4 .......... .......... ...(3)
i 1 i 1 i 1 i 1
Solving for a,b, and c from (1), (2) and (3), we get with these values of a,b, and c the
X: 0 1 2 3 4
Solution
X Y X2 X3 X4 XY X2Y
0 1 0 0 0 0 0
26
3 2.5 9 27 81 7.5 22.5
Exercise
1. Find the best fitting parabola to the data given below by the
x : 71 68 73 69 67 65 66 67
y : 69 72 70 70 68 67 68 64
If y a0 a1 x a2 x 2 ... ak x k is the kth degree polynomial of best fit to the set of points
i 1
Thus the normal equations for estimating a 0 , a1 , a 2 , ... , a n are obtained on equating to zero the
27
E
0 yi na0 a1 xi a2 xi2 ... ak xik
a0
E n
0 xi yi a0 xi a1 xi2 ... ak x k 1
a1 i 1
E n
0 xik yi a0 xik a1 xik 1 ... ak xi2 k
ak i 1
Exercise
1. Find the polynomial of degree three that best fits the data given below by the method of
x : 71 68 73 69 67 65 66 67
y : 69 72 70 70 68 67 68 64
4. Multiple Regressions
There are different multiple regression forms. For the sake of discussion let us see the following
regression type.
n
E zi axi bxi yi cyi
2
i 1
E n
2 zi axi bxi yi cyi xi 0
a i 1
n n
xi zi a xi2 b xi2 yi c xi yi .......... .......... .......... (1)
i 1 i 1
28
E n
2 zi axi bxi yi cyi xi yi
b i 1
n n n n
zi xi yi a xi2 yi b xi2 yi2 c xi yi2 .......... .......... .......... (2)
i 1 i 1 i 1 i 1
E n
2 zi axi bxi yi cyi yi
b i 1
n n n n
zi yi a xi yi b xi yi2 c yi2 .......... .......... .......... (3)
i 1 i 1 i 1 i 1
By solving (1), (2) and (3) for a,b, and c , we get the best approximation.
Let xi , yi , i 1,2,3,..., n be the n sets of observations of related data and let y ab be the
x
y a b
Let Y log10 , A log10 , and B log , then (*) reduces to
10
Y A Bx which is linear in x and Y , we can find A, B since x and Y are known, and from
y ax b
y a x
log log b log
10 10 10
y a x
Y A bx, letting y log , A log , x log
10 10 10
29
a, b are known and thus y ax b is found out.
Example 1. From the table given below, find the best values of
x: 0 5 8 12 20
Solution
e e
Y A bx log Y A Bx where B = b log
10 10
B x 5 A Y
B x 2 A x xY
x y Y x2 xY
0 3.0 0.4771 0 0
8 1.0 0 64 0
5 A 45B 0.3511
45A 633B 17.1287
30
A 0.4815
B 0.0613
So a 10 A 100.4815 3.0304
e
B b log 0.0613
10
10
b (0.0613) log 0.1411
e
0.1411x
Hence the curve is y 3.0304e
Exercise
1. Fit a straight line to the following data and hence find y ( x 25)
x: 0 5 10 15 20
y: 7 11 16 20 26
x: 1 2 3 4 5
y: 2 3 5 8 10
x: 1 2 3 4 5 6 7 8
31
(0,0,1), (0,1,2), (1,0,4), (1,1,1), (2,0,4), (1,2,5)
a
6. It is given that x , and y are related by y bx to the data below and obtain the best
x
values of a and b.
x: 1 2 4 6 8
32
Chapter Three
In this chapter we are highly interested in finding the solution of ordinary differential
- Predictor-corrector method
In the fields of Engineering and Science, we come across through the natural phenomena that can
for instance, the equation of motion, the equation of deflection of a beam, etc. The solution of
While finding the solution of these differential equations there are number of differential
equations that we cannot solve analytically; however, in such situations, depending on the nature
of the model, we go for numerical solutions of these differential equations. In many researches,
especially after the advent of modern computers, the numerical solutions of the differential
33
Thus, in this part we try to look some of the methods of numerical solutions that are
approximate solutions and in many cases these solutions are in the required (desired) degree of
dy
Suppose we want to solve f ( x, y ) with the initial condition y ( x0 ) y 0 .
dx
Let y y (x) be the exact solution. If we plot and draw the graph of
y y (x ) , (the exact curve) and also draw the approximate curve by plotting
Approximate solution
Q
P Exact solution
(x0,y0)
QM = approximate value
PM = exact value at x = xi
Then QP = QM-PM
M
= yi – y(xi) = is called
f x, y ........(1)
dy
Suppose y '
dx
34
y ' ' x0 x x0 2 y ' ' ' x0 x x0 3
y x y x0 y ' x0 x x0 ....
2! 3!
dy d2y
where y ' x0 , y ' ' x0 2 , etc
dx x x0 dx x x0
x2
y x y 0 xy' 0 y ' ' 0 ...
2!
dy
Example 1. Evaluate the solution of the differential equation y2 1
dx
x 0.6 given y (0) 0 and compare this result with its exact
solution.
Solution
y ' ' ' 2 y '2 2 yy' ' y' ' ' 0 2
x2 x3
y x y 0 xy' 0 y ' ' 0 y ' ' ' 0 ...
2! 3!
35
x 3 16x 5
0 x2 ...
3! 5!
y ( 0) 0
y0.2 0.2
0.23 2 0.25 0.2 0.008 2 0.00032 0.4213
3 15 3 15
y0.6 0.6
0.63 2 0.65 0.6720
3 15
dy
Exact solution y 2
1
dx tan 1 y x c y tan x
This table shows that when the distance of x from x 0 increases the error also increases.
In this example, we have expanded y (x ) in the neighborhood of x 0 and used the same
Now instead of doing this, after getting y( x1 ) y(0.2) , expand y (x ) again in the
neighborhood of x 0.2 and use this result to get y (0.6) . In doing so, we can minimize the
error.
36
y' ' 0.2x 0.2 2 y' ' ' 0.2x 0.2 3
yx y0.2 y' 0.2x 0.2 ...
2! 3!
y (0.2) 0.2027
y 0.4 0.2027 1.04110.4 0.2 0.4 0.22 2.3389 0.4 0.23 ...
0.4221
2 6
0.422480536 0.4225
When we compare this value with the actual one i.e. 0.4228, we see that the error is only 0.0003,
nearly 0.07%
Therefore, to reduce the error, each time obtain the power series of y (x ) at x xi 1 and use this
x3
First we got y ( x) x ... in terms of x and then we substituted
3
37
x x1 0.2 . Instead, without getting y (x ) as a function of x we can directly get y ( x1 ) = y (0.2)
as
( x1 , y1 ), ( x2 , y 2 ),... which satisfy approximately a pre-assigned but not known particular solution.
That is,
dry
Where y r x0 r
dx x x
0
, where h x1 x0 or x1 x0 h
Even though the series in (2) is an infinite series, we can truncate it at any convenient term, if h
38
Now, once if we get y , we can calculate y1' , y1'' ,... , etc by using
y f ( x, y )
x x1 , we get
h 2 '' h3 '''
y2 y1 hy1' y1 y1 ...
2! 3!
h 2 '' h3 '''
yn 1 yn hyn' yn yn ...
2! 3!
Since this is an infinite series, to get an approximate value we have to truncate it at some term to
Now, let us consider the terms up to and including h n and neglect terms involving h n 1 and
higher powers of h . The Taylor algorithm used this way is said to be of nth order.
Thus, the truncation error is O(h n 1 ) . If h is small enough we can neglect terms after the nth
h n n
f where x0 x1 if x1 x0 h
n!
dy
Example 1. Solve x y, given y (1) 0 , and find y (1.1), y (1.2) by using
dx
Taylor’s method.
Solution
y0 y x 1 0
dy
y' x y
dx
39
y ' ' y '1 y0' x0 y0 1 0 1
y1.1 0 0.11
0.12 2 0.13 2 0.14 2 0.15 2 ...
2! 3! 4! 5!
0.11033847
y1' ' ' y1 2.2103384
y2 0.11033847 0.11.21033847
0.1
2
2.21033847 0.1 3
2.21033847
2 3!
0.1 2.21033847 ...
4
4!
0.2461077
40
dy
x y
dx
dv dy
Let x y v 1
dx dx
dv dv
v 1 and dx
dx v 1
x c n v 1
x c n x y 1
x y 1 exc
Since y (1) 0
2 0 e c 1
c 1 n 2 c n 2 1
y x 1 2e x 1
x 2 y 2 and y0 1 .
dy
four decimal places, given
dx
Solution
dy
y ' x 2 y 2 here x 0 0 and y0 1, h 0.1
dx
y ' 0 02 12 1
41
y0'' ' 2 2 y0' 2 y0 y0' ' 8
y04 4 y0' y0'' 2 y0' y0'' 2 y0 y0''' 6 y0' y0'' 2 y0' y0'' 28
1.11145
1 xy and y0 0
dy
dx
Solution
y ' 1 2 xy y0' 1 2 x0 y0 1
y' ' ' 2 y' y' xy' ' y0''' 22 0 4
y 5 2 4 y ' ' ' xy4 y05 32, etc
y0.2 0 0.21
0.22 0 0.23 4 0.24 0 0.25 33 ...
2! 3! 4! 5!
42
0.194752003
y0'' 2 x0 y0' y0 20.20.9220992 0.194752063 0.758343806
. y0' ' ' 2 2 y0' x0 y0'' 20.2 0.7583436806 20.9220992
3.38505933
3! 4!
0.359883723
Solution
y' x 2 y y0' 1
43
y 4 y ' ' ' y04 1
y (0.1) 1 (0.1)(1)
0.1
2
1 0.1 1
0.12 1 0.1 3 1 0.1 4 1 0.1 5 1 ...
2 3! 4! 5!
= 0.905125
f x, y , z and g x, y , z
dy dz
dx dx
y ( x0 ) y 0 , z x0 z 0
44
can be solved by Taylor series method as given below:
Solution
y1 y(0.1) ? z1 z0.1 ?
h 2 '' h 3
y1 y 0.1 y 0 hy '
0 y0 y 0 ... …… (1)
2! 3!
h 2 '' h3 '''
and z1 z (0.1) y0 hy0' z0 z0 ... ..... (2)
2! 3!
y0 1 z0 1
y01 z0 x0 1 z0' x0 y0 0 1 1
z04 y0''' 2
45
y1 1 0.1
0.01
0 0.0012 0.00010 ...
2 6 24
= 1+0.1+0.000333+…
= 1.1003
z1 1 0.1
0.01
2 0.0010 0.00012 ...
2 6 24
Solution
Here x 0 0, y 0 2 and z 0 1
y' x z z' x y 2
y' ' ' z' ' z' ' ' 2 y' 2 yy' '
2
y 4 z ' ' ' etc z 4 4 y ' y ' ' 2 y ' y ' '2 yy' ' ' 6 y ' y ' '2 yy' ' etc
y05 30 z05 74
y(0.1) 2 (0.1)(1)
0.12 3 0.13 3 0.14 10 0.15 30 ...
2 6 24 120
46
= 2.084544167
z (0.1) 1 (0.1)(4)
0.1
2
3 0.1
3
10 0.1
4
30 0.1
5
74 ...
2 6 24 120
= 2.084544167+0.267132966-0.016226621-0.0003105449027
- (0.000003091501458) +…
a lower order differential equation. A second order differential equation can be reduced to a first
order differential equation by transforming y z and then the given equation can be solved so
easily.
d2y dy
Suppose f x, y, …… (1)
dx
2
dx
y' ' f x, y, y' is the given differential equation together with the given initial
conditions
p ' f ( x, y , p )
h 2 '' h3 '''
p1 p0 hp0' p0 y0 ... where p1 px x1 & x1 x0 h …… (*)
2 3!
47
h 2 '' h3 '''
y1 y0 hy '
0 y0 y0 ... becomes
2 3!
h2 h3
y1 y 0 hp0 p0 p0 ... ...(**)
2! 3!
Since p' f ( x, y, p ) and taking the derivative of p again and again with respect to x, we get
Hence p0' , p0'' , p0''' ,... can be solved using (**) and (*), so that we can get
y1 & p1 .
Once knowing y1 and p1 we can get p1' , p1'' , p1''' ,... at x1 , y1
Again using
h 2 '' h3 '''
p2 p1 hp1' p1 p1 ... we get some value for p2 and using
2! 3!
h 2 '' h3 '''
y2 y1 hy1' y1 y1 ... we get still some value for y2 .
2! 3!
y' ' ' x y' y 2 0, y0 1, y' 0 0 by using Taylor series method.
2
Solution
z ' xz2 y 2
h 2 ''
Here, z1 z0 hz z0 ... ...1
'
0
2
48
z ' xz2 y 2 y' z
z '' z 2 2 xzz'2 yy' y ' ' z ' , y ' ' ' z ' ' ,....
z' ' ' 2zz'2 xzz' ' zz' xz' 2 yy' ' y'
2
2
z0' x0 z02 y02 1
z0'' 0 and z0 2
'''
z1 0 0.1 1
0.01 0 0.001 2 ...
2 6
= -0.0997
h 2 ''
y1 y (0.1) y0 hy0' y0 ...
2
1 (0.1)( z )
0.1 ' 0.1 ''
2
z
3
z ...
0 0 0
2 6
1 0.10
0.01 0.001
(1) (0) ... = 0.995
2 6
Similarly,
2
y2 y x2 y1 hy1'
h
y1'' ...
2
z1'' 0.1687
49
Using (2),
= 0.9801
Example 8. Solve y' ' y xy' given y0 0 and calculate y (0.1) .
Solution
y ' ' ' y ' y ' xy' ' 2 y ' xy' ' y0'' y0 x0 y0' 1
y 4 2 y ' ' y ' ' xy' ' ' 3 y ' ' xy' ' ' y0''' 2 y0' x0 y0'' 0
x 2 '' x 3 '''
Here y x y0 xy0' y0 y0 ...
2 3!
x2 4
1 0 1 0 x 3 ...
2! 4!
x2 x4 x6
1 ...
2 8 48
1
0.12 0.14 0.16 .... 1.00501252
2 8 48
Exercise
Using Taylor series method, find the values required in each problem.
dy
1. Find y (0.1) given x y , y ( 0) 1
dx
50
2. Find y (0.1) given y x 2 y 1, y (0) 1
dy 1
3. Obtain y ( 4.2) and y ( 4.4) given 2 , y(4) 4 taking h 0.2 .
dx x y
x 3 xy 2
4. Find y (0.1), y (0.2), y (0.3) given y , y (0) 1 .
ex
dy dz
x z, x y 2 and y (0) 2, z (0) 1
dx dx
dx dy
ty 1, tx given x 0, y 1 at t 0
dt dt
x dy
7. Solve for x and y x y t, 2 x t given x 0, y 1 at t 1 .
dt dt
f x, y subject to y ( x0 ) y0
dy
AIM: To solve
dx
f x, y dy f x, y dx
dy
Now
dx
Integrating, y f x, y dx c
x
Setting x x0 , we have
y0 f x, y dx c
x0
y y 0 f x, y dx
x
x0
51
y y0 f x, y dx this type of equation is called an integral equation.
x
x 0
After getting the first approximation y (1) for y , use this value of y (1) in place of y in
y n y0 f x, y n 1 dx
x
x0
This equation is called Picard’s iteration formula. This formula gives the general iterative
formula for y.
The sequence y (1) , y ( 2) ,…, y (n ) should converge to y (x ) ; otherwise the process is not valid.
f
The condition for the convergence of the sequence is both f ( x, y ) and are continuous.
y
f
i.e. f x, y k1 a n d k2 in a region containing the point ( x0 , y0 ) where k1 , k2 are
y
constants.
52
Solution
y' y x 2
y y0
x
x0
y x dx....
2
Hence, x0 = 0, y0 = 1 and f ( x, y ) y x 2
y 1 y x 2 dx .....1
x
y 1 x
1 1 x dx 1 x
0
x3
3
2
Using y(1) again in (1), we get
y 2 1 y 1 x 2 d x
x
x x3
1 1 x x 2 dx
0
3
x 2 x3 x 4
1 x
2 3 12
y 3 1 y 2 x 2 d x
x
x x 2 x3 x 4
1 1 x x 2 dx
0
2 3 12
x 2 x3 x 4 x5
1 x
2 6 12 60
y0.1 1 0.1
0.12 0.13 0.14 0.15
2 6 12 60
53
1.104824833
y0.2 1 0.2
0.22 0.23 0.24 0.25
2 6 12 60
= 1.218528
Note- In getting the value y (0.2) we could have started with x0 = 0.1 and
x
i.e. y 1.104824833 0.1 y0 x dx
2
x
1 x3
y 1.104824833 y0 x
3 0.1
x3 0.13
1.104824833 1.104824833x 1.104824833(0.1)
3 3
x3
0.99467574 1.104824833x
3
y 2 1.104824833
x
0.1
y x dx
1 2
x x3
1.104824833 0.99467574 1.104824833x x 2 dx
0
3
dy
Example 2. Solve x y, given y (0) 1 . Obtain the values of
dx
54
result with the exact solution.
Solution
Here f ( x, y ) x y, x0 0 and y 0 1
y y0 f x, y dx
x
x0
1 f x, y dx
x
y 1 1 f x, y dx
x
1 x,1dx
x
x2
= 1 x 1 dx 1 x
x
0 2
x x2
y 2 1 1 x x dx
0
2
x3
1 x x 2
x x3
y 3 1 x 1 x x 2 dx
0
6
x3 x 4
1 x x2
3 24
x3 x 4
y x 1 x x 2 ...
3 24
55
0.001 0.0001
1 0.1 0.01 ...
3 24
= 1.1103374
y y0 f x, y dx
x
0. 1
x y dx
x
1.1103374
0.1
0.1
= 0.98930366 1.1103374x x 2
y 2 1.1103374 x 0.98930366 1.1103374x x 2 dx
x
0.1
x 1
y 3 1.1103374 0.989970326 1.98930366x 2.1103374x 2 x3 dx
0.1
3
2.1103374 x 3 0.1
3
12
x 0.1
1 4 4
y 3 0.2 1.1103374 0.989970326(0.1) 1.98930366(0.03)
2.1103374(0.007) 0.0015
1
12
= 1.283910904
56
dy
Solving x y analytically, we get y 2e x x 1
dx
y (0.2) = 1.242805516
x 2 y 2 , y 0 1 by Picard’s method
dy
Example 3. Solve
dx
Solution
Here x0 0, y0 1
y y0 f x, y dx = 1 x 2 y 2 dx
x
x0
x
0
Now
y 1 1 x 2 1 dx 1 x
x
0
x3
3
x3
2
y 2 x
1 x 1 x dx
2
0 3
2 x3 1 4 1 7 2 5
1 x x2 x x x
3 6 63 15
2 3 1 4 2 5 1 7
1 x x2 x x x x ...
3 6 15 63
Solution
By Picard’s method
x
x0
x
0
y y0 f ( x, y )dx e x y dx
y 1 e x 0 dx e x 1
0
x
57
y 2 e x e x 1 dx x
0
x
0
x
y 3 e x x dx e x x2
2
1
x x2
y 4 e x e x 1 dx
0
2
x3
x
6
5 x x x3
y e x dx
6
0
x2 x4
e
x
1
2 24
x2 x4
y x e x 1
2 24
Exercise
dy
a) Solve x y 2 1 , given y (0) 0 .
dx
yx
b) Obtain y (0.1) given y and y (0) 1
yx
2. Find the values of y for x 0, x 0.1 and x 0.5 given y x 2 y 2 and which passes
through (0,1) .
x2
3. Given y and y (0) 0 , find y (0.25), y (0.5)
1 y2
58
Euler’s Method
In solving a first order differential equation by numerical methods, we have two types of
solutions:
i) Values of y at specified values of x
ii) A series solution of y in terms of x , which will yield the value of y at a particular
value of x by direct substitution in the series solution.
Taylor and Picard’s method studied so far belong to the first category in finding the numerical
solution of differential equations; the methods due to Euler, Runge-kutta, Adam-Bash Forth and
Milne come under the second category.
The methods of second category are called step-by-step methods because the values of y are
calculated by short steps ahead of equal interval h of the independent variable x .
Euler’s method
x x0 , x1 , x2 ,... where xi xi 1 h
y
i.e. xi x0 ih , i 0,1,2,... P2
P1
Q2
P0
(x1,y1) Q1
M2
M0 M1
x0 x1 x2 x
0
Let the actual solution of the differential equation be denoted by the graph Pi Pi ( xi , yi ) lies on
59
y y0 y' x0 , y0 x x0
= f x0 , y0 x x0
y y0 f x0 , y0 x x0
The value of y on the curve is approximately equal to the value of y on the tangent
at ( x0 , y0 ) corresponding to x xi .
y1 y0 f x0 , y0 x1 x0
i.e. y1 y0 hy0'
Again, we approximate the curve by the line through ( x1, y1 ) and whose slope is f ( x1, y1 ) , we
get
y2 y1 f x1, y1 h
y1 hy1'
In other words, y ( x h) y ( x) hf ( x, y )
In this method, the actual curve is approximated by a sequence of short straight lines.
As the intervals increase the straight line deviates much from the actual curve. Hence the
Q1 P1 error at x x1
60
Example 1. Given y y and y (0) 1 , determine the values of y at
Solution
y y and y (0) 1 ; f ( x, y ) y
By Euler algorithm,
61
Solution
Here h 0.2 , f ( x, y ) x y, x0 0, y 0 1
By Euler algorithm,
y1 y0 hf x0 , y0 y0 hx0 y0
= 1 0.2(0 1) 1.2
= 1.48
= 1.856
= 2.3472
Exact solution is y 2e x x 1
As you can see from the table, the values of y deviate from the exact values as x increases. To
Let the tangent at ( x0 , y0 ) to the curve be P0A. In the interval ( x0 , x1 ) by the previous
62
y11 y0 hf x0 , y0 where y11 M1Q1
y
D
P1 B
(x0,y0) C
A
Q1 (x1y )
P0
x0 x1
x
M0 M1
i.e.
1
2
f x0 , y0 f x1 , y11
That is,
y y0
1
2
f x0 , y0 f x1 , y11 x x
0
y1 y0
1
2
h f x0 , y0 f x1 , y11
h f x0 , y0 f x1 , y0 hf x0 , y0
1
y0
2
In general,
h f xn , yn f xn h, yn hf xn , yn
1
y n 1 y n
2
63
Notice that the difference between Euler’s method and the improved Euler’s method
is that in the improved one we take the average of the slopes at ( x0 , y0 ) and x1 , y11 instead of
In the improved Euler method, we arranged the slopes, whereas in modified Euler method, we
Let P0A be the tangent at ( x0 , y0 ) to the curve. Now let this tangent meet the ordinate at
f x0 h, y0 hf x0 , y0 .
1 1
2 2
k1(x1,y1)
B
(x0,y0)
P0 A
N1
M0 x
0 x0 x0+ h x1=x0+h
Let this line meet x x1 at k1 x1 , y11 .
This y11 is taken as the approximate value of y at x x1
y11 y0 h f x0 h, y0 hf x0 , y0
1 1
2 2
64
In general,
yn 1 yn h f xn h, yn hf xn , yn
1 1
2 2
or yx h yx h f x h, y hf x, y
1 1
2 2
When you read some literature there is some confusion among the authors. Some take the
improved Euler method as the modified Euler method and the modified Euler method is not
mentioned at all.
Euler’s method.
Solution
h f x0 , y0 f x1 , y0 hf x0 , y0
1
y1 y0
2
y1 0
0.2
2
y0 e x 0 y0 h y0 e x 0 e x 0 h
0.1 0 1 0 0.20 1 e0.2
y0.2 y1 0.24214
65
y 2 y1 h f x1 , y1 f x1 h, y1 hf x1 , y1
1
2
y(0.4) y2 0.59116
y 2 xy , y (0) 1 .
Solution
f ( x, y ) 2 xy; x0 0, y 0 1
yn 1 yn h f xn , yn hf xn , yn
h 1
2 2
y1 y0 h f x0 , y0 hf x0 , y0
h 1
2 2
f ( x0 , y0 ) f (0,1) 0
y1 1 (0.25) f (0.125,1)
= 1 (0.25)(2)(0.125)(1)
66
y (0.25) 1.0625
dy
y ' 2 xy 2 xdx
y
Using y (0) 1
y ( 0) c 1
y ex
2
dy
Example 5. Solve the equation 1 y, given y (0) 0 using modified
dx
Solution
y 1 y
f x, y 1 y, f x0 , y0 1 y0 1
y1 y0 h f x0 , y0 h f x0 , y0
h 1
2 2
67
Now again f ( x1 , y1 ) 1 y1 = 1- 0.95 = 0.905
y2 y1 h f x1 h, y1 h f x1 , y1
1 1
2 2
= 0.180975
y3 y2 h f x2 h, y2 h f x2 , y2
1 1
2 2
0.180975 0.1 f 0.2 f 0.2,0.180975
0.1 0.1
,0.180975
2 2
= 0.258782375
h f xn , yn f xn h, yn h f xn , yn
1
yn 1 yn
2
h f x0 , y0 f x0 h, y0 h f x0 , y0
1
y1 y0
2
f x0 , y0 1 y 1
= 1 - 0.1 0.9
h f x1 , y1 f x1 h, y1 h f x1 , y1
1
y2 y1
2
68
f x1 , y1 1 y1 1 0.095 0.905
= f (0.2,0.1855) = 0.8145
y2 0.095
0.1
0.8145 0.905 0.180975
2
y3 y2
1
h f x2 , y2 f x2 h, y2 h f x2 , y2
2
0.180975
0.1
1 0.180975 f 0.3,0.180975 0.11 0.180975
2
0.258782375
Exact solution
dy dy
1 y dx
dx 1 y
n1 y x c1 1 y ce x
At x 0, 1 0 ce 0 c 1
y 1 e x
y0.1 0.095162581
y (0.2) 0.181269246
y (0.3) 0.259181779
69
0.3 0.258782375 0.258782375 0.259181779
Solution
h f xn , yn f xn h, yn hf xn , yn
1
y n 1 y n
2
h f x0 , y0 f x0 h, y0 hf x0 , y0
1
y1 y0
2
1
0.1 2
2
x0 y0 f 0.1, y0 0.1 x02 y0
1 0.05 1 0.1 1 0.1 1 0.9055
2
y , y0 1
dy 2x
x 0.2 given
dx y
Solution
h f xn , yn f xn h, yn h f xn , yn
1
y n 1 y n
2
Here x0 0, y 0 1, h 0.1
h f x0 , y0 f x0 h, y0 hf x0 , y0
1
y1 y0
2
70
f x0 h, y 0 hf xn , y n f 0.1,1 0.11 f (0.1,1.1)
20.1
1.1 0.918181818...
1.1
= 0.918182
y1 1
0.1
1 0.918182 1.095909091
2
y2 y1
h
f x1 , y1 hf x1 h, y1 hf x1 , y1
2
20.1
f x1 , y1 1.095909091
1.09590909
0.913412201
f 0.2,1.187250311
20.2
1.187250311
1.187250311
0.850337365
Thus y2 1.095909091
0.1
0.913412201 0.850337365
2
1.184096569
x 2 y 2 , y 0 1
dy
given
dx
Solution
71
By modified Euler method,
y1 y0 hf x0 h, y0 f x0 , y0
1 h
2 2
1 0.1 0.052 1 0.051
2
y (0.1) = 1.1105
y2 y1 hf x1 h, y1 f x1 , y1
1 h
2 2
1.1105 0.1 0.152 1.1726605132
1.250263268
Exercise
dy 2x
2. Compute y (0.3) taking h 0.1 given y , y (0) 1 using improved Euler
dx y
method.
3. Find y (0.6), y (0.8) and y (1) given y x y, y (0) 0 taking h 0.2 by improved
Euler method.
yx
4. Use improved Euler method to find y (0.1) given y , y (0) 1 .
yx
dy
5. Using improved Euler method find y (0.2), y (0.4) given x y , y ( 0) 1 .
dx
y y sin x, y (0) 2
72
7. Use modified Euler method and obtain y (0.2) given y log( x y ), y (0) 1, h 0.2 .
dy y
8. Use improved and modified Euler method, to get y (1.6) if y 2 , if y (1) 1 .
dx x
y 5 2 3 1
10. Given y x y , y (1) find y ( 2) if h 0.125 .
x 2 2
if h 0.1 .
Runge-Kutta Method
y x h y x hy' x
h2
2!
y ' ' x 0 h3 .......... ( 2)
f f dy
y' ' f x y ' f y f x ff y ........ 3
x y dx
Using the values of y and y derived from (1) and (3), in (2) we get
y x h y x hf h f x ff y O h 3
1 2
2
y hf h f x ff y O h 3
1 2
2
........ 4
2 y hf x mh, y mk1 k2
73
and let y ak1 bk2 where a, b and m are constants to be determined to get the better
accuracy of y.
Now expand k 2 and y in powers of h, by Taylor series for two variables, we have
k2 h f x mh, y mk1
2
mh mk1 f
x y
h f x, y mh mk1 f ...
x y 2!
2
mh mk f
x y
1
h f mhf x mhff y ...
2!
Substituting k1 , k2 in y , we get
y ahf b hf mh 2 f x ff y O h3
(a b)hf bmh2 f x ff y O h3 ak1 bk2 .....5
1
a b 1, mb
2
1
a 1 b and m
2b
y 1 bk1 b k2
74
Where k1 hf ( x, y)
h hf
k2 h f x ,y
2b 2b
hf
yx h yx 1 bhf bhf x , y
h
2b 2b
i.e. yn 1 yn 1 b h f xn , yn b h f xn
h
, yn
h
f xn , yn O h3
2b 2b
1
From this general second order Runge-kutta formula, setting a 0 , b 1 , m , we get the
2
k1 hf ( x, y )
1 1
k2 hf x h, y k1
2 2
and y k2 where h x
For n = 3, a similar derivation to the one as the second-order method can be performed. Since
y n 1 y n
1
k1 4k2 k3
6
, where k1 h f ( x, y)
1 1
k2 hf x h, y k1h
2 2
k3 hf ( x h, y k 2k2 )
75
The most popular and commonly used form is the classical fourth-order Runge-kutta method.
y n 1 y n
1
k1 2k2 2k3 k4
6
, where k1 hf x, y
1 1
k2 hf x h, y k1h
2 2
h 1
k3 hf x , y k2 h
2 2
k4 hf x h, y k3h
h 1
y0 k2 hf x0 , y0 k1
2 2
hf x0 , y0 hf x0 , y0
h 1
2 2
y1 y0 hf x0 , y0 hf x0 , y0
h 1
2 2
Thus, the second order Runge-kutta method is simply the modified Euler method.
reduces to
k1 hf x0
1 h
y h f x0 4 f x0 f x0 h
6 2
76
h
h
2 f x0 4 f x0 f x0 h
3 2
h
length by Simpson’s one-third rule. i.e. y reduces to the area by Simpson’s one-third rule.
2
Solution
1
k2 hf x0 h, y0 k1 0.10.05 1 0.05 0.11
1
2 2
k3 hf x0 h, y0 hk2 0.10.05 1 0.055 0.1105
1 1
2 2
1
1
0.1 20.11 20.1105 0.12105
6
= 1.110341667
77
Now starting from ( x1 , y1 ) we get ( x2 , y2 ) . Again apply Runge-kutta algorithm replacing
( x0 , y0 ) by ( x1 , y1 ) .
k
k2 hf x1 , y1 2 0.10.15 1.176384605
h
2 2
0.13263846
y 0.2 1.110341667
1
0.121034166 20.132085875 0.13263846 0.144298012
6
= 1.242805142
y (0.2) 1.242805516
The difference between the exact solution and the fourth order Runge-kutta method is
0.00000037432 .
Solution
i) Second order
78
1
k2 hf x0 h, y0 k1 0.1 1 0.05 0.095
1
2 2
y1 y0 k2
1 0.095 0.905
k2 0.1 0.905 0.0905 0.085975
1
2
k1 hf ( x0 , y 0 ) 0.1
k 2 = - 0.095
k 3 hf ( x0 h, y 0 2k 2 k1 )
1
1
0.1 4(0.095) (0.091
6
0.904833333
79
h 1
k2 (0.1) x1 , y1 k1
2 2
0.1 0.904833333 0.0904833333
1
2
- 0.085959166
- 0.082339833
y 2 y1
1
k1 4k 2 k 3
6
0.904833333
1
0.0904833333 4 0.082339833 0.082339833
6
0.821136249
k1 0.1
k2 0.095
1
k3 hf x0 h, y0 k2 0.1 1 0.0475 0.09525
1
2 2
y1 1
1
k1 2k2 2k3 k4
6
0. 9048375
80
1
k2 0.1 f x0 h, y0 k1
1
2 2
1 1
k3 (0.1) f x0 h, y0 k2
2 2
0.1 0.9048375 0.085959562 0.086185771
1
2
k4 hf x1 h, y1 k3
y2 y1
1
k1 2k2 2k3 k4
6
0.9048375
1
0.09048375 2 0.085959562 0.086185771
6
0.081865172 0.818730902
As we can see from the table fourth order values are closer to the exact values.
y xy 2 , y 0 1 by taking h 0.1
dy
Example 3. Compute y (0.3) given
dx
Solution
y y xy 2 f ( x, y ) ( y xy 2 )
81
x0 0, y 0 1, h 0.1, x1 0.1, x 2 0.2, x3 0.3
0.1 0.95 0.050.95
2
- 0.0995125
h 1
k3 hf x0 , y0 k2
2 2
0.1 f 0.05,0.95024375
0.1 0.95024375 0.050.95024375
2
- 0.09953919
k4 hf x0 h, y0 k3
0.1 f 0.1,0.900460809
0.098154377
y1 1
1
0.1 2 0.0995125 2 0.09953919 0.098154377
6
y0.1 0.900623707
0.098173601
82
h k
k2 hf x1 , y1 1
2 2
0.1 f 0.15,0.851536906
0.096030417
h k
k3 hf x1 , y1 2
2 2
0.1 0.852608498 0.150.852608498
2
0.096164968
k4 hf x1 h, y1 k3
0.1 f 0.2,0.804458738
- 0.093388951
y2 0.900623707
1
0.098173601 2 0.096030417 2
6
0.096164968 0.093388951
0.804631486
k1 hf x2 , y2
0.1 0.804631486 (0.2)(0.804631486) 2
= - 0.093411785
(0.1) f 0.25,0.757925593
h k
k2 hf x2 , y2 2
2 2
= - 0.090153839
83
k
k3 hf x2 h, y2 2 0.1 f 0.25,0.759554566
2
-0.090378535
= - 0.084179227
y3 0.804631486
1
0.093411785 2 0.090153839 2
6
0.090378535 0.084179227
0.714855526
if y y x , y (0.6) 1.7379
2
Solution
k1 hf x0 , y0 0.1 1.7379 0.62 0.13779
h k
k2 hf x0 , y0 1
2 2
0.10.65,1.806795 0.1384295
h k
k3 hf x0 , y0 2
2 2
0.1 1.80711475 0.652 0.38461475
k4 hf x0 h, y0 k3
84
y 0.7 1.7379
1
0.13779 20.1384295 20.138461475 0.138636147
6
= 1.876268016
k1 hf x1 , y1 0.1 1.876268016 0.7 2 0.138626801
h k
k2 hf x1 , y1 1
2 2
h k
k3 hf x1 , y1 2
2 2
k4 hf x1 h, y1 k3
0.1 f 0.8,2.014560224 0.137456022
y 0.8 1.876268016
1
0.138626801 20.138308141 2
6
0.138292208 0.13746022
2.014481936
dy y 2 x 2
given y (0) 1 at x 0.2,0.4
dx y 2 x 2
Solution
y x
85
1 0
k1 hf x0 , y2 0.2 0.2
1 0
h k
k2 hf x0 , y0 1
2 2
1.12 0.12
0.2 2 0.196721311
2
1. 1 0.1
h k
k3 hf x0 , y0 2
2 2
1.0983606562 0.12
0.2 0.196711597
2
1.098360656 0.1
2
k4 hf x0 h, y0 k3
1.1967115982 0.22
0.2 0.18913131
2
1.196711598 0.2
2
= 1.195999521
1.1959995212 0.22
k1 0.2 f x1 , y1 0.2
2
1.195999521 0.2
2
= 0.189118717
k
k2 0.2 f x1 , y1 1 0.2 f 0.3,1.29055888
h
2 2
0.179493515
86
k
k3 hf x1 , y1 2 0.2 f 0.3,1.285746279
h
2 2
0.179347655
0.168804528
y 0.4 1.195999521
1
0.189118717 20.179493515 2
6
0.179347655 0.168804528
= 1.375267119
y ( x0 ) y 0 , z ( x0 ) z 0
Now starting from ( x0 , y 0 , z 0 ) the increments y and z in y and z respectively are given
by formulae
h k m h k m
k2 hf1 x0 , y0 1 , z0 1 m2 hf2 x0 , y0 1 , z0 1
2 2 2 2 2 2
h k m h k m
k3 hf1 x0 , y0 2 , z0 2 m3 hf2 x0 , y0 2 , z0 2
2 2 2 2 2 2
and y
1
k1 2k2 2k3 k4 z
1
m1 2m2 2m3 m4
6 6
87
y1 y0 y and z1 z0 z
dy dz
x z, x y 2 given y (0) 2, z (0) 1 using Runge-kutta
dx dx
Solution
Here x0 0, y0 2, z0 1, h 0.1, f1 ( x, y, z) x z, f 2 ( x, y, z) x y
2
h k m h k m
k2 hf1 x0 , y0 1 , z0 1 m2 hf2 x0 , y0 1 , z0 1
2 2 2 2 2 2
0.085 - 0.41525
h k m h k m
k3 hf1 x0 , y0 2 , z0 2 m3 hf2 x0 , y0 2 , z0 2
2 2 2 2 2 2
0.0842375 - 0.412180625
0.068781937 - 0.424404595
y1 2
1
0.1 2(0.085 2(0.0842375) 0.068781937)
6
88
= 2.084542823
z1 1
1
0.4 2 0.41525 2 0.412180625 0.424404595
6
= 0.586789025
y z' f x, y, y' and y z are the two simultaneous equations with f1 ( x, y, z ) z
and f 2 ( x, y, z) f ( x, y, z) itself.
Once again by applying Runge-kutta method for solving simultaneous first order differential
Solution
z f1 x, y, z
dy
dx
y xz f 2 x, y, z
dz
dx
given y0 1, z0 0, y0 , h 0.1, x0 0
'
89
h k m h k m
k2 hf1 x0 , y0 1 , z0 1 m2 hf2 x0 , y0 1 , z0 1
2 2 2 2 2 2
0.005
k3 hf1 0.05,1 ,0.049875 (0.1) [-1 - (0.05)(-0.05)]
2
(0.1)(0.1,0.09950125,0.099500625)
(0.1)((0.1)(0.09950125) 0.9950125)
- 0.098506243
y1 1
1
0 2(0.005) 2(0.0049875) (0.0099500625)
6
0.995012489
Exercise
In the exercise below, unless specified use fourth order Runge-Kutta method.
dy
2. Obtain the value of y at x 0.2 if y satisfies x 2 y x, y (0) 1
dx
taking h 0.1 .
dy
3. Solve xy for x 1.4 , taking y (1) 2, h 0.2 .
dx
90
dy y x
4. Solve given y (0) 1 , to obtain y (0.2) .
dx y x
du
5. Solve the initial-value problem 2tu 2 , u (0) 1 with h 0.2 on the interval (0,0.6) .
dt
1
6. Evaluate y (0.1), y (0.2), y (0.3) given y ( x 1) y 2 , y (0) 1 .
2
dy y 1
7. Solve 2 , y (1) 1 for y (1.1) taking h 0.05 .
dx x x
dy dz
10. Solve the system: xz 1, xy for x 0.3, x 0.6, x 0.9 taking
dx dx
x 0, y 0, z 1 .
dy dz
11. Solve x z, x y , given y (0) 0, z (0) 1 for x 0.0 to 0.2 taking h 0.1.
dx dx
dy dz xy
12. Evaluate y (1.1), z (1.1) given xyz, , y (1) 0.5, z (1) 1 .
dx dx z
dx dy
given xy t , x(0) 1, ty x, y (0) 1 .
dt dt
91
d 2 x tdx
17. Obtain the value of x (0.1) given 4 x, x(0) 3, x (0) 0 .
dt 2 dt
Predictor-Corrector Method
The methods so far discussed are called single step methods because they use only the
information from the last step computed. But now we try to discuss multi-step methods.
f x, y , y x0 y0
dy
Consider
dx
h f xi , y i f xi 1 , y i 1 ...2
1
y i 1 y i
2
To overcome this difficulty, we calculate y i 1 using Euler’s formula (1) and then we use it on the
right hand side of (2), to get the left hand side of (2). This y i 1 can be used further to get refined
y i 1 on the left hand side. Here, we predict the value of y i 1 from the rough formula (1) and use
in (2) to correct the value. Every time, we improve using (2). Hence equation (1) Euler’s
A predictor formula is used to predict the value of y at y i 1 and a corrector formula is used
f x, y , y x0 y0 numerically.
dy
Suppose our aim is to solve
dx
92
y1 y0 x0 h y x1 y x1 , y2 y x0 2h , ..., yn y x0 nh , where h is a suitable
u u 1 2 u u 1u 2 3
y y 0 u y 0 y0 y0 ...
2! 3!
x x0
, where u x x0 uh
h
Changing y to y
4 uu 1 2 '
h y0' uy0' y0 ... du
0
2
Since x x0 uh dx hdu
u 2 1 2 ' u3 u 2 1 3 ' u 4
Now y4 y0 h uy0' y0' y0 y0 u 3 u 2 ...
2 2 3 2 6 4
1 64
h4y0' 8y0' 8 2 y0' 3 y0' 64 64 16 ...
1
2 3 6
20 8
h4y0' 8y0' 2 y0' 3 y0' ...
3 3
h4y0' 8( E 1)y0' E 1 y0' E 1 y0' 4 y0' ...
20 2 8 3 14
3 3 45
h 4y0' 8( y1' y0' )
20 '
8
14
y0 2 y1' y0' y3' 3 y2' 3 y1' y0' 4 y0' ...
3 3 45
93
20 8 ' 40 ' 20 8 14
h 4 8 y0 8 8 y1 8 y2 y3' h4 y0' ..
3 3 3 3 3 45
8 4 8 14
h y1' y2' y3' h4 y0' ...
3 3 3 45
4h
3
2 y1' y2' 2 y3' y0 ... ....3
14h 4 '
45
Taking into account only up to the third order equation, (3) gives
y4 y0
4h
3
2 y1' y 2' 2 y 3'
…………… (4)
y0
4h
2 f1 f 2 2 f 3
3
y , where
14h 4 ' 14h v
The error happened in (4) is y0 ... and this can be proved to be
45 45
x0 , x4 .
14h 5 v
The error is y and hence (3) becomes
45
y 4 y0
4h
3
2 y1' y2' 2 y3' 45
y
14h v
……..(5)
In general,
yn 1 yn 3
4h
3
2 yn' 2 yn' 1 2 yn'
14h5 v
45
y 1 , where 1 xn 3 , xn 1 ……(6)
To get Milne’s corrector formula, integrate equation (2) between the limits x 0 to x 0 2h .
94
2 uu 1 2 '
y2 y0 h y0' uy0' y0 ... du
0
2
2 u2 1 u3 u 2
h y0' u y0' 2 y0' ...
2
0
0
2 2 3 2
18
h 2 y0' 2E 1y0' 2 E 1 y0' 4 y0' ...
2 4 1
23 15 24
1
1
h 2 y0' 2 y1' y0' y2' 2 y1' y0' 4 y0' ...
3 90
3
h '
h
y0 4 y1' y2' 4 y0' ...
90
…….…(7)
y 2 y0
h '
3
y0 4 y1' y2' ...(8)
h 5 v
y
h 4 '
Here the error is y0 ... and this can be proved to be
90 90
y2 y0
h '
3
y0 4 y1' y2'
h 5 v
90
y
In general,
y n 1 y n 1
h '
3
y n 1 4 y n' y n 1 '
h 5 v
90
y 2 where xn 1 2 xn 1 .
x y given
dy 1
Example 1. Find y ( 2) if y (x ) is the solution of
dx 2
95
Solution
f x, y x y y'
1
2
y n 1 y n 3
4h
3
2 yn' 2 yn' 1 2 yn'
y 4 y0
4h
3
2 y1' y2' 2 y3
Now, y1'
1
x1 y1 1 0.5 2.636 1.568
2 2
y2'
1
x2 y2 1 1 3.595 2.2975
2 2
y3'
1
x3 y3 1 1.5 4.968 3.234
2 2
40.5
y4 2 21.568 2.2975 23.234
3
= 6.871
y4 y2
h '
3
y2 4 y3' y4'
y4'
1
x4 y4 1 2 6.871 4.4355
2 2
y4 3.595
0.5
2.2975 43.234 4.4355
3
= 6.873166667
96
Example 2. Using Milne’s method find y ( 4.4) given 5 xy y 2 0
2
Solution
2 y2
y' , x0 4, x1 4.1, x2 4.2, x3 4.3, x4 4.4, h 0.1
5x
2 y12 2 1.00492
y '
0.048301267
54.1
1
5x1
2 y12 2 1.00972
y2' 0.046690757
5x2 54.2
2 y32 2 1.01432
y
'
0.045171884
54.3
3
5x2
y 4 y0
4h
3
2 y1' y2' 2 y3'
40.1
1 20.048301267 0.046690757 20045171884
3
= 1.018700739
2 y42 2 1.0187007392
y4' 0.043738581
5x4 54.4
y4 y2
3
h '
y2 4 y3' y4'
97
1.0097
0.1
0.046690757 40.045171884 0.043738581
3
= 1.018737229
Example 3. Determine the value of y (0.4) using Milne’s method given y ' xy y , y 0 1;
2
use Taylor series to get the values of y (0.1), y (0.2), and y (0.3)
Solution
y' ' ' xy' '2 y'2 yy' '2( y' )2 y0''' 10
h 2 '' h3 '''
y1 y0 hy0' y0 y0 ...
2 3!
Now y1 x1 y1 y1 1.358611111
' 2
y1''' x1 y1'' 2 y1 2 y1 y11' 2 y1'
2
16.4113088
y 2 1.11666667 0.11.358611111
0.01 4.28675926 0.00116.4113088 ...
2 6
= 1.276696793
98
y2''' x2 y2'' 2 y2' 2 y2 y2'' 2 y2'
2
28.68725078
= 1.502345674
y 4 y0
4h
3
2 y1' y2' 2 y3'
y2' 1.885294059
40.1
y4 1 21.358611111 1.885294059 22.70774626
3
= 1.832989424
y4 y2
3
h '
y2 4 y3' y4'
1.276696793
0.1
1.885294059 42.70774626 4.093046
3
1.83700763
Example 4. Given
dy 1
1 x 2 y 2 and
dx 2
y0 1, y0.1 1.06, y(0.2) 1.12, y(0.3) 1.21 ,
99
Solution
y'
1
2
1 x2 y2
y0'
1
1 x0 2 y02 1 1 01 1
2 2 2
y1'
1
2
2 1
2
2
1 x12 y12 1 0.12 1.06 0.567418
1 1
y 3 (1 x32 ) y 32 (1 0.3 2 )(1.21) 2 0.7979345
2 2
y 4 y0
4h
3
2 y1' y2' 2 y3'
40.1
1 20.367418 0.652288 20.7979345
3
= 1.277122267
y4 y2
h '
3
y2 4 y3' y4' y '
4
0.946003944
1.12
0.1
0.652288 4(0.7979345) 0.946003944
3
= 1.279667665
y4'
1
2
1 0.4 2 1.279667665 0.949778612
2
100
So y4 1.12
0.1
0.652288 40.7979345 0.949778612
3
= 1.279793487
y 4'
1
2
1 0.4 2 (1.279793487) 2 0.949965394
y4 1.12
0.1
0.652288 40.7979345 0.949965394
3
= 1.279799713
Continuing this process again and again, after some steps we get
y4 1.279800037
Solution
By Modified Euler
y2 y1 hf x1 , y1 hf x1 , y1
h 1
2 2
0.1 0.11 0.1 0.11 0.1 0.1855
1
2
101
By improved Euler method
h f x2 , y2 f x3 , y2 hf x2 , y2
1
y3 y2
2
0.1855
0.1
1 0.1855 1 0.1855 0.11 0.1855
2
= 0.2628775
y 4 y0
4h
3
2 y1' y2' 2 y3'
y0
4h
21 y1 1 y2 21 y3
3
40.1
0 21 0.1 1 0.1855 2(1 0.2628775
3
= 0.327966
y4 y2
3
h '
y2 4 y3' y4'
y2
h
3
1 y2 41 y3 y4'
0.1
0.1855 ((1 0.1855) 4(0.2628775) 0.672034
3
= 0.333334133
Exercise
dy
0.2 x 0.1 y, y (0) 2, y (0.05) 2.0103, y (0.1) 2.0211, y (0.15) 2.0323
dx
102
2. Find y (0.8) given y y x 2 , y (0) 1, y (0.2) 1.12186, y (0.4)1.46820, y (0.6) 1.7379 .
3. Using Runge-Kutta method of fourth order, find y at x 0.1, x 0.2, x 0.3 given
1
4. Solve y (1 x) y 2 , y (0) 1 by Taylor series method at x 0.2, x 0.4, x 0.6 and
2
dy
5. If 2e x y, y (0) 2, y (0.1) 2.010, y (0.2) 2.040, y (0.3) 2.090 , find y (0.4) and
dx
6. Estimate y (0.8) and y (1) using Milne’s method correct to three decimal places, given
7. Solve y x y 2 , y (0) 1 to obtain y (0.4) by Milne’s method. Obtain the data you
dy y 1
8. Using both predictor-corrector methods, estimate y (1.4) if y satisfies 2 , and
dx x x
1
9. Given y , y (0) 2, y (0.2) 2.0933, y (0.4) 2.1755, y (0.6) 2.2493 , find
x y
10. Compute y (0.6) by Milne’s method given y x y, y (0) 1 with h 0.2 . Obtain the
11. Given y 3e x 2 y, y (0) 0 , find y (0.1) by Euler method; y (0.2) by Taylor series
103
12. Find y (0.2) by Taylor series method; y (0.4) by modified Euler method; y (0.6) by
13. Given y 1 xy, y (0) 1 obtain y (0.1) by Picard’s method; y (0.2) by modified Euler
14. Given y 2 xy 2 , y (0) 10, obtain power series by Picard’s method; using Milne’s
BVPs can be solved numerically by using either the Shooting Method or the Finite-
Difference Method (FDM). Here we consider the numerical solution of PVP using FDM. The
y x0 a and y xn b (2)
yi 1 2 yi yi 1
yi'' 2
O h2 y iv x p x y x q x
h
(3)
Problems of the type in Eq. (3) and Eq. (4), which involve the fourth-order differential
equation, are much involved and will not be discussed here. There exist many methods for
104
solving second-order BVPs of the type in Eq. (1) and Eq. (2). Of these, the Finite-Difference
The FDM for the solution for a two-point BVP consists in replacing the derivatives occurring
in the differential equation (and the boundary conditions as well) by means of their finite-
difference approximations and then solving the resulting linear system of equations by a
standard procedure.
follows:
y x h y x h ''
y' x y x ...
h 2
Thus we have
y x h y x
y' x O h (6)
h
y x y x h
y' x O h (8)
h
105
Which is the backward difference approximation for y ' x .
A central difference approximation for y ' x can be obtained by subtracting Eq. (7) from
y x h y x h
y' x O h2 (9)
2h
It is clear that Eq. (9) is better approximation to y ' x than either Eq. (6) or Eq. (8). Again,
adding Eq. (5) and Eq. (7) we get an approximation for y '' x as
y x h 2 y x y x h
y '' x 2
O h2 (10)
h
derivatives.
To solve the BVP defined by Eq. (1) and Eq. (2), we divide the range x0 , xn into n equal
y xi yi y x0 ih , i 0,1, 2,..., n.
From Eq. (9) and Eq. (10), values of y ' x & y '' x at the point x xi can now be written as
yi 1 yi
yi' O h2
2h
yi 1 2 yi yi 1
and yi'' 2
O h2
h
106
In many applied problems; however, derivative boundary conditions may be prescribed, and
this requires a modification of the procedures described above. The following examples
y ii y 1 0, 0 x 1,
Use the FDM to determine the value of y(0.5). Its exact solution is given by
1 cos1
y x cos x sin x 1 ,
sin1
y 0.5 0.139493927 .
yi 1 2 yi yi 1
yi 1 0
h2
yi 1 2 h2 yi yi 1 h2 , i 1, 2,..., n 1 ,
1
Choosing h (i.e. n 2 ), the above system becomes
2
107
1 1
y0 2 y1 y2 .
4 4
y1 y 0.5 0.142857142 .
Comparing with exact solution given above shows that the error in the computed solution is
0.00336 .
1
On the other hand, if we choose h (i.e. n=4), we obtain the three equations:
4
31 1
y0 y1 y2
16 16
31 1
y1 y2 y3
16 16
31 1
y2 y3 y4
16 16
which 0.00082 . Since the ration of the error is about 4 , it follows that the order of
convergence is h 2 .
These results show that the accuracy obtained by the finite difference method depends upon the
width of the subinterval chosen and also on the order of approximations. As h is reduced, the
d2y
y 0, 0 x 2,
dx 2
108
The exact solution of this problem is y sinh x . The finite-difference approximation is given by
1
yi 1 2 yi yi 1 yi i
h2
We subdivide the subinterval 0, 2 the four equal parts so that h 0.5 . Let the values of y at the
Writing the difference equations at the three interval points (which are the unknowns), we obtain
4 y0 2 y1 y2 y1
4 y1 2 y2 y3 y2 ii
4 y2 2 y3 y3 y3
9 y1 4 y2 0
4 y1 9 y2 4 y3 0 iii
4 y2 9 y3 14.50744
Exercise
y '' y 0, y 0 0, y 1 1 ,
109
by finite-difference method. Compare the computed solution at y 0.5 with the exact
2. Project work. Shooting Method. This is a popular method for the solution of two-point
y '' x f x , y x0 0 and y x1 A ,
for the value y ' x0 . Let the solution corresponding to x x1 be Y0 . If Y1 is the value
obtained by another guess m1 for y ' x0 , then Y0 and Y1 and are related linearly. Thus,
Obviously, the process can be repeated till we obtain the value for y x1 is close to A .
y '' x y x , y 0 0, y 1 1
110