Vous êtes sur la page 1sur 31

Numerical Analysis 1

Chapter # 2
Solution of Algebraic and Transcendental Equations
Notes:
(1) Linear Equations: An equation in which the highest power of variable is “One”
is called linear equation. e.g.
 x+2=0
 2x + 10 = 0 etc
(2) Non-Linear Equation: Equation involving higher powers of a variable is called
Non-Linear Equation.e.g.
 x3 + 4x2 + 10x + 3 = 0

 x4 + 9x2 + 20 = 0

(3) Transcendental Equation: Equation involving functions of variable

(e.g. Trigonometric, Exponential and logarithmic functions etc) is called


Transcendental Equation.e.g.

 Sinx = 6x + 2

 ex – lnx = 20

 e-x – Sinx = 0

(4) There are two methods of solving Non-Linear and Transcendental Equations.

 Numerical Method.

 Analytical Method

Types of Numerical Method

(i) Newton Raphson Method (ii) Secant Method

(iii) False Position Method (iv) Bisection Method

(v) Iterative Process


Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 2

The process of finding Successive approximation to a quantity is called an iterative


process.

Type No # 1

Newton Raphson method

KEY

 .f(x) =  (Given)

d
 Find f ′(x) i.e. f ( x) and put x = xn in f(x) and f ′(x ) .
dx

 Interval or initial point x0 will be given if not, put x = 0, 1, 2, 3, 4, ………….in f(x).

 If f(x) changes its sign for any two close values of x, the interval will be that one
and the small value of the interval will be x0.

 Finally put n = 0, 1, 2, 3, 4, …………… in the formula:

f ( xn )
x n +1 = x n − to get x1, x2, x3,………………
f ′( x n )

 If the two values of x are approximately equal then we stop the iteration, and the
last value of x will be a positive root of f(x).

Q.21/Page # 47

Apply any numerical method to calculate the square root of 3 up to six decimal places.

Ans:

Square root of 3 = 3

Let x = 3

Squaring both sides

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 3

X2 = 3 ⇒ x2 – 3 = 0

Let f(x) = x2 – 3 ⇒ f(xn) = xn2 - 3

d d
f (x) = ( x2 – 3) ⇒ f ′(x ) = 2x ⇒ f ′( x n ) = 2 xn
dx dx

Using Newton Raphson Method

f ( xn )
x n +1 = x n −
f ′( x n )

2 2 2 2
xn − 3 2xn − xn + 3 xn + 3
x n +1 = x n − = = ----------> (1)
2 xn 2 xn 2xn

To find x0

As f(x) = x2 – 3

For x = 0, f(0) = 0 – 3 = -3 (-ve)

For x = 1, f(1) = 1 – 3 = -2 (-ve)

For x = 2, f(2) = 22 – 3 = 4 – 3 = 1 (+ve)

Since f(x) changes its sign at x = 1 and x = 2

⇒ The root lies in the interval (1, 2) ⇒ x0 = 1

2
x0 + 3 1 + 3 4
For n = 0, equation (1) ⇒ x1 = = = =2
2 x0 2 2

2
x1 + 3 2 2 + 3 4 + 3 7
For n = 1, equation (1) ⇒ x 2 = = = = = 1.75
2 x1 2(2) 4 4

2
x 2 + 3 (1.75) 2 + 3 6.0625
For n = 2, equation (1) ⇒ x 3 = = = = 1.732149
2 x2 2(1.75) 3.5

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 4

2
x 3 + 3 (1.732149) 2 + 3
For n = 3, equation (1) ⇒ x 4 = = = 1.7320508
2 x3 2 x3

We stop the iteration because the value of x3 and x4 are approximately equal. Hence
the root is x = 1.7320508. (ANSWER)

Q.16/page # 47

Find the +ve real root of xex = 1, using Newton Raphson method.

Use x0=1.

Ans:

Given that: xex = 1 ==> xex – 1 = 0

Let f(x) = xex – 1 ==> f(xn) = xnexn – 1

d
⇒ f ′(x ) = ( xe x −1) = xex + ex.1 – 0
dx

⇒ f ′(x ) = xex + ex

⇒ f ′( x n ) =exn ( xn + 1)

Using Newton Raphson Method

f ( xn ) x n e xn − 1
x n +1 = xn − => x n +1 = x n − xn
f ′( x n ) e ( x n + 1)

x n e xn ( x n + 1) − ( x n e xn − 1)
x n +1 =
e xn ( x n + 1)

2 2
x n e xn + x/ n e xn − x/ n e xn + 1 x n e xn + 1
⇒ x n +1 = ⇒ x n +1 = xn ---------> (1)
e xn ( x n + 1) e ( x n + 1)

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 5

For n = 0, equation (1) =>

2
x0 e x0 + 1
x1 = x0
e ( x0 + 1)

12.e1 +1 2.7183 +1 3.7183


x1 = = = = 0.6839
e1 (1 +1) 2.7183 × 2 5.4365

⇒ x1 = 0.6839

For n = 1, equation (1) =>

x1 e x1 + 1 ( 0.6839) e 0.6839 + 1 0.4677× 1.9816+ 1 1.9267


2 2
x2 = x1 = = = = 0.5776
e ( x1 + 1) e 0.6839(0.6839+ 1) 1.9816× 1.6839 3.3368

For n = 2, equation (1) =>

x2 e x2 + 1 ( 0.5776) e 0.5776 + 1 0.3336× 1.7816+ 1 1.5944


2 2
x3 = x2 = = = = 0.5672
e ( x2 + 1) e 0.5776(0.5776+ 1) 1.7816× 1.5776 2.8109

After 3 iterations the values of x2 and x3 coincide. Hence the root is x = 0.5672.
(ANSWER)

TYPE NUMBER 2
SECANT METHOD
Key
 The formula for Secant Method is:
x n −1 f ( x n ) − x n f ( x n −1 )
x n +1 =
f ( x n ) − f ( x n −1 )

 f(x) will be given.


 For f(xn) and f(xn-1) put x = xn and x = xn-1 in the given function f(x).

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 6

 Interval (x0, x1) will be given or individually the values of x0 and x1 will be given,
if not then 1st we find the values of x0 and x1 by putting x = 0, 1, 2, 3, 4,
………….. to get the change in sign for f(x).
 Finally put n = 1, 2, 3, 4, …………….. in the formula. The root will be that for
which two values of x coincide.
(ii) To solve xx = 10 by Secant Method.
xn xn −1
Let f(x) = xx – 10 ⇒ f(xn) = x n − 10 ⇒ f(xn-1) = xn−1 − 10
Using Secant Method
x n −1 f ( x n ) − x n f ( x n −1 )
x n +1 = --------> (1)
f ( x n ) − f ( x n −1 )

