0% found this document useful (0 votes)
109 views

Solved Examples in Numerical Analysis: Solution of Equations in One Variable Example

1) The document provides examples of using numerical analysis methods like bisection method and Newton's method to find the roots of equations. 2) For each example, it shows the iterative process of finding better approximations for the root through calculations and updating the interval range. 3) Tables are included that list the interval ranges evaluated at each step and the resulting approximations that converge towards the root solution.

Uploaded by

yehya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views

Solved Examples in Numerical Analysis: Solution of Equations in One Variable Example

1) The document provides examples of using numerical analysis methods like bisection method and Newton's method to find the roots of equations. 2) For each example, it shows the iterative process of finding better approximations for the root through calculations and updating the interval range. 3) Tables are included that list the interval ranges evaluated at each step and the resulting approximations that converge towards the root solution.

Uploaded by

yehya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Solved Examples in Numerical Analysis

Solution of Equations in one Variable


Example (1):

Using Bisection Method to find the approximate value of the root of the equation
5x3 + x2 − 2= 0 .

Solution:

Let f ( x ) = 5 x 3 + x 2 − 2 thus we have


f (0) = - 2 , f (1) = 4  p  (0,1)
let the first approximate of the root is p1 =(0 + 1) / 2 = 0.5
f ( p1 ) = - 1.125  p  (0.5 ,1)
p2 = (0.5 + 1) / 2 = 0.75
f ( p2 ) = 0.67  p  (0.5 , 0.75)
p3 = (0.5 + 0.75) / 2 = 0.625
f ( p3 ) = - 0.38867  p  (0.625 , 0.75)
p4 = ( 0.625 + 0.75) / 2 = 0.6875
f ( p4 ) = 0.0974  p  (0.625 , 0.6875)
p5 = (0.625 + 0.6875) / 2 = 0.65625  p  0.65625
we can put the result in the following table

a b pn = 1 (bn − an ) f ( pn )
2

0 1 0.5 -1.125

0.5 1 0.75 0.671875

0.5 0.75 0.625 -0.388671875

0.625 0.75 0.6875 0.097412109

0.625 0.6875 0.65625 -0.156219482

0.65625 0.6875 0.671875 -0.032108307

0.671875 0.6875 0.6796875 0.031968594

Table (1)
The approximate root is 0.6796875

1
Example (2):

Find the root of the equation x 3 + 4 x 2 − 10 = 0 in the interval (1, 2) .

Solution:
f ( x ) = x 3 + 4 x 2 - 10
f (1) = - 5 , f ( 2) = 4  p (1, 2)
p1 =(1+ 2) / 2 = 1.5 ,
f ( p1 ) = f (1.5) = 2 .375  p (1,1.5)
p2 = (1+1.5) / 2 = 1.25 ,
f ( p2 ) = f (1.25) = -1.79687  p (1.25,1.5)

p3 = (1.25 +1.5) / 2 = 1.375 ,


f ( p3 ) = f (1.375) = 0 .16211  p (1.25,1.375)

Apply the method then we have


p8 = 1.36328125, p9 = 1.365234375
and f(p9 ) = 0.000072
then the approximate value of the root is 1.365234375

n a b pn f ( pn )

0 1 2 1.5 2.375

1 1 1.5 1.25 -1.796875

2 1.25 1.5 1.375 0.162109375

3 1.25 1.375 1.3125 -0.848388672

4 1.3125 1.375 1.34375 -0.350982666

5 1.34375 1.375 1.359375 -0.096408844

6 1.359375 1.375 1.3671875 0.032355785

7 1.359375 1.3671875 1.36328125 -0.032149971

8 1.36328125 1.3671875 1.365234375 7.20248E-05

Table (2)
The root is 1.365234375

2
Example (3):

Find the root of the equation x 3 − x 2 − 1 = 0 in the interval (0, 2) .

Solution:
The result shown in the following table
n a b pn f ( pn )

0 0 2 1 -1

1 1 2 1.5 0.125

2 1 1.5 1.25 -0.609375

3 1.25 1.5 1.375 -0.291015625

4 1.375 1.5 1.4375 -0.095947266

5 1.4375 1.5 1.46875 0.011199951

6 1.4375 1.46875 1.453125 -0.043193817

7 1.453125 1.46875 1.4609375 -0.016203403

8 1.4609375 1.46875 1.46484375 -0.002553523

9 1.46484375 1.46875 1.466796875 0.004310243

10 1.46484375 1.466796875 1.465820313 0.00087512

11 1.46484375 1.465820313 1.465332031 -0.000840011

Table (3)

The root is 1.465332031

Newton's method

Example (7):

Find the root of the equation x 4 − x = 10 .

Solution:

f (x) = x 4 − x − 10 = 0, f  (x) = 4 x 3 − 1
the iteration formula is

3
xn4 − xn − 10
xn + 1 = x n − , n = 0,1, 2, 3,....
3
4 xn − 1
or in the form
3 xn4 + 10
xn + 1 = , x0 = 2, n = 0, 1, 2, ...
4 xn − 1
3

3 x04 + 10 3(2)4 + 10
x1 = = = 1.870967742
4 x0 3 − 1 4(2)3 − 1
the algorithm is shown in the flowing table

n xn B= 4xn3-1 A= 3xn4+10 xn+1= A/B

0 2 31 58 1.870967742

1 1.870967742 25.14744218 46.76092694 1.855780702

2 1.855780702 24.56465605 45.58174652 1.855584561

3 1.855584561 24.55655098 45.56675608 1.855584529

4 1.855584529 24.55654965 45.56675361 1.855584529

Table (9)

The root is 1.855584529

Exercise (1)
(1) By bisection method find 3 25 .
Solution:
by using Newton iteration method we have
xn 3 − a 2 x n 3 + a
xn +1 = xn − = , n = 1,2,3,... let a = 25 and since the cubic root of
3 xn2 3 xn2
2 xn 3 + 25
25 in-between 2 and 3 starting by x0 = 2.5 xn +1 = , n = 1,2,3,...
3 xn2

4
n xn xn + 1 f ( x)

0 2.5 3.000000000 -9.375

1 3 2.925925926 2

2 2.925925926 2.924018982 0.048976274

3 2.924018982 2.924017738 3.19129E-05

4 2.924017738 2.924017738 1.35785E-11

5 2.924017738 2.924017738 0

3 25  2.924017738

(2) Find the root of the equation x 3 + 3 x − 10 = 0 by using


(a) Bisection method.
(b) Newton iteration method.
Solution:
x 3 + 3 x − 10 = 0
f ( x ) = x 3 + 3 x − 10
f (0) = −10, f (1) = −6, f (2) = 4
 r  (1,2)
(a) Bisection method.

i a b xi = ( a + b ) / 2 f ( xi )

1 1 2 1.5 -2.125

2 1.5 2 1.75 0.609375

3 1.5 1.75 1.625 -0.833984375

4 1.625 1.75 1.6875 -0.132080078

5 1.6875 1.75 1.71875 0.233612061

6 1.6875 1.71875 1.703125 0.049518585

5
7 1.6875 1.703125 1.6953125 -0.041591167

8 1.6953125 1.703125 1.69921875 0.003885925

9 1.6953125 1.69921875 1.697265625 -0.018872045

10 1.697265625 1.69921875 1.698242188 -0.007497919

11 1.698242188 1.69921875 1.698730469 -0.001807212

12 1.698730469 1.69921875 1.698974609 0.001039053

13 1.698730469 1.698974609 1.698852539 -0.000384156

Root  1.69888549 Error  0.000384156

(b) Newton’s method

x 3 + 3x − 10 = 0
f ( x ) = x 3 + 3x − 10
f ( x ) = 3 x 2 + 3

x n 3 + 3x n − 10 2x n 3 + 10
x n +1 = x n − =
3x n 2 + 3 3x n 2 + 3

i xi xi + 1 f ( xi + 1 )

0 1 2 4

1 2 1.733333333 0.407703704

2 1.733333333 1.699395733 0.005950068

3 1.699395733 1.698885604 1.32658E-06

4 1.698885604 1.69888549 6.39488E-14

5 1.69888549 1.69888549 0

R = 1.69888549
-------------------------------------------------------------------------------------------------------

6
Find the one root for the equation x 3 − 5 x 2 + 2 = 0 . Calculate the error at each
iteration.

Answer

Let f ( x ) = x 3 − 5 x 2 + 2
x -1 0 1 2 3 4 5

f(x) -4 2 -2 -10 -16 -14 2

Then we have a root in the interval ( −1,0) and one in (0,1) the third root in the
interval (4,5)
by using Newton method with initial value -1

n xn xn+1 f ( xn+1 )

0 -1 -0.692307692 -0.728265817

1 -0.692307692 -0.60520442 -0.053031623

2 -0.60520442 -0.597788304 -0.000374443

3 -0.597788304 -0.597735191 -1.91638E-08

4 -0.597735191 -0.597735188 0

The approximate value of the root=-0.597735188


by using Newton method with initial value 0.1

n xn xn+1 f ( xn+1 )

0 0.1 2.111340206 -10.87694476

1 2.111340206 0.706073727 -0.140694465

2 0.706073727 0.680792234 -0.001858059

3 0.680792234 0.680449259 -3.4795E-07

4 0.680449259 0.680449195 -1.24345E-14

5 0.680449195 0.680449195 0

7
The approximate value of the root is 0.680449195

by using newton method with initial value 4

n xn xn+1 f ( xn+1 )

0 4 5.75 26.796875

1 5.75 5.107196402 4.796052532

2 5.107196402 4.930730815 0.315920199

3 4.930730815 4.917360801 0.001748036

4 4.917360801 4.917285995 5.45711E-08

5 4.917285995 4.917285993 0

The approximate value of the root is 4.917285993


-------------------------------------------------------------------------------------------------------
Curve Fitting
Example (1):

Find the least squares line for the following data

(−1, 10), (0, 9), (1, 7), (2, 5), (3, 4), (4, 3), (5, 0), (6, − 1).

Solution:

Let the equation of the L.S.L in the form y = Ax + B tabulate the data as following

x y x2 xy

-1 10 1 -10

0 9 0 0

1 7 1 7

2 5 4 10

3 4 9 12

8
4 3 16 12

5 0 25 0

6 -1 36 -6

N N N N
 xk =20  yk =37  xk =92  xk yk = 25
2

k =1 k =1 k =1 k =1

92 A + 20 B = 25
Equations (2) ,(3) gives
20 A + 8B = 37
by solving these equations we get A = -1.6071429, B = 8.6428571

Therefore the L.S.L is y = -1.6071429 x + 8.6428571

Example (2):

Find the least squares line for the following data

(0.5, 0.31), (1.0, 0.82), (1.5, 1.29), (2.0, 1.85), (2.5, 2.51), (3, 3.02).

Solution:

Let the equation of the L.S.L in the form y = Ax + B tabulate the data as following

x y x2 xy

0.5 0.31 0.25 0.155

1 0.82 1 0.82

1.5 1.29 2.25 1.935

2 1.85 4 3.7

2.5 2.51 6.25 6.275

3 3.02 9 9.06

N N N N
 xk = 10.5  yk = =9.8  xk = =22.75  xk yk = 21.945
2
k =1 k =1 k =1 k =1

9
Equations (2) ,(3) gives

22.75 A + 10.5B = 21.945


10.5 A + 6 B = 9.8
by solving these equations we get A = 1.096, B = −0.285

Therefore the L.S.L is y = 1.096 x − 0.285

Transformation for data (Linearization)

Example (3) :

Fit the curve y = a x b to the following readings :

x 1 2 4 6 10
y 2.6 5.6 13.3 21.2 40.1

Solutions:

y = a xb
 log y = ln a + b log x put Y = log y , A = ln a X = log x
the linear form is Y = A + bX

The normal equations are


N N N
 Yk X k = A  X k + b  X k2 (6)
k =1 k =1 k =1
N N
 Yk = NA + b  X k (7)