as root lies in the interval (2, 3) ⇒ x0 = 2 and x1 = 3


equation (1) ⇒
x xn −1 x xn − 1
x n −1 ( x n n − 10) − x n ( x n −1 − 10) x n −1 ( x n n − 10) − x n ( x n −1 − 10)
x n +1 = xn xn −1
= xn xn −1
( x n − 10) − ( x n −1 − 10) x n − 10 − x n −1 + 10
x xn − 1
x n −1 ( x n n − 10) − x n ( x n −1 − 10)
= x xn −1
x n n − x n −1
x xn − 1
x n −1 .x n n − 10x n −1 − x n .x n −1 + 10x n
⇒ x n +1 = x xn −1
− −− > (1)
x n n − x n −1
For n = 1, equation (1) ⇒
x x
x 0 .x1 1 − 10x 0 − x1 .x 0 0 + 10x1 2( 3 )3 − 10( 2 ) − 3( 2 ) 2 + 10( 3 ) 54 − 20 − 12 + 30 52
x2 = = = = = 2.2609
x
x1 1 − x 0
x0
33 − 2 2 27 − 4 23

For n = 2, equation (1) ⇒


x2 x
x1 .x 2 − 10 x1 − x 2 .x1 1 + 10 x 2 3( 2.2609 ) 2.2609 − 10( 3 ) − 2.2609( 3 )3 + 10( 2.2609 )
x3 = =
x2
x2
− x1
x1
( 2.2609 ) 2.2609 − 3 3
18.9721 − 30 − 61.0443 + 22.6090 − 49.4632
x3 = = = 2.3923
6.3240 − 27 − 20.6760
For n = 3, equation (1) ⇒

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 7

x3 x2
x 2 .x 3 − 10 x 2 − x 3 .x 2 + 10 x 3 2.2609( 2.3923 ) 2.3923 − 10( 2.2609 ) − 2.3923( 2.2609 ) 2.2609 + 10( 2.3923 )
x4 = =
x3
x3
− x2
x2
( 2.3923 ) 2.3923 − ( 2.2609 ) 2.2609
182189 − 22.6090 − 15.1290 + 23.9230 4.4039
x4 = = = 2.4546
8.0582 − 6.3240 1.7342
For n = 4, equation (1) ⇒
x4 x3
x 3 .x 4 − 10 x 3 − x 4 .x 3 + 10 x 4 2.3923( 2.4546 ) 2.4546 − 2.4546( 2.3923 ) 2.3923 − 10( 2.3923 ) + 10( 2.4546 )
x5 = =
x4
x4
− x3
x3
( 2.4546 ) 2.4546 − ( 2.3923 ) 2.3923
21.6802 − 19.7798 − 23.9230 + 24.5460 2.5234
x5 = = = 2.5126
9.0625 − 8.0582 1.0043
We stop the iteration because the values of x4 and x5 are approximately equal. Hence
the root is x = 2.5126 (ANSWER)

TYPE NO. 3
METHOD OF FALSE POSITION
OR
REGULA FALSI METHOD
KEY
(1) Formula for False position is
f ( xL )[ xR − xL ]
xi = x L +
f ( xL ) − f ( xR )
Where xL = Lower value of the interval
xR = Upper value of the interval
(2) The function f(x) will be given.
(3) The interval will be given, if not then put x = 0, 1, 2, 3,………….in f(x).
If f(x) changes its sign for any two consecutive values of x, the interval will be
that one.
(4) We put all these values in the formula (1) to get xi.
(5) Find f(xi), if f(xi) is nearly equal to ‘ZERO’ stop the iteration process otherwise
proceed by reducing the interval in the following ways:

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 8

F(xL) F(xR) F(xi) Replace xL or xR by xi


Positive Negative Positive Replace xL by xi
Negative Positive Positive Replace xR by xi
Positive Negative Negative Replace xR by xi
Negative Positive Negative Replace xL by xi
(6) We stop the iteration process when the value of f(xi) is nearly equal to zero and
the root will be xi.

Q.14/Page # 46
To solve the question f(x) = sinx – 0.5x by using the False position Method.
From the previous question the root lies in the interval (1,2) ⇒ xL = 1, xR= 2
Now f(xL) = f(1) = sin1 – 0.5(1) = 0.8414 – 0.5 = 0.3414
And f(xR) = f(2) = sin2 – 0.5(2) = 0.9093 – 1 = -0.0907
Using the formula for Regula Falsi Method
f ( x L )[ x R − x L ]
xi = x L +
f ( x L ) − f ( x R ) --------->(1)

0.3414 [ 2 − 1] 0.3414
xi = 1 + =1 + = 1 + 0.7900 = 1.79
0.3414 + 0.0907 0.4321
now f(xi) = f(1.79) = sin(1.79) -0.5(1.79) = 0.9760-0.895=0.081
(Not nearly equal to zero. So we proceed)
We have the following situation
.f(xL) = 0.3414 (+ve)
.f(xR) = - 0.0907 (-ve)
.f(xi) = 0.081 (+ve)
⇒ xi = xL = 1.79, xR = 2
⇒ f(xi) = 0.081 = f(xL) [i.e. we replace xL by xi and f(xL) by f(xi) in (1)]
equation (1) ⇒
0.081[2 − 1.79 ] 0.0170
xi = 1.79 + = 1.79 + = 1.79 + 0.0990 = 1.8890
0.081 + 0.0907 0.1717
Now f(xi) = f(1.8890) = sin(1.8890) – 0.5(1.8890) = 0.0053
Since the value of f(xi) is nearly equal to Zero ⇒ the root is x = 1.8890 Answer
TYPE NO. 4
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 9