k =1 k =1

Construct the table as follows


x y X=log x Y=log y XY X2
1 2.6 0 O. 41497 0 0
2 5.6 0.30103 0.74819 O. 22523 O.O9062
4 13.3 0.6O206 1.12385 0 . 67663 0.36248
6 21.2 0.77815 1.32634 1.03209 O. 60552
10 40.1 1 . 0000 1 .60314 1.6O314 1.0
N
 2.68124 5.21649 3.53709 2.05862
k =1

10
And substitute in the normal equations(6),(7)

3.53709 = 2.68124 A + 2.05862 b


5.21649 = 5 A + 2.68124 b

and solve the resulting system

A = 2.68124 b = 5.21649

A = 2.68124 b = 5.21649
hence log a = 2.68124 → a = 2.1959997

finally the curve in the form y = 2.1959997 x5.21649

Example (4):

Fit the curve y = a e bx to the following readings:

x 1 2 3 4 5 6 7 8

y 15.3 20.5 27.4 36.6 49.1 65.6 87.8 117.6

Solutions:

y = a e bx
 log y = log a + b log e x
The linear equationsis
Y = A + Bx where Y = log y , A = log a , B = b log e
the normal equations are

N N
 Yk = NA + B  xk (17)
k =1 k =1
N N N
 xk Yk = A  xk + B  xk2 (18)
k =1 k =1 k =1

11
Tabulate the data as in the following table

x y Y=log y xY x2

1 15.3 1.184691431 1.184691431 1

2 20.5 1.311753861 2.623507722 4

3 27.4 1.437750563 4.313251688 9

4 36.6 1.563481085 6.253924342 16

5 49.1 1.691081492 8.455407461 25

6 65.6 1.816903839 10.90142304 36

7 87.8 1.943494516 13.60446161 49

8 117.6 2.070407322 16.56325857 64

36 419.9 13.01956411 63.89992587 204

from (16)

1 N N 
A=   Yk − B  xk  (18)
N  k =1 k =1 
substitute in (17)
N N N
N  xk Yk −  Yk  xk
k =1 k =1 k =1
B = 2
= 0.126473509
N   N
N  xk2 −   xk 
k =1  k =1 
using (18) we get A=1.058314724
 a = 10 A= 11.43706854
B 0.126473509
b= = = 0.291216016
log e 0.434294482

the fitting curve is y = 11.43706854 e0.291216016 x

12
Exercises
(1) Use least square method to fit the curve y = ax + b to the following data:
x = 3 at y .Hence find (0, 3.2),(2, 4.1),(4, 4.2),(6, 5.4)

xi yi xi2 x i yi

0 3.2 0 0

2 4.1 4 8.2

4 4.2 16 16.8

6 5.4 36 32.4

4 4 4 4
 xi =12  yi =16.9  xi2 = 56  xi yi =57.4
i =1 i =1 i =1 i =1

4 4 4
a  x i 2 + b  x i =  yi x i
i =1 i =1 i =1
4 4
a  xi + 4b =  yi
i =1 i =1

4  4  4 
4  y i X i −   X i   y i 
a = i =1  i =1  i =1  = 4(57.4) − (12)(16.9) = −0.009203297
4  4 
2
4(56) − (12)2
4  X i −  Xi 
2
i =1  i =1 

1 4 4 
and b=   y i − a  Xi  = 1
4 ( 16.9 − 4(12) ) = 4.25260989
n  i =1 i =1 

Then the required curve is y = −0.009203297 x + 4.25260989

------------------------------------------------------------------------------------------------------

(2) Fit the curve y = a x 3 + b to the data (7.9, 0.2),(11.9, 0.4),(16.4, 0.8),( 22.6,1.6)
Answer:

Let the line in the form y = aX + b where X i = xi 3


13
xi yi X i = xi 3 Xi2 xi yi

7.9 0.2 493.039 243087.4555 98.6078

11.9 0.4 1685.159 2839760.855 674.0636

16.4 0.8 4410.944 19456426.97 3528.755

22.6 1.6 11543.18 133244912.2 18469.08


4 4 4
 xi = 58.8
4 4
 yi = 3  X i = 18132.322  X 2i = 155784187.44891  yi xi = 22770.5082
i =1 i =1 i =1 i =1 i =1

4 4 4
a  X i 2 + b  X i =  yi X i
i =1 i =1 i =1
4 4
a  X i + 4b =  yi
i =1 i =1

We can use the solution of these equation as following


4  4  4 
4  y i X i −   X i   y i 
a = i =1  i =1  i =1  = 4(22770.5082) − ( 58.8 )( 3 ) = 1.246284  10−04
4(155784187.44891) − ( 58.8 )
2 2
4  4 
4  X 2i −   X i 
i =1  i =1 

1 4 4 
and b=   yi −a  Xi  = 1
4
( 3 − 4(58.8) ) = 0.185049752037084
n  i =1 i =1 

Then the required curve is y = ( 1.246284E - 04 ) x 3 + 0.185049752037084

------------------------------------------------------------------------------------------------------

1
(3) Fit the curve y = to the data (1, 0.5),( 2, 0.4),( 4, 0.3),(6, 0.2),(8, 0.1) .
ax +b
2

Answer:

We put the equation curve in the form


1 1
= ax 2 + b and hence Y = aX + b where Y = , X = x 2
y y

14
x y X Y X2 XY
1 0.5 1 2 1 2

2 0.4 4 2.5 16 10

4 0.3 16 3.3333333 256 53.3333333

6 0.2 36 5 1296 180

8 0.1 64 10 4096 640

 121 22.833333 5665 885.333333

5  5  5  5  5  5 
5  Y i X i −   X i   Y i  5  Y i X i −   X i   Y i 
a = i =1  i =1  i =1  = i =1  i =1  i =1  = 0.12158969
2 2
5  5  5  5 
5  X 2i −   X i  5  X 2i −   X i 
i =1  i =1  i =1  i =1 
1 5 5  1 5 5 
and b =   Y i − a  X i  =   Y i − a  X i  = 1.62419614
5  i =1 i =1  5  i =1 i =1 
1
Then the best curve is y =
0.12158969x 2 + 1.62419614
------------------------------------------------------------------------------------------------------

(4) Fit the curve y = a exp( − b x 2 ) to the data


(1, 9.01),(2, 6.01),(3, 6.07),(4, 2.02),(5, 0.22),(8, 0.02) .

Answer:

y = a exp( − b x 2 )

log y = − bx 2 log e + log a


Y = AX + B

where

15
Y = log y
A = − b log e

X = x2
B = log a

xi yi Xi Yi X i2 X iYi

1 9.01 1 0.954724791 1 0.954724791

2 6.01 4 0.778874472 16 3.115497888

3 6.07 9 0.783188691 81 7.048698220

4 2.02 16 0.305351369 256 4.885621911

5 0.22 25 -0.657577319 625 -16.439432979

8 0.02 64 -1.698970004 4096 -108.734080278


6 6 6 6
 X i = 119  Yi = 0.465592  X i = 5075
2
 X iYi = 109.1689704
i =1 i =1 i =1 i =1

6  6  6  6  6  6 
6  Y i X i −   X i   Y i  6  Y i X i −   X i   Y i 
A = i =1  i =1  i =1  = i =1  i =1  i =1  = −0.04361343671690
2 2
6  6  6  6 
6  X 2i −   X i  6  X 2i −   Xi 
i =1  i =1  i =1  i =1 

1 6 6  1 6 6 
and B =   Y i − a  X i  =   Y i − a  X i  = 0.942598495
6  i =1 i =1  6  i =1 i =1 
A
b= = 0.100423649
− log e

a = 10 B = 1.260154078

y = 1.260154078 exp( −0.100423649 x 2 )

----------------------------------------------------------------------------------------------------------------
16
   
(5) Fit the curve y = a sin 2 x + b to the data (0,4.2),( ,5.8),( ,8.3),( ,9.9),( ,12.5)
6 4 3 2

Answer:

y = a sin 2 x + b
y = aX + b

where X = sin 2 x

xi Xi yi X i2 X i yi

0 0 4.2 0 0

0.523598776 0.25 5.8 0.0625 1.45

0.785398163 0.5 8.3 0.25 4.15

1.047197551 0.75 9.9 0.5625 7.425

1.570796327 1 12.5 1 12.5


5 5 5 5
 X i = 2.5  yi = 40.7  X i = 1.875
2
 X i yi = 25.525
i =1 i =1 i =1 i =1

5  5  5  5  5  5 
5  y i X i −   X i   y i  5  y i X i −   X i   y i 
A = i =1  i =1  i =1  = i =1  i =1  i =1  = 8.28
2 2
5  5  5  5 
5  X 2i −   X i  5  X 2i −   Xi 
i =1  i =1  i =1  i =1 
1 5 5  1 5 5 
and B =   y i − a  X i  =   y i − a  X i  = 4
5  i =1 i =1  5  i =1 i =1 

y = 8.28sin 2 x + 4

------------------------------------------------------------------------------------------------------

(6) Fit the curve y = a cos 2 x + b to the data

(0,11.2),(  ,10.4),(  ,9.7),(  ,9.2),( ,10.9)


6 4 3

Answer:
17
y = a cos 2 x + b
y = aX + b

where X = cos 2 x

xi Xi yi X i2 X i yi

0 1 11.2 1 11.2

0.523599 0.75 10.4 0.563 7.8

0.785398 0.5 9.7 0.25 4.85

1.047198 0.25 9.2 0.063 2.3

3.141593 1 10.9 1 10.9


5 5 5 5
 X i = 3.5  yi = 51.4  X i2 = 2.875  X i yi = 37.05
i =1 i =1 i =1 i =1

5  5  5  5  5  5 
5  y i X i −   X i   y i  5  y i X i −   X i   y i 
A = i =1  i =1  i =1  = i =1  i =1  i =1  = 2.51765
2 2
5  5  5  5 
5  X 2i −   X i  5  X 2i −   Xi 
i =1  i =1  i =1  i =1 

1 5 5  1 5 5 
and B =   y i − a  X i  =   y i − a  X i  = 8.51765
5  i =1 i =1  5  i =1 i =1 

y = 2.51765 sin 2 x + 8.51765

----------------------------------------------------------------------------------------------------------------

(7) Fit the curve y = a x 3 + b to the data


(1,10.9),(1.2,12.9),(1.4,15.2),(1.6,18.8),(1.8, 23)

18
Answer:

Let the line in the form y = aX + b where X i = xi 3

xi X i = xi 3 yi Xi2 xi yi

1 1 10.9 1 10.9

1.2 1.728 12.9 2.985984 22.2912

1.4 2.744 15.2 7.529536 41.7088

1.6 4.096 18.8 16.777216 77.0048

1.8 5.832 23 34.012224 134.136


4 4 4 4
 X i = 15.4  yi = 80.8  X i = 62.30496
2  yi xi = 286.0408
i =1 i =1 i =1 i =1

5 5 5
a  X i 2 + b  X i =  yi X i
i =1 i =1 i =1
5 5
a  X i + 5b =  yi
i =1 i =1

We can use the solution of these equation as following


5  5  5  5  5  5 
5  y i X i −   X i   y i  5  y i X i −   X i   y i 
a = i =1  i =1  i =1  = i =1  i =1  i =1  = 2.499623478
2 2
5  5  5  5 
5  X 2i −   X i  5  X 2i −   X i 
i =1  i =1  i =1  i =1 
1 5 5  1 5 5 
and b =   y i − a  X i  =   y i − a  X i  = 8.461159688
n  i =1 i =1  n  i =1 i =1 

then the required curve is

y = 2.499623478 x 3 + 8.461159688

----------------------------------------------------------------------------------------------------------------

19
Numerical Differentiation
f ( x + h) − f ( x − h)
f ( x ) =
2h
f ( x + h) − 2 f ( x ) + f ( x − h)
f ( x ) =
h2
1
 f ( x) =  f ( x − 2 h ) − 8 f ( x − h ) + 8 f ( x + h) − f ( x + 2 h) 