BISECTION METHOD
OR
BOLZANO METHOD
KEY
• The value of f(x) will be given.
• Find those values of x for which f(x) changes its sign. The root will lie in that
interval.
• Find the mid point of the interval and find f(x) for that value of x.
• Reduce the interval for which f(x) changes its sign [Already discussed in Type #3]
and go on till the value of f(x) nearly equal to zero. This will be your root.

Q.11/Page # 46
Find a positive real root of f(x) = sinx – x/2, with x1 = π /2 and x2 = π using Bisection
Method. Do six iterations.
Ans: Given function is: f(x) = sinx – x/2 -------->(1)
1st we find the interval for which f(x) changes its sign.
Since x1 = π /2 and x2 = π
Therefore f(x1) = f(π /2) = sinπ /2 -π /2/2 = 1 – π /4 = 1 – 0.785 = 0.215 (+ve)
And f(x2) = f(π ) = sinπ - π /2 = 0 – 1.571 = -1.571(-ve)
As f(x) changes its sign for x1 = π /2 and x2 = π
⇒ the interval is (π /2, π ) or (1.571, 3.142)
Now we find the mid point of x1 and x2
x1 + x 2 1.571 + 3.142
Mid point = x = = = 2.356
2 2

Put this value of x in (1)


.f(x) = f(2.356) = sin(2.356) – 2.356/2 = -0.471
(not nearly equal to zero, so we proceed)
For the next step we have:
.f(x1) is +ve f(x2) is – ve f(x) is – ve

⇒ x1 = 1.571 and x2= x = 2.356


Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 10

[we choose x as x2 because f(x2) and f(x) have same sign]


And f(x1) = 0.215 (+ve), f(x2) = f(x) = - 0.471 (-ve)
x1 + x 2 1.571 + 2.356
Now mid point = x = = = 1.963
2 2

Put this value of x in equation (1)


.f(x) = f(1.963) = sin(1.963) – 1.963/2 = -0.058
(not nearly equal to zero, so we proceed)
For the next step, we have:
.f(x1) = 0.215 (+ve), f(x2) = - 0.471 (-ve), f(x) = -0.058 (-ve)
⇒ x1 is the same and x2 = x = 1.963
x1 + x 2 1.571 + 1.963
So, mid point = x = = = 1.767
2 2

Put in equation (1)


.f(x) = f(1.767) = sin(1.767) – 1.767/2 = 0.097
(Not nearly equal to zero, so we proceed)
For the next step, we have:
.f(x1) = 0.215 (+ve), f(x2) = - 0.058 (-ve), f(x) = 0.097 (+ve)
⇒ x1 = x = 1.767 and x2 = 1.963 (which is the same)
x1 + x2 1.767 + 1.963
So, Mid point = x = = = 1.865
2 2
Put in equation (1)
.f(x) = f(1.865) = sin(1.865) – 1.865/2 = 0.024
(Not nearly equal to zero, so we proceed)
For the next step, we have:
.f(x1) = 0.097 (+ve), f(x2) = - 0.058 (-ve), f(x) = 0.024 (+ve)
⇒ x1 = x = 1.865 (Changed) and x2 = 1.963 (Not changed)
x1 + x2 1.867 + 1.963
So , Mid point = x = = = 1.889
2 2
Put this value of x in equation (1)
.f(1.889) = sin(1.889) – 1.889/2 = 0.004
This value of f(x) is nearly equal to Zero. Hence the root is x = 1.889(ANSWER)

CHAPTER # 3
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 11

LINEAR EQUATIONS
Consider the system of equations.
2x1 – 3 x2 + 7x3 = 10
8x1 + 2 x2 + 5x3 = 12
4x1 – 3x2 – 9 x3 = 16
All the above equations involve three unknowns i.e. x1, x2, x3 with maximum power
“ONE”. So this system of equations is called system of linear equations. We can write
it in matrix form as:
2 −3 7  x1  10 
8 5    
 2 x 2 = 12 

4 −3 −9
x 3 
 16 

i.e. Ax = c
2 −3 7 
 5 
Where A = 8 2  and is called coefficient matrix

4 −3 −9

10 
 
c = 12  which is called column matrix or column vector.

16 

Augmented Matrix is:

2 −3 7 10 
 5 12 
Ac = 8 2 

4 −3 −9 16 

The system of linear equations can be solved by two methods.

• Direct Method.
• Iterative Method.

Types of Direct Method

• Crammer’s Rule
• Gauss Elimination Method.
• Gauss Jordan Method.
• Method of Inversion.
• Choleski’s Factorization Method.

TYPE NO. 1
CRAMMER’S RULE
KEY

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 12

• Write the system of equations in Matrix form i.e. Ax = c


• Find |A|. If |A| ≠0, solution exists and if |A| = 0, then solution does not exit.
• Find |A1|, |A2|, |A3|, where |A1|, |A2| and |A3| are the determinants obtained by
replacing the 1st , 2nd and 3rd column of A by c respectively.
A1 A2 A3
• The solution is: x1 = A
, x2 = A
, x3 = A
.
• The solution set will be written as: a = (x1, x2, x3) T
Where T stands for Transpose

Q.3/Page # 84
Solve the system of equations by using Crammer’s Rule
2.16x1 + 3.75x2 + 0.98x3 = 8.68
4.12x1 + 1.67x2 + 7.21x3 = 0.25
3.14x1 + 4.02x2 + 2.16x3 = 9.16
Ans:
The system can be written in matrix form as:
2.16 3.75 0.98   x1  8.68 
4.12 1.67 7.21  x  = 0.25 
  2   
3.14 4.02 2.16   x 3  9.16 

i.e. Ax = c

1st we find |A|

2.16 3.75 0.98


|A| = 4.12 1.67 7.21
3.14 4.02 2.16
Expanding by R1
1.67 7.21 4.12 7.21 4.12 1.67
|A| = 2.16
4.02 2.16
−3.75
3.14 2.16
+0.98
3.14 4.02
|A| = 2.16[ (1.67)(2.16) – (4.02)(7.21)]
- 3.75[(4.21)(2.16) – (7.21)(3.14)]
+ 0.98[(4.12)(4.02) – (3.14)(1.67)]
|A| = 2.16(3.60 – 28.98) – 3.75(8.90 – 22.64) + 0.98(16.56 – 5.24)
|A| = - 54.82 + 51.52 + 11.09 = 7.79 ≠0

⇒ Solution exists.

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 13

8.68 3.75 0.98


Now | A 1 |= 0.25 1.67 7.21
9.16 4.02 2.16
Expanding by R 1
1.67 7.21 0.25 7.21 0.25 1.67
= 8.68 −3.75 +0.98
4.02 2.16 9.16 2.16 9.16 4.02
=8.68(3.60 - 28.98) - 3.75(0.54 - 66.04) +0.98(1.005 - 15.29)
= −220 .298 +245 .62 −13 .999 = 11 .32
2.16 8.68 0.98
Also | A 2 |= 4.12 0.25 7.21
3.14 9.16 2.16
Expanding by R 1
=2.16(0.54 - 66.04) - 8.68(8.89 - 22.64) +0.98(37.74 - 0.785)
=- 141.48 +119.35 +36.21 =14.08
2.16 3.75 8.68
And | A 3 |= 4.12 1.67 0.25
3.14 4.02 9.16
Expanding by R 1

= 2.16(15.29 - 1.005) - 3.75(37.74 - 0.785) +8.68(16.56 - 5.24)


=30.85 - 138.58 +98.257 = - 9.4724
| A1 | 11.32
So x 1 = = =1.44
|A| 7.79
| A 2 | 14 .08
x 2 = = =1.798
|A| 7.79
| A | −9.4724
x 3 = 3 = = −1.209
| A| 7.79
Hence the solution is : x = ( x1 , x 2 , x3 ) T = (1.44 ,1.798 ,−1.209 ) T

Some important Hints


(i) Elementary Row Operation (ERO)
The operations over a matrix A are called elementary row operations if:
• Any two rows of A are interchanged i.e. Ri j
• Any row of A is multiplied by a non-zero element. i.e. KRi
• Any row of A is added to a scalar multiple of another row of A. i.e. Ri ± KRj
(ii) Echelon Form of a Matrix
A matrix is said to be echelon matrix if:
• The first non-zero element of each row is non – zero [as a special case 1]
• The number of zeros on L.H.S of “1” (one) increases row by row.
• Zero row is the last one
Example
1 2 3 4 
0 1 5 6 
A= 
0 0 1

−3
 
0 0 0 1 
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 14

(iii) Reduced Echelon form


A matrix is called in reduced Echelon form if:
• It is in Echelon form.
• If “1” lies in any column, the remaining Entries in that column will be Zero.
Example:
1 0 0 1
 0 2
A = 0 1 
0
 0 
1 3

Type No. 2
Gauss Elimination Method
KEY
• Write the system of equations in matrix form.
• Write the matrix form in tabular form.
• Change the co-efficient matrix to Echelon form.
• Find the values of unknowns. i.e. x1, x2, x3,…………..
• Solution is: x = ( x1 , x2 , x3 )
T

Q.2/Page # 83
Solve by Gauss Elimination Method
2x1 – x2 + 3x3 – x4 = 7
x1 – x2 + 4x3 – 2x4 = 5
3x1 + 2x2 + x3 + 4x4 = 31
4x1 – 3x2 + 3x3 – 3x4 = -5
Ans:
Writing the system of equations in matrix form

 2 − 1 3 − 1  x1   7 
 1 − 1 4 − 2  x   5 
   2 =  
 3 2 1 4   x3   3  1
    
 4 − 3 3 − 3   x4   − 5
Ax = c
Using Gauss Elimination Method, We write the system in tabular form as:

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 15

Row
Rows X1 X2 X3 X4 C
Explanation

R1 2 -1 3 -1 7 Eq(1)
R2 1 -1 4 -2 5 Eq(2)
R3 3 2 1 4 31 Eq(3)
R4 4 -3 3 -3 -5 Eq(4)

R5 1 -1/2 3/2 -1/2 7/2 ½ R1


R6 0 -1/2 5/2 -3/2 3/2 R2 – R5
R7 0 7/2 -7/2 11/2 41/2 R3 – 3R5
R8 0 -1 -3 -1 -19 R4 – 4R5

R9 1 -1/2 3/2 -1/2 7/2


R10 0 1 -5 3 -3 -2R6
R11 0 0 -14 5 -31 R7 – 7/2R10
R12 0 0 -8 2 -22 R8 + R10

R13 1 -1/2 3/2 -1/2 7/2


R14 0 1 -5 3 -3
R15 0 0 1 -5/14 31/14 -1/14 R11
R16 0 0 0 -12/14 -60/14 R12 + 8R15

R17 1 -1/2 3/2 -1/2 7/2


R18 0 1 -5 3 -3
R19 0 0 1 -5/14 31/14
R20 0 0 0 1 60/12 -14/12 R16

R20 ⇒ x4 = 60/12 = 5
⇒ x4 = 5
5 31 5 31
R19 ⇒ x3 − x4 = ⇒ x 3 − (5) =
14 14 14 14
31 25 31 + 25 56
⇒ x3 = + = = =4
14 14 14 14
R18 ⇒ x2 − 5 x3 + 3x 4 = −3 ⇒ x 2 − 5(4) + 3(5) = −3 ⇒ x2 − 20 + 15 = −3 ⇒ x 2 = −3 + 5 ⇒ x 2 = 2
1 3 1 7 1 3 1 7 5 7
R17 ⇒ x1 − x2 + x3 − x 4 = ⇒ x1 − ( 2) + (4) − (5) = ⇒ x1 − 1 + 6 − =
2 2 2 2 2 2 2 2 2 2
7 5 7 + 5 + 2 − 12 2
⇒ x1 = + + 1 − 6 ⇒ x1 = = =1
2 2 2 2
Hence x = ( x 1 , x 2 , x 3 , x 4 ) T
= (1, 2, 4,5 ) T

Q.1(ii)/Page # 83
X1 + x2 + x3 + x4 = 4
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 16

2x1 + 3x2 + 7x3 – x4 = 11


3x1 – 2x2 + 5x3 – 3x4 = 3
4x1 – 5x2 – 2x3 – 3x4 = -6
Ans:
Matrix form is
1 1 1 1  x1   4 
2 3 7 −1    
 x 2 =  11 
3 −2 5 − 3 x3  3 
    
4 −5 −2 − 3x 4 − 6
Ax = c
Using Gauss Jordon Method in tabular form:
Row
Rows X1 X2 X3 X4 C
Explanation
R1 1 1 1 1 4 Eq(1)
R2 2 3 7 -1 11 Eq(2)
R3 3 -2 5 -3 3 Eq(3)
R4 4 -5 -2 -3 -6 Eq(4)
R1
R5 1 1 1 1 4
R2 – 2R5
R6 0 1 5 -3 3
R3 – 3R5
R7 0 -5 2 -6 -9
R8 0 -9 -6 -7 -22
R4 – 4R5
R9 0 1 5 -3 3 R6
R10 1 0 -4 4 1 R5 – R9
R11 0 0 27 -21 6 R7 + 5R9
R12 0 0 39 -34 5 R8 + 9R9

R13 0 0 1 -7/9 2/9 1/27 R11


R14 0 1 0 8/9 17/9 R9 – 5R13
R15 1 0 0 8/9 17/9 R10 + 4R13
R16 0 0 0 -11/3 -11/3 R12 – 39R13

R17 0 0 0 0 1 -3/11 R16


R18 0 0 1 0 1 R13+7/9R17
R19 0 1 0 0 1 R14– 8/9R17
R20 1 0 0 1 1 R15–8/9 R17

R21 1 0 0 0 1 R20
R22 0 1 0 0 1 R19
R23 0 0 1 0 1 R18
R24 0 0 0 1 1 R17

R24 ⇒ x4 = 1
R23 ⇒ x3 = 1
R22 ⇒ x2 = 1
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 17

R21 ⇒ x1 = 1
Hence the solution is: x = ( x1 , x 2 , x3 , x 4 ) = (1,1,1,1) Answer
T T

Type No. 4
Method of Inversion
Key
• Write the system of equation in matrix form.
• Re-write it as x = A-1c
• Find A-1 by Gauss Jordan Method.
• Tabular form of this method contains co-efficient Matrix and the identity matrix.
Change the co-efficient Matrix to identity Matrix by ERO and get the values of
unknowns.
Identity Matrix is:
1 0 0
 0
I = 0 1  etc.

0 0 1

Q.4/Page # 84
Solve the system of equation by Inversion of the matrix.
4.65x1 + 1.98x2 – 4.62x3 = 11.25
0.79x1 – 2.54x2 + 3.16x3 = -4.91
4.02x1 – 8.17x2 + 2.93x3 = -6.90
Ans:
Matrix form of the system is
4.65 1.98 − 4.62  x1  11 .25 
0.79 − 2.54 3.16     
 x 2 = − 4.91 

4.02 −8.17 2.93 
x3  −6.90 
Ax = c
x = A-1c -(1)

We 1st find A-1 by Gauss Jordan Method

Row
Rows X1 X2 X3 C1 C2 C3
Explanation

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 18

R1 4.65 1.98 -4.62 1 0 0 Eq(1)


R2 0.79 -2.54 3.16 0 1 0 Eq(2)
R3 4.02 -8.17 2.93 0 0 1 Eq(3)

R4 1 0.42 0.99 0.25 0 0 1/4.65 R1


R5 0 -2.88 2.38 -0.11 1 0 R2 – 0.79R4
R6 0 -9.87 -1.04 -1 0 1 R3 – 4.02R4

R7 0 1 -0.82 0.07 -0.34 0 -1/2.88 R5


R8 1 0 1.34 0.22 0.14 0 R4 – 0.42R7
R9 0 0 -9.20 -0.32 -3.43 1 R6 + 9.87R7

R10 0 0 1 0.34 0.36 -0.11 -1/9.20 R9


R11 0 1 0 0.36 -0.04 -0.08 R7 + 0.82R10
R12 1 0 0 -0.24 -0.34 0.14 R8 – 1.34R10

R13 1 0 0 -0.24 -0.34 0.14 R12


R14 0 1 0 0.36 -0.04 -0.08 R11
R15 0 0 1 0.34 0.36 -0.11 R10

−0.24 −0.34 0.14 


-1  −0.04 −0.08 
Hence A =  0.36 

 0.34 0.36 0.11 

Equation (1) ⇒
 x1  −0.24 −0.34 0.14 11 .25 
x 2 =  0.36 −0.04 −0.08  
    4.91 

x3   0.34 0.36 0.11 

−6.90 

 x1  − 2.74 −1.70 −0.99  −5.40 
x 2 =  4.01 −0.24 + 0.61  =  4.38 
     

x3   3.90 +1.78 + 0.74 
   6.43 

Hence the solution is: x = ( x1 , x2 , x3 ) = ( −5.40 ,4.38 ,6.43 )
T T

NOTES
(i) Square Matrix
Number of Rows = Number of Columns

(ii) Rectangular Matrix


Number of Rows ≠ Number of Columns
(iii) Diagonal Matrix
If in a Matrix, aij =0 for i ≠ j and atleast one aii ≠ 0
For example

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 19

2 0 0
 0
A= 0 6  where 2, 6, 3 are called diagonal elements.
0
 0 
3
(iv) Upper Triangular Matrix
If aij = o, for i > j and there exists at least one non-zero entry for i < j .
For example
3 2 5
 9
U = 0 7 

0 0 6

(v) Lower Triangular Matrix
If aij = 0, for i < j and there exists at least one non-zero entry for i > j
For example
4 0 0
 0
L = −9 2 

1 6 7

(vi) Singular Matrix
If |A| = 0 ⇒ A is singular.
(vii) Non-singular Matrix
If |A| ≠ 0 ⇒ A is non-singular.
(viii) How to express a Matrix A in the product of L and U.
i.e. A = LU
where L is the unit lower triangular and U is the upper triangular. i.e.
a11 a12 a13 
 
If A = a21 a22 a23  , then
a31 a32 a33 
a11 a12 a13   1 0 0 u11 u12 u13 
a a22 a23  = l21 1 0 . 0 u 22 u 23 
 21    
a31 a32 a33  l31 l32 1  0 0 u33 

TYPE NO. 5
CHOLESKI’S METHOD
KEY
• Given a system of equation: Ax = c
• Find L and U such that: LU = A
• Where L is the lower triangular matrix with diagonal elements “1” and U is upper
triangular Matrix.
• Let y = (y1, y2, y3,…………., yn)T
• Find y by using: Ly = c
• Find x = (x1, x2, x3, ……..xn)T by using Ux = y which is the solution
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 20

Q.17/Page # 88
1 2 3
 7
Decompose the Matrix A = 2 8  in to the product of LU. Where L is the unit

2 16 12 

lower triangular and U is upper triangular. Hence solve the system of equations.
.x1 + 2x2 + 3x3 = 2
2x1 + 8x2 + 7x3 = 7
2x1 + 16x2 + 12x3 = 10
Ans:
1st we express the matrix in the LU form. i.e. A = LU
1 2 3  1 0 0 u11 u12 u13 
2   
 8 7 = l 21 1 0. 0 u 22 u 23 
2
 16  l
12  l 32 1  0 0 u 33 
 31  
⇒ u11 = 1 u12 + 0 + 0 = 2 u13 + 0 + 0 = 3
l21.u11 + 0 + 0 = 2 ⇒u12 = 2 ⇒ u13 = 3
l21(1) = 2 l21.u12 + u22 = 8 l21.u13 + u23 = 7
⇒ l21= 2 (2)(2) + u22 = 8 (2)(3) + u23 = 7
l31.u11 + 0 = 2 u22 = 8 – 4 = 4 u23 = 7 – 6 = 1
l31(1) = 2 ⇒ u22 = 4 l31.u13 + l32.u23 + u33 = 12
⇒ l31 = 2 l31.u12 + l32.u22 + 0 = 16 2.3 + 3.1 + u33 = 12
2.2 + l32 (4) = 16 u33 = 12 – 6 – 3 = 3
4l32 = 16 – 4 = 12 ⇒ u33 = 3
⇒ l32 = 3

1 0 0 1 2 3
 0 and U = 
 1
hence L = 2 1 0 4 

2 3 1
 
0 0 3

Now we find the solution set of the system


To find y such that:
L y = c
1 0 0  y1   2 
2 1 0  y  =  7 
  2   
2 3 1   y  10 
 3
 y +0+0  2
 1   
 2 y1 + y 2 + 0  =  7 
2 y + 3 y + y  10 
 1 2 3   

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 21

R1 ⇒ y1 = 2
R2 ⇒ 2y1 + y2 = 7
⇒ (2)(2) + y2 = 7
⇒ y2 = 7 – 4 = 3
⇒ y2 = 3
R3 ⇒ 2y1 + 3y2 + y3 = 10
⇒ (2)(2) + (3)(3) + y3 = 10
⇒ y3 = 10 – 4 – 9 = - 3
⇒ y3 = -3
Therefore y = (y1, y2, y3)T = (2, 3, -3)T
Now we find x= (x1, x2, x3)T such that:
U x = y
1 2 3 x1   2 
0    
 4 1
 x 2  =  3 

0 0 
3  −3
 x3   
x1 +2 x 2 +3 x3   2 
   
 0 + 4 x 2 + x3  =  3 
 0 +0 +3 x  −3
 3   
R3 ⇒ 3x3 = -3
⇒ x3 = -1
R2 ⇒ 4x2 + x3 = 3
⇒ 4x2 + (-1) = 3
⇒ 4x2 = 3 + 1 = 4
⇒ x2 = 1
R3 ⇒ x1 + 2x2 + 3x3 = 2
⇒ x1 + 2.1 + 3. -1 = 2
⇒ x1 + 2 – 3 = 3
⇒ x1 = 4
Hence the solution is: x = (x1, x2, x3)T = (4, 1, -1)T

Diagonally Dominant Matrix


A square Matrix A whose elements are aij is said to be diagonally dominant if:
n
aii ≥ ∑ aij
i=1 , i = 1,2, ……………n
i≠ j
Example
a a12 a13  5 1 −2
 11  
Let A = a 21 a 22 a 23  = 3 − 12 3 
a a32 a33  1 − 4 − 20 
 31 
In the above matrix the Diagonal elements are 5, -12, -20. the absolute of these value are 5, 12, 20. These
values are greater than the absolute sum of the remaining elements two elements in that row. For example 5
is greater than |1| + |-2| = 1 + 2 = 3. Similar case for the other two rows.

TYPE NO. 2
ITERATIVE METHODS
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 22

There are two types of Iterative Methods


• Jacobi Method
• Gauss Seidel Method.

Type # 1
Jacobi’s Method

KEY
• Write down the system in Diagonally Dominant form
• Write down the Diagonally Dominant form in Iterative form.
• Find 1st Iteration by Putting x0 = (0, 0, 0, 0,………)T
• We continue this process until we get the required accuracy.

Q.16/ Page # 87
Solve the system of equations
x1 + 0.1x2 = 1.0
0.1x1 + x2 + 0.1x3 = 2
0.1x2 + x3 = 3
Using (i) Jacobi’s Method.
(ii) Gauss Seidel Method.

Ans:
(i) 1st we will use the Jacobi’s Method
x1 + 0.1x2 = 1.0
0.1x1 + x2 + 0.1x3 = 2
0.1x2 + x3 = 3

The system is already in diagonally dominant form. So it can be written as:

. x1 = 1 – 0.1x2
. x2 = 2 – 0.1x2 – 0.1x3 -----------------> (A)
. x3 = 3 – 0.1x2
1st Iteration
Put x1 = x2 = x3 = 0 in (A)
⇒ x1 = 1 , x2 = 2 and x3 = 3
2nd Iteration
Put x1 = 1, x2 = 2 and x3 = 3 in (A)
⇒ x1 = 1 – (0.1)2 = 1 – 0.2 = 0.80
x2 = 2 – (0.1) 1 – (0.1) 3 = 2 – 0.1 – 0.3 = 1.6
x3 = 3 – (0.1)2 = 3 – 0.2 = 2.8
3rd Iteration
Put x1 = 0.80, x2 = 1.6 and x3 = 2.8 in (A)
⇒ x1 = 1 – (0.1) (1.60) = 0.84
. x2 = 2 – (0.1)(0.80) – (0.1)(2.8) = 1.64
x3 = 3 – (0.1)(1.6) = 2.836
th
4 Iteration
Put x1 = 0.84, x2 = 1.64 and x3 = 2.836 in (A)
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 23

⇒ x1 = 1 – (0.1) (1.64) = 0.836


x2 = 2 – (0.1)(0.84) – (0.1)(2.846) = 1.6324
x3 = 3 – (0.1)(1.64) = 2.836
This converges to the exact solution. Hence the solution is:
x1 = 0.836, x2 = 1.6324 and x3 = 2.836
(ii) Now we will use Gauss Seidel Method to solve the system.
Since
. x1 = 1 – 0.1x2-----------------------> (1)
. x2 = 2 – 0.1x2 – 0.1x3-------------> (2)
. x3 = 3 – 0.1x2 ----------------------> (3)
1st Iteration
Put x2 = 0 in (1) ⇒ x1 = 1
Put x1 = 1 and x3 = 0 in (2)
⇒ x2 = 2 – (0.1)(1) – 0 = 1.99
Put x2 = 1.99 in (3)
⇒ x3 = 3 – (0.1)(1.99) = 2.801
nd
2 Iteration
Put x2 = 1.99 in (1)
⇒ x1 = 1 – (0.1)(1.99) = 0.801
Put x1 = 0.801 and x3 = 2.801 in (2)
⇒ x2 = 2 – (0.1)(0.801) – (0.1)(2.801) = 1.640
Put x2 = 1.640 in (3)
⇒ x3 = 3 – (0.1)(1.640) = 2.836
rd
3 Iteration
Put x2 = 1.640 in (1)
⇒ x1 = 1 – (0.1)(1.640) = 0.836
Put x1 = 0.836 and x3 = 2.836 in (2)
⇒ x2 = 2 – (0.1)(0.836) – (0.1)(2.836) = 1.632
Put x2 = 1.632 in (3)

⇒ x3 = 3 – (0.1)(1.632) = 2.836
This converges to the real solution. So the solution is:
x1 = 0.836, x2 = 1.632 and x3 = 2.836

Q.10/Page # 86
Solve the system of equations.
6x1 – 3x2 + x3 = 11
2x1 + x2 – 8x3 = -15
x1 – 7x2 + x3 = 10
Using Gauss Seidel method with initial vector x0 = (0, 0, 0)T

Ans:
1st we will write the system in Diagonally Dominant form by interchanging 2nd and 3rd equations.i.e.
6x1 – 3x2 + x3 = 11
x1 – 7x2 + x3 = 10 -----------> (A)
2x1 + x2 – 8x3 = -15

Writing the system (A) as:


Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 24

x1 = 1/6(11 + 3x2 – x3)----------> (1)


x2 = 1/7(-10 + x1 + x3)----------> (2)
x3 = 1/8(15 + 2x1 + x2)---------> (3)
1st Iteration
Put x2 = x3 = 0 in (1)
⇒ x1 = 1/6(11+0 – 0) = 1.833
Put x1 = 1.833 and x3 = 0 in (2)
⇒ x2 = 1/7(- 10 + 1.833 + 0) = - 1.166
Put x1 = 1.833 and x2 = - 1.166 in (3)
⇒ x3 = 1/8(15 + 2(1.833) – 1.166) = 2.125
nd
2 Iteration
Equation (1) ⇒ x1 = 1/6[11 + 3(- 1.166) – 2.125] = 0.885
Equation (2) ⇒ x2 = 1/7[- 10 + 0.885 + 2.125] = - 0.989
Equation (3) ⇒ x3 = 1/8[15 + 2(0.885) – 0.989] = 1.972
3rd Iteration
Equation (1) ⇒ x1 = 1/6[11 + 3(- 0.989) – 1.972] = 1.001
Equation (2) ⇒ x2 = 1/7[- 10 + 1.001 + 1.972] = - 1.003
Equation (3) ⇒ x3 = 1/8[15 + 2(1.001) – 1.003] = 2.000
Which converges to the real solution. i.e x1 = 1, x2 = - 1 and x3 = 2
hence the solution is x = (x1, x2, x3)T = (1, -1, 2)T

Q.9/Page # 86
The pair of equations
.x1 + 2x2 = 3.0
.3x1 + x2 = 4.0
Can be re-arranged to give:
x1 = 3 – 2x2
x2 = 4 – 3x1
Apply Jacobi’s Method to this arrangement, beginning with x = (1.01, 1.01)T and notice the system diverges.
Now apply Gauss Seidel method to system and comment which method diverges more rapidly.
Ans: Given that: x1 = 3 – 2x2
.x2 = 4 – 3x1
1st we use Jacobi’s Method
1st Iteration
put x1 = 1.01 and x2 = 1.01 in the above equations.
.x1 = 3 – 2(1.01) = 0.98
.x2 = 4 – 3(1.01) = 0.97
2nd Iteration
x1 = 3 – 2(0.97) = 1.06
x2 = 4 – 3(0.98) = 1.06
3rd Iteration
x1 = 3 – 2(1.06) = 0.88
x2 = 4 – 3(1.06) = 0.82
4th Iteration
x1 = 3 – 2(0.82) = 1.36
x2 = 4 – 3(0.88) = 1.36
5th Iteration
x1 = 3 – 2(1.36) = 0.28
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 25

x2 = 4 – 3(1.36) = - 0.08
6th Iteration
x1 = 3 – 2(- 0.08) = 3.16
x2 = 4 – 3(0.28) = 3.16
after 6th Iteration x1 = 3.16 and x2 = 3.16. i.e. x = (3.16, 3.16)T, which is diverging.
Now using Gauss Seidel Method
x1 = 3 – 2x2---------->(1)
x2 = 4 – 3x1---------->(2)
1st Iteration
put x2 = 1.01 in (1)
⇒ x1 = 3 – 2(1.01) = 0.98 put in (2) ⇒ x2 = 4 – 3(0.98) = 1.06
2nd Iteration
equation (1) ⇒ x1 = 3 – 2(1.06) = 0.88
equation (2) ⇒x2 = 4 – 3(0.88) = 1.36
3rd Iteration
equation (1) ⇒ x1 = 3 – 2(1.36) = 0.28
equation (2) ⇒ x2 = 4 – 3(0.28) = 3.16
4th Iteration
equation (1) ⇒ x1 = 3 – 2(3.16) = - 3.32
equation (2) ⇒ x2 = 4 – 3(- 3.32) = 13.96
5th Iteration
equation (1) ⇒ x1 = 3 – 2(13.96) = - 24.92
equation (2) ⇒ x2 = 4 – 3(- 24.92) = 78.76
6th Iteration
equation (1) ⇒ x1 = 3 – 2(78.76) = - 154.52
equation (2) ⇒ x2 = 4 – 3(- 154.52) = 467.56
After 6th Iteration x1 = - 154.52 and x2 = 467.56. i.e. x = (- 154.52, 467.56)T. which is diverging.
Comment: After six iterations we see that Gauss Seidel Method diverges rapidly than the Jacobi’s Method.
CHAPTER#4

Numerical Integration

1. Trapezoidal Rule or Trapezium Rule.

b 1 1 
∫a
f ( x ) dx = h  f ( x 0 ) + f ( x1 ) + f ( x 2 ) + .......... .... + f ( x n )
2 2 
b −a
Where h=
n

2. Simpson’s Rule

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 26

h
[ f ( x0 ) + 4 f ( x1 ) + 2 f ( x 2 ) + 4 f ( x3 ) + 2 f ( x 4 ) + 4 f ( x5 ) + .......... ....... + f ( x n )]
b

a
f ( x) dx =
3
b −a
Where h=
n
Error = Approximate value – True value

EXERCISE ON PAGE 112

Q #1 b 3 1
:∫ f ( x ) dx = ∫ ( x + ) dx
P − 112 x
a 2

1
Here f ( x) = x + , a = 2, b = 3, n = 4
x
b−a 3−2 1
h= = =
n 4 4

1
x f ( x) = x +
x
1
x0 = 2 ⇒ f ( x0 ) = f (2) = 2 + = 2.5
2
1 1
x1 = 2 + = 2.25 ⇒ f ( x1 ) = f ( 2.25 ) = 2.25 + = 2.694
4 2.25
2 1
x2 = 2 + = 2.5 ⇒ f ( x 2 ) = f (2.5) = 2.5 + = 2.9
4 2.5
3 1
x3 = 2 + = 2.75 ⇒ f ( x3 ) = f ( 2.75 ) = 2.75 + = 3.114
4 2.75
4 1
x4 = 2 + =3 ⇒ f ( x 4 ) = f (3) = 3 + = 3.333
4 3

Apply Trapezoidal Rule

b 1 1 

a
f ( x ) dx = h  f ( x 0 ) + f ( x1 ) + f ( x 2 ) + f ( x3 ) + f ( x 4 ) 
2 2 

3 1 1  2.5 3.333 
∫ ( x + x )dx = 4 
2 2
+ 2.694 + 2.9 + 3.114 +
2  
Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar
Numerical Analysis 27

1
= (1.25 + 8.708 +1.667 )
4
1
= ×11 .625 = 2.9063
4
For true value
3 1 3 3 1
∫ ( x + x )dx = ∫
2 2
xdx + ∫
2 x
dx

3
x2 3
= + ln x 2
2 2

1 2
= (3 − 2 2 ) + (ln 3 − ln 2)
2
1
= (9 − 4) + (1.099 − 0.693 )
2
= 2.5 + 0.406 = 2.906
Error = Approximate value – True value = 2.9063 − 2.906 = 0.0003

b 2 1
(ii) ∫a
f ( x )dx = ∫
0 e4x
dx

1
Here f ( x) = = e − 4 x , a = 0, b = 2, n = 4
e4x
b−a 2−0 2 1
h= = = =
n 4 4 2
x f ( x ) = e −4 x

x0 = 0 f ( x 0 ) = f (0) = e 0 = 1

1
x1 = 0 + = 0.5 f ( x1 ) = f (0.5) = e −4( 0.5) = 0.135
2
2
x2 = 0 + =1 f ( x 2 ) = f (1) = e −4 = 0.018
2
3
x3 = 0 + = 1.5 f ( x3 ) f (1.5) = e −4 (1.5) = 0.002
2
4
x4 = 0 + =2 f ( x 4 ) = f (2) = e −8 = 0.0003
2
Trapezoidal rule
b 1 1 
∫a
f ( x )dx = h  f ( x 0 ) + f ( x1 ) + f ( x 2 ) + f ( x3 ) + f ( x 4 ) 
 2 2 

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 28

1 1 0.0003 
=  + 0.135 + 0.018 + 0.002 +
2 2 2  
1
= ( 0.5 + 0.1550 + 0.0002 )
2
1
= × 0.6550 = 0.3275
2

For true value


2
2 e −4 x 1 −4 x 2

0
e −4 x dx =
−4
=−
4
e
0
0

1
= − (e −8 − e 0 )
4
1
= − (0.0003 −1)
4
1
= − (−0.9997 ) = 0.2499
4
Error = Approximate value – True value
=0.3275-0.2499=0.0776

Q #2 b 2
: ∫ f ( x)dx = ∫ ( x 4 − x 2 +1) dx
P − 112 a 1

Here f ( x) = x 4 − x 2 + 1, a = 1, b = 2, n = 2

b − a 2 −1 1
h= = =
n 2 2
x f ( x ) = x 4 − x 2 +1

x0 =1 f ( x 0 ) = f (1) = 1 −1 +1 = 1

1
x1 = 1 + = 1.5 f ( x1 ) = f (1.5) = (1.5) 4 − (1.5) 2 + 1 = 3.8125
2
2
x2 = 1 + =2 f ( x 2 ) = f ( 2) = ( 2) 4 − ( 2) 2 + 1 = 13
2
Simpson’s Rule
h
[ f ( x0 ) + 4 f ( x1 ) + f ( x 2 )]
b
∫a
f ( x ) dx =
3
1
∫1 ( x − x +1)dx = 2 ×3 [1 + 4(3.8125 ) +13 ]
3
4 2

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 29

1
= (1 +15 .2500 +13 )
6
1
= × 29 .2500 = 4.8760
6
b 2
(ii) ∫a
f ( x ) dx =∫ e x sin xdx
0

Here f ( x) = e x sin x, a = 0, b = 2, n = 2

b −a 2−0 2
h= = = =1
n 2 2
x f ( x) = e x sin x

x0 = 0 f ( x 0 ) = f (0) = e 0 sin 0 = 0

x1 = 0 + 1 = 1 f ( x1 ) = f (1) = 2.2874

x 2 0 +1(2) = 2 f ( x 2 ) = f ( 2) = 6.7188

Simpson’s Rule

h
[ f ( x0 ) + 4 f ( x1 ) + f ( x 2 )]
b
∫a
f ( x )dx =
3
1
∫0 e sin xdx = 3 [0 + 4 × 2.2874 + 6.7188 ]
2
x

1
= ×15 .8668
3
= 5.2886

Q #3 b 1
: ∫ f ( x ) dx = ∫ ydx
P − 112 a 0

Here a = 0, b =1, h = 0.1

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 30
x f ( x) = y
x 0 = 0. 2 f ( x 0 ) =1
x1 = 0.1 f ( x1 ) = 0.99
x 2 = 0.2 f ( x 2 ) = 0.961
x3 = 0.3 f ( x3 ) = 0.9141
x 4 = 0.4 f ( x 4 ) = 0.852
x 5 = 0. 5 f ( x5 ) = 0.779
x 6 = 0. 6 f ( x 6 ) = 0.697
x 7 = 0.7 f ( x 7 ) = 0.613
x8 = 0.8 f ( x8 ) = 0.527
x 9 = 0. 9 f ( x9 ) = 0.445
x10 = 1 f ( x10 ) = 0.369

Trapezoidal Rule

1 
 f (x0 ) + f (x1 ) + f (x2 ) + f (x3 ) + f (x4 ) + f (x5 ) + f (x6 ) + f (x7 ) + f (x8 ) + f (x9 )
b 2
∫ a  1
f ( x ) d =x h 

+ f (x1 )0
 2 
1 1 0.3 5 9
∫ 0 y d= 0x.1 2 + 0.9 +90.9 +60.9 1+ 04.8 5+ 02.7 7+ 09.6 9+ 07.6 1+ 03.5 2+ 07.4 4+ 5 2 
0.1 × 6.7780 = 0.6678

Q #4 b 2 dx
: ∫ f ( x ) dx = ∫
1+ x4
P − 112 a 1

1
Here f ( x) = , a = 1, b = 2, n = 6
1+ x4
b − a 2 −1 1
h= = =
n 6 6
1
x f ( x) =
1+ x4

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar


Numerical Analysis 31

x0 =1 f ( x 0 ) = 0.5

1
x1 = 1 + = 1 .2 f ( x1 ) = 0.325
6
2
x2 = 1 + = 1.3 f ( x 2 ) = 0.259
6
3
x3 = 1 + = 1.5 f ( x3 ) = 0.165
6
4
x4 = 1 + = 1.7 f ( x 4 ) = 0.107
6
5
x5 = 1 + = 1.8 f ( x5 ) = 0.087
6
6
x6 = 1 + =2 f ( x 6 ) = 0.059
6

Trapezoidal Rule

b 1 1 
∫a
f ( x )dx = h  f ( x 0 ) + f ( x1 ) + f ( x 2 ) + f ( x3 ) + f ( x 4 ) + f ( x5 ) + f ( x 6 ) 
2 2 
2 1 1 0.5 0.059 
∫1 1 + x 4 dx = 6  2 + 0.325 + 0.259 + 0.165 + 0.107 + 0.087 + 2 
1
= ×1.223 + 0.205
6

= 0.4088 Answer

Prepared by: Inayat Ullah Lecturer in Mathematics Edwardes College Peshawar