12h
1
 f ( x) =  − f ( x + 2h) + 16 f ( x + h) − 30 f ( x) + 16 f ( x − h) − f ( x − 2h) 
12h 2
−3 f ( x0 ) + 4 f ( x0 + h) − f ( x0 + 2h)
f ( x0 ) =
2h
3 f ( x0 ) − 4 f ( x0 − h) + f ( x0 − 2h)
f ( x0 ) =
2h
2 f ( x ) − 5 f ( x + h) + 4 f ( x + 2h) − f ( x + 3h)
f ( x ) =
h2
Example (3):

By using the following data approximate

f (2.0), f (2.0), f (1.8), f (1.8), f (2.2), f (2.2)

x 1.8 1.9 2.0 2.1 2.2

y 10.889365 12.703199 14.778112 17.148957 19.855030

Solution:

To approximate f ( 2.0)

x = 2.0 , f (2.0) = 14.778112, h = 0.1 ,


x + h = 2.1, f(x + h) = 17.148957
x + 2h = 2.2 , f(x + 2h) = 19.855030
x - h = 1.9 , f(x - h) = 12.703199
x - 2h = 1.8 , f(x - 2h) = 10.889365

20
(i) By using three - point formula

− 3 f ( x ) + 4 f ( x + h) − f ( x + 2 h)
 f ( x ) =
2h
− 3 f (0.2) + 4 f ( 2.1) − f ( 2.2)
 f (0.2) =
2(0.1)
− 3(14.778112) + 4(17.148952) − (19.855030)
= = 22.032310
0.2

(ii) by using backward formula:

3 f ( x ) − 4 f ( x − h) + f ( x − 2 h )
f ( x ) =
2h

3 f (0.2) − 4 f (1.9) + f (1.8)


 f ( 2.0) =
2(0.1)
3(14.778112) − 4(12.703199) + (10.889365)
= = 22.054525
0.2

(iii) by using centered finite difference formula:

f ( x + h) − f ( x − h)
f ( x ) =
2h

f ( 2.1) − f (1.9) 17.148957 − 12.703199


 f ( 2.0) = = = 22.228790
2(0.1) 0.2

By using Five points formula:

f ( x − 2 h) − 8 f ( x − h) + 8 f ( x + h) − f ( x + 2 h)
f ( x ) =
12h
f (1.8) − 8 f (1.9) + 8 f ( 2.1) − f ( 2.2)
f ( 2.0) =
12(0.1)

(10 .889365 ) − 8(12 .703199 ) + 8(17 .148957 ) − (19 .855030 )


 f ( 2.0) = = 22 .16699916
12 ( 0.1)

21
Second derivative

f ( x + h) − 2 f ( x ) + f ( x − h)
 f ( x ) =
h2
f ( 2.1) − 2 f ( 2) + f (1.9)
 f (0.2) =
h2
(17.148957) − 2(14.778112) + (12.7037119)
= = 29.5932
0.01

at x = 1.8 consider:

x + h = 1.9, x + 2h = 2.0

− 3 f ( x ) + 4 f ( x + h) − f ( x + 2 h)
 f ( x ) =
2h
− 3 f (1.8) + 4 f (1.9) − f ( 2.0)
f (1.8) =
2(0.1)
= (5)[ −3(10.889365) + 4(12.703199) − (14.778112)]
= (5)(− 32.668095 + 50.812796 − 14.778112) = (5)(3.366589)
= 16.832945 ,

2 f ( x ) − 5 f ( x + h) + 4 f ( x + 2h) − f ( x + 3h)
 f ( x ) =
h2
2 f (1.8) − 5 f (1.9) + 4 f ( 2.0) − f ( 2.1)
 f (1.8) =
(0.1) 2
2(10.889365) − 5(12.703199) + 4(14.778112) − (17.148957 )
=
(0.1) 2
= (100)(0.226226 ) = 22.6226

At x =2.2 we have x − h = 2.1, x − 2h = 2 , x − 3h = 1.9

since

3 f ( x ) − 4 f ( x − h ) + f ( x − 2 h)
f ( x ) =
2h

3 f ( 2.2) − 4 f ( 2.1) + f ( 2.0)


Thus:  f ( 2.2) =
2h

22
3(19.855030) − 4(17.148957) + (14.778112) 5.747374
= = = 28.73687
2(0.1) 0.2

2 f ( x) − 5 f ( x − h) + 4 f ( x − 2h) − f ( x − 3h)
f ( x) =
h2
2 f (2.2) − 5 f (2.1) + 4 f (2.0) − f (1.9)
f (2.2) =
(0.1)2
1
 f (2.2) = [2(19.855030) − 5(17.148957) + 4(14.778112) − (12.703199)]
0.01
0.374524
= = 37.4524
0.01

(3) From the following table evaluate y, y at x = 0.55

x 0.35 0.40 0.45 0.50 0.55 0.60 0.65

y 1.521525 1.505942 1.487968 1.467462 1.4444243 1.418083 1.388686

Solution:

To approximate y(0.5) we have

x = 0.55 f ( x ) = f (0.55) = 1.4444243,


x + h = 0.60 f ( x + h ) = f (0.60) = 1.418083,
x − h = 0.5 f ( x − h ) = f (0.5) = 1.467462,
x + 2h = 0.65 f ( x + 2h ) = f (0.65) = 1.388686,
x − 2h = 0.45 f ( x − 2h ) = f (0.45) = 1.487968

(i) By using three - point formula

− 3 f ( x ) + 4 f ( x + h) − f ( x + 2 h)
y ( x ) =
2h
−3 f (0.55) + 4 f (0.60) − f (0.65)
 y(0.55) =
2(0.05)
−3(1.4444243) + 4(1.418083) − (1.388686)
= = -0.496269
0.2

(ii) By using backward formula:

23
3 f ( x ) − 4 f ( x − h) + f ( x − 2h)
y( x ) =
2h

3f (0.55) − 4f (0.50) + f (0.45)


 y (0.55) =
2(0.05)
3(1.4444243) − 4(1.467462) + (1.487968)
= = -0.486071
2(0.05)

(iii) By using centered finite difference formula:

f ( x + h) − f ( x − h)
y( x ) =
2h

f (0.60) − f (0.50) 1.418083 − 1.467462


 y(0.55) = = = -0.58379
2(0.05) 0.1

By using five points formula:

f ( x − 2 h) − 8 f ( x − h) + 8 f ( x + h) − f ( x + 2 h)
y ( x ) =
12h
f (0.45) − 8 f (0.50) + 8 f (0.60) − f (0.65)
y(0.55) =
12(0.05)
1.487968 − 8(1.467462) + 8(1.418083) − 1.388686
= = -0.492916667
12(0.05)

Second derivative by using Three points formula:

f ( x + h ) − 2f ( x ) + f ( x − h )
y ( x ) =
h2
f (0.60) − 2f (0.55) + f (0.50)
 y (0.55) =
h2
(1.418083) − 2(1.4444243) + (1.467462)
= = -1.32144
(0.05)2

24
By using five points formula:

1
y ( x ) =  −f (x + 2h ) + 16f (x + h ) − 30f (x ) + 16f (x − h ) − f (x − 2h )
12h 2
1
y (55) =  −f (0.65) + 16f (0.60) − 30f (0.55) + 16f (0.50) − f (0.45)
12(0.05)2
1
=  −(1.388686) + 16(1.418083) − 30(1.4444243) + 16(1.467462) − 1.487968
12(0.05)2
= -1.355433333

-------------------------------------------------------------------------------------------------------
(4 a) From the following table evaluate y, y at x = 0.50

x 0.35 0.40 0.45 0.50 0.55 0.60 0.65

y 1.521525 1.505942 1.487968 1.467462 1.4444243 1.418083 1.388686

Solution:

To approximate y(0.5) we have

x = 0.5, f ( x ) = f (0.5) = 1.467462, h = 0.05,


x + h = 0.55, f ( x + h) = f (0.55) = 1.4444243
x + 2h = 0.60, f ( x + 2h) = f (0.60) = 1.418083
x − h = 0.45 , f ( x − h) = f (0.45) = 1.487968
x − 2h = 0.40 , f ( x − 2h) = f (0.40) = 1.505942

(i) By using three - point formula

− 3 f ( x ) + 4 f ( x + h) − f ( x + 2 h)
y ( x ) =
2h
−3 f (0.5) + 4 f (0.55) − f (0.60)
 y(0.5) =
2(0.05)
−3(1.467462) + 4(1.4444243) − (1.418083)
= = -0.427718
0.2

(ii) By using backward formula:

3 f ( x ) − 4 f ( x − h) + f ( x − 2h)
y( x ) =
2h

25
3 f (0.5) − 4 f (0.45) + f (0.40)
 y(0.5) =
2(0.05)
3(1.467462) − 4(1.487968) + (1.505942)
= = -0.43544
2(0.05)

(iii) By using centered finite difference formula:

f ( x + h) − f ( x − h)
y( x ) =
2h

f (0.55) − f (0.45) 1.4444243 − 1.487968


 y(0.5) = = = -0.435437
2(0.05) 0.1

By using five points formula:

f ( x − 2h) − 8 f ( x − h) + 8 f ( x + h) − f ( x + 2h)
y ( x ) =
12h
f (0.40) − 8 f (0.45) + 8 f (0.55) − f (0.60)
y(0.50) =
12(0.05)
1.505942 − 8(1.487968) + 8(1.4444243) − 1.418083
= = -0.434141
12(0.05)

Second derivative

By using three points formula:

f ( x + h ) − 2 f ( x ) + f ( x − h)
y( x ) =
h2
f (0.55) − 2 f (0.50) + f (0.45)
 y(0.50) =
h2
(1.4444243) − 2(1.467462) + (1.487968)
= = -1.01268
2
(0.05)

26
By using five points formula:

1
f ( x ) =  − f ( x + 2h) + 16 f ( x + h) − 30 f ( x ) + 16 f ( x − h) − f ( x − 2h)
12h2
1
f ( x ) =  − f (0.6) + 16 f (0.55) − 30 f (0.50) + 16 f (0.45) − f (0.40)
12(0.05)2
1  −(1.418083) + 16(1.4444243) 
=  
12(0.05)2  −30(1.467462) + 16(1.487968) − 1.505942 
= -0.98694

-------------------------------------------------------------------------------------------------------
(1) From the following table evaluate y, y at x = 1 , 1.2 and at 1.4
x 1 1.2 1.4 1.6 1.8

y 2 1.113938 1.730126719 1.198306241 1.593882

Solution:

To approximate y(0.5) we have

x = 0.55 f ( x ) = f (0.55) = 1.4444243,


x + h = 0.60 f ( x + h ) = f (0.60) = 1.418083,
x − h = 0.5 f ( x − h ) = f (0.5) = 1.467462,
x + 2h = 0.65 f ( x + 2h ) = f (0.65) = 1.388686,
x − 2h = 0.45 f ( x − 2h ) = f (0.45) = 1.487968

(i) By using three - point formula

− 3 f ( x ) + 4 f ( x + h) − f ( x + 2 h)
y ( x ) =
2h
−3 f (0.55) + 4 f (0.60) − f (0.65)
 y(0.55) =
2(0.05)
−3(1.4444243) + 4(1.418083) − (1.388686)
= = -0.496269
0.2

(ii) By using backward formula:

3 f ( x ) − 4 f ( x − h) + f ( x − 2h)
y( x ) =
2h

27
3f (0.55) − 4f (0.50) + f (0.45) 3(1.4444243) − 4(1.467462) + (1.487968)
 y (0.55) = =
2(0.05) 2(0.05)
= -0.486071

(iii) By using centered finite difference formula:

f ( x + h) − f ( x − h)
y( x ) =
2h

f (0.60) − f (0.50) 1.418083 − 1.467462


 y(0.55) = = = -0.58379
2(0.05) 0.1

By using five points formula:

f ( x − 2 h) − 8 f ( x − h) + 8 f ( x + h) − f ( x + 2 h)
y ( x ) =
12h
f (0.45) − 8 f (0.50) + 8 f (0.60) − f (0.65)
y(0.55) =
12(0.05)
1.487968 − 8(1.467462) + 8(1.418083) − 1.388686
= = -0.492916667
12(0.05)

Second derivative by using Three points formula:

f ( x + h ) − 2f ( x ) + f ( x − h )
y ( x ) =
h2
f (0.60) − 2f (0.55) + f (0.50)
 y (0.55) =
h2
(1.418083) − 2(1.4444243) + (1.467462)
= = -1.32144
(0.05)2

By using five points formula:

1
y ( x ) =  −f (x + 2h ) + 16f (x + h ) − 30f (x ) + 16f (x − h ) − f (x − 2h )
12h 2
1
y (55) =  −f (0.65) + 16f (0.60) − 30f (0.55) + 16f (0.50) − f (0.45)
12(0.05)2
1
=  −(1.388686) + 16(1.418083) − 30(1.4444243) + 16(1.467462) − 1.487968
12(0.05)2
= -1.355433333
28
-------------------------------------------------------------------------------------------------------
(6) Use the following table to compute f (1.3) in the case h = 0.1, h = 0.01

x 1.2 1.29 1.3 1.31 1.4

y 11.59006 13.78176 14.04276 14.30741 16.86187

When h = 0.1
f (x ) = f (1.3) = 14.04276
f ( x − h ) = f (1.2) = 11.59006
f ( x + h ) = f (1.4) = 16.86187
f ( x + h ) − 2f ( x ) + f ( x − h )
We use f ''( x ) =
h2
h = 0.1, h = 0.01
f (x ) = f (1.3) = 14.04276
f ( x − h ) = f (1.29) = 13.78176
f ( x + h ) = f (1.31) = 14.30741
f ( x + h ) − 2f ( x ) + f ( x − h )
We use f ''( x ) =
h2

-------------------------------------------------------------------------------------------------------
Numerical Integration

Trapezoidal Rule of Integration

h
I =  f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + ... + 2 f ( xn−1 ) + f ( xn ) 
2

Example (1):

1 1
consider the integral  dx with h=0.1 and then n=10 and by using trapezoidal
0 1 + x

rule the results are tabulate at the following table

The formula for the Trapezoidal rule is

29
h
I =  f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + ... + 2 f ( xn−1 ) + f ( xn ) 
2
substitute about the values of f (xk ) from the table we get

k xk f ( xk )

0 0 1.00000000 1.00000000

1 0.1 0.90909091 1.81818182

2 0.2 0.83333333 1.66666666

3 0.3 0.76923077 1.53846154

4 0.4 0.71428571 1.428571429

5 0.5 0.66666667 1.333333333

6 0.6 0.62500000 1.250000000

7 0.7 0.58823529 1.176470588

8 0.8 0.55555556 1.111111111

9 0.9 0.52631579 1.05263157

10 1.0 0.50000000 0.50000000

Table (1)

IT = 0.693771403 We know that the exact solution is ln2 = 0.6931471805599


Example (2):

2 sin x
Evaluate  dx take h = 0.5, 0.2, 0.1
0 x

Solution:

Considering h=0.5

30
x f(x) 2 f ( x)

1 1 1

0.5 0.958851077 1.917702154

1.0 0.481470984 1.68294197

1.5 0.664996657 1.329993315

2 0.454648713 0.454648713

Table (2)
h
IT =  f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + ... + 2 f ( xn −1 ) + f ( xn ) 
2
0.2
= [1+1.917702154+1.68294197+1.329993315+0.454648713]=1.596321538
2
at h=0.2
h
I =  f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + ... + 2 f ( xn −1 ) + f ( xn ) 
2
0.2
= [1 + 1.986693308 + 1.947091712 + 1.882141578 + 1.793390227
2
+ 1.68294197 + 1.553398477 + 1.407785329 + 1.249467004
+ 1.082052923 + 0.454648713] = 1.603961124
x f(x) 2f(x)

0 1 1
0.2 0.993346654 1.986693308
0.4 0.97354855 1.947091712
0.6 0.941070789 1.882141578
0.8 0.896695113 1.793390227
1.0 0.841470984 1.68294197
1.2 0.776699238 1.553398477
1.4 0.703892664 1.407785329
1.6 0.624733501 1.249467004
1.8 0.541026461 1.082052923
2 0.454648713 0.454648713

31
At h = 0.1

h
IT = f (x ) + 2 f (x1 ) + f (x 2 ) + ... + f (xn −1 ) + f (xn ) 
2 0
0.2
= [1 + 1.996668333 + 1.986693308 + 1.970134711 + 1.94091712
2
+ 1.917702154 + 1.882141578 + 1.840621964 + 1.793390227
+ 1.740726466 + 1.68294197 + 1.620377018 + 1.553398477
+ 1.482397208 + 1.407785329 + 1.329993315 + 1.249467004
+ 1.166664483 + 1.082052923 + 0.996105355 + 0.454648713]
= 1.604741308

IT = 1.604741308

x f ( x) 2 f ( x)

0 1 1
0 .1 0.998834166 1.996668333
0 .2 0.993346654 1.986693308
0 .3 0.985067335 1.970134711
0 .4 0.973545855 1.94091712
0 .5 0.958851077 1.917702154
0 .6 0.941070789 1.882141578
0 .7 0.920310981 1.840621964
0 .8 0.896695113 1.793390227
0 .9 0.870363232 1.740726466
1 .0 0.841470984 1.68294197
1 .1 0.810188509 1.620377018
1 .2 0.776699238 1.553398477
1 .3 0.741198604 1.482397208
1 .4 0.703892664 1.407785329
1 .5 0.664996657 1.329993315
1 .6 0.6244733501 1.249467004
1 .7 0.583332241 1.166664483
1 .8 0.514026461 1.082052923
1 .9 0.498052677 0.996105355
2 0.454648713 0.454648713

32
Simpson’s 1/3 Rule of Integration Method

In general, Simpson’s 1/3 rule may be expressed for n base points as

h
I S = [ f ( x0 ) + 4 f ( x1 ) + 2 f ( x2 ) + 4 f ( x3 ) + 2 f ( x4 ) + 4 f ( x5 ) + 2 f ( x6 )
3
+ ... + 2 f ( xn− 2 ) + 4 f ( xn−1 ) + f ( xn )]

1 dx
Example (3): Evaluate  using Simpson’s rule (h=0.1)
2
01+ x

Solution:

1
a = 0, b = 1, f ( x) = , xk = x0 + kh = 0 + k (0.1) = 0.1 k
2
1+ x

0.1
Is = 1 + 4(0.9901 + 0.9174 + 0.8 + 06711 + 0.5525)
3
+2(0.9615 + 0.8621 + 0.7353 + 0.6098) + 0.5 = 0.7853933
IT = 0.784981495

Is = 0.7853933, IT = 0.784981495, IExact = 0.78539816

k xk f (xk ) 2f (xk )or4f (xk )

0 0 1 1
1 0.1 0.9901 3.9604
2 0.2 0.9615 1.923
3 0.3 0.9174 3.6696
4 0.4 0.8621 1.7242
5 0.5 0.8 3 .2
6 0.6 0.7353 1.4706
7 0.7 0.6711 2.6844
8 0.8 0.6098 1.2196
9 0.9 0.5525 2.21
10 1.0 0.5 0.5

33
Example (4):

1
dx
Evaluate 1+ x2
using Simpson’s rule(h=0.1)
0

Solution:

a = 0, b = 1.2, f ( x) = x4 + 5 x − 1
xk = x0 + kh

 xk = 0 + k (0.2) = 0.2 k , k = 0,1,2,..., n

k xk f (xk ) 2f (x k ) 2f ( x k ) 2f ( x k )
or 4f ( x k ) or 3f ( x k )

0 0 1 -1 -1 -1

1 0.2 0.0016 0.0032 0.0064 0.0048

2 0.4 1.0256 2.0512 2.0512 3.0768

3 0.6 2.1296 4.2592 8.5184 4.2592

4 0.8 3.4096 6.8192 6.8192 10.2288

5 1.0 5.00 10 20 15

6 1.2 7.0736 7.0736 7.0736 7.0736

IT = 2.92064

I s = 2.89792

I Exact = 2.89766

34
i xi f ( xi ) 2 f ( xi )
1e x
−1
(1)  dx 0 0 0 0
0 x
1 0.1 0.332579645 0.665159289

2 0.2 0.495071618 0.990143235

3 0.3 0.63875187 1.277503739

4 0.4 0.777643127 1.555286254

5 0.5 0.917430419 1.834860838

6 0.6 1.061350808 2.122701615

7 0.7 1.211666239 2.423332478

8 0.8 1.370196413 2.740392825

9 0.9 1.53855677 3.077113541

10 1 1.718281828 1.718281828

I= 0.920238782

i xi f ( xi ) 2 f ( xi ) 4 f ( xi )

0 0 0 0

1 0.1 0.332579645 1.330318579

2 0.2 0.495071618 0.990143235

3 0.3 0.63875187 2.555007478

4 0.4 0.777643127 1.555286254

5 0.5 0.917430419 3.669721677

6 0.6 1.061350808 2.122701615

7 0.7 1.211666239 4.846664955

8 0.8 1.370196413 2.740392825

9 0.9 1.53855677 6.154227081

10 1 1.718281828 1.718281828

9.126805758 18.55593977

I= 0.922758184

35
i xi f ( xi ) 2 f ( xi )
1
(2)  tan x 0 0 0 0
0

1 0.1 0.316756487 0.633512974

2 0.2 0.450233312 0.900466625

3 0.3 0.556180051 1.112360103

4 0.4 0.650225514 1.300451028

5 0.5 0.739122784 1.478245568

6 0.6 0.82712563 1.654251261

7 0.7 0.917762704 1.835525408

8 0.8 1.014711071 2.029422141

9 0.9 1.12256769 2.245135379

10 1 1.247961428 1.247961428

I=0.721866596

i xi f ( xi ) 2 f ( xi ) 4 f ( xi )

0 0 0 0

1 0.1 0.3167565 1.2670259

2 0.2 0.4502333 0.900466625

3 0.3 0.5561801 2.2247202

4 0.4 0.6502255 1.300451028

5 0.5 0.7391228 2.9564911

6 0.6 0.8271256 1.654251261

7 0.7 0.9177627 3.6710508

8 0.8 1.0147111 2.029422141

9 0.9 1.1225677 4.4902708

10 1 1.2479614 1.247961428

36
7.132552482 14.609559

I= 0.724737045

1
 1+ x
2
(3) dx
0

Solution:

i xi f ( xi ) 2 f ( xi )

0 0 1 1

1 0.1 1.004987562 2.009975124

2 0.2 1.019803903 2.039607805

3 0.3 1.044030651 2.088061302

4 0.4 1.077032961 2.154065923

5 0.5 1.118033989 2.236067977

6 0.6 1.166190379 2.332380758

7 0.7 1.220655562 2.441311123

8 0.8 1.280624847 2.561249695

9 0.9 1.345362405 2.690724809

10 1 1.414213562 1.414213562

I= 1.148382904

37
i xi f ( xi ) 2 f ( xi ) 4 f ( xi )

0 0 1 1

1 0.1 1.0049876 4.0199502

2 0.2 1.0198039 2.039607805

3 0.3 1.0440307 4.1761226

4 0.4 1.077033 2.154065923

5 0.5 1.118034 4.472136

6 0.6 1.1661904 2.332380758

7 0.7 1.2206556 4.8826222

8 0.8 1.2806248 2.561249695

9 0.9 1.3453624 5.3814496

10 1 1.4142136 1.414213562

11.50151774 22.932281

I=1.147793281

38

You might also like