Numerical Analysis Edited
Numerical Analysis Edited
6x3 = -18
X3 = −18⁄6 = -3
1
Example 2
Solve the set of equations using Gaussian Elimination method
2 x1 3x 2 2 x3 9 (1)
3x1 2 x 2 x3 4 (2)
x1 4 x 2 2 x3 6 (3)
Solution
3
Multiply equation (1) by ( ) and subtract from equation (2)
2
13 19
x 2 4 x3 (4)
2 2
5 3
x 2 x3 (5)
2 2
5
Multiply equation (4) by and subtract from equation (5)
13
7 56
x3
13 26
x3 4
5 3
x2 4
2 2
5 5
x2
2 2
x2 1
2 x1 3(1) 2(4) 9
2 x1 4
x1 2
x1 2, x 2 1, x3 4
Example 3
Solve the set of equations using Gaussian Elimination method
2
x1 3x 2 2 x3 8 (1)
2 x1 x 2 x3 9 (2)
3x1 2 x 2 3x3 5 (3)
Solution
5 x2 3x3 7 (4)
18 18
x3
5 5
x3 1
x1 3 2 2 1 8
x1 4 8
x1 4
x1 4, x 2 2, x3 1
Example 4
Solve using Gaussian Elimination method, the set of equation. Leave your answer to two decimal places
(2 d. p)
5.22X1 + 3.9X2 – 1.38X3 = 3.41
1.26X1 – 4.33X2 – 2.75X3 = 11.18
1.53X1 + 2.84X2 + 6.16X3 = 7.34
Solution
1.26
Multiplying equation (1) by 5.22 and subtract from equation (2), we have
3
-5.274X2 – 2.417X3 = 10.357 - - - - - - - - - - - (4)
1.53
Multiplying equation (1) by 5.22
and subtract from equation (3), we have
Solution
X2- 3x3 = 5
2x2+x3 = 3
Multiply equation (4) by (2⁄1) and subtract from equation (5)
7x3 = -7
X3 = -1
2x2-1 = 3
X2 = 2
4
X1+2-1 = 2
X1 = 1
X1= 1, X2 = 2, X3 = -1
Example 6
Solve the set of equations using Gaussian Elimination method
−𝟒𝒙𝟐 𝒙𝟑
+ = 𝟐 … … … … … … … … … … … … … … … … … … . (𝟒)
𝟑 𝟑
Multiply equation (1) by (2⁄3) and subtract from equation (3)
𝑥2 10𝑥3
− = −7 … … … … … … … … … … … … … .5
3 3
Multiply equation (1) by (−1⁄4) and subtract from equation (5)
−39𝑥3 −13
=
12 2
𝑥3 = 2
𝑥2 10(2)
− = −7
3 3
𝑥2=−1
𝑥1=1
XI = 1, X2 = -1, X3 = 2
5
ITERATIVE METHODS FOR SOLVING LINEAR SYSTEMS OF EQUATIONS
- The Jacobi Iterative method
- The Gauss-Seidel iterative method
First Iteration
Start with the trial solution, X1 = X2 = X3 = X4 = 0. We have
X1 = 2.300, X2 = 1.666, X3 = 4.250, X4 = 4.700
Second Iteration
X1 = 0.495, X2 = 2.050, X3 = 2.614, X4 = 3.270
Third Iteration
X1 = 1.346, X2 = 2.065, X3 = 3.240, X4 = 4.220
Fourth Iteration
X1 = 0.908, X2 = 1.979, X3 = 2.866, X4 = 3.889
Fifth Iteration
X1 = 1.052, X2 = 1.988, X3 = 3.045, X4 = 4.057
6
Sixth Iteration
X1 = 0.969, X2 = 1.998, X3 = 2.979, X4 = 3.973
Seventh Iteration
X1 = 1.012, X2 = 2.003, X3 = 3.013, X4 = 4.011
Eighth Iteration
X1 = 0.995, X2 = 2.000, X3 = 2.995, X4 = 3.995
Ninth Iteration
X1 = 1.0025, X2 = 2.000, X3 = 3.0021, X4 = 4.0025
Tenth Iteration
X1 = 0.9988, X2 = 1.9999, X3 = 2.9990, X4 = 3.9989
First Iteration
X1 = X2 = X3 = X4 = 0
1
X1 = [23 + 3(0)– 0– 4(0)] = 2.300
10
7
1
X4 = [47 - 2.300+ 3(1.156)– 4(3.482)] = 3.424
10
Example 3
Consider the following set of equations using Jacobi method and Gauss-Seidel method
10X1 – X2 + 2X3 =6
-X1 + 11X2 – X3 + 3X4 = 25
2X1 – X2 + 10X3 – X4 = -11
3X2 – X3 + 8X4 = 15
Solution
1
X1 = [6 + X2 – 2X3]
10
1
X2= 11[25 + X1 + X3 – 3X4]
1
X3= 10[-11 - 2X1+ X2– X4]
1
X4= 8[15 - 3X2 + X3]
8
Second Iteration
X1 = 1.0473, X2 = 1.7159, X3 = -0.8052, X4 = 0.8852
Third Iteration
X1 = 0.9326, X2 = 2.0530, X3 = -1.0493, X4 = 1.1309
Fourth Iteration
X1 = 1.0152, X2 = 1.9537, X3 = -0.9681, X4 = 0.9739
Fifth Iteration
X1 = 0.9890, X2 = 2.0114, X3 = -1.0103, X4 = 1.0214
Sixth Iteration
X1 = 1.0032, X2 = 1.9922, X3 = -0.9945, X4 = 0.9944
Seventh Iteration
X1 = 0.9981, X2 = 2.0023, X3 = -1.0020, X4 = 1.0036
Eighth Iteration
X1 = 1.006, X2 = 1.9987, X3 = -0.9990, X4 = 0.9989
Ninth Iteration
X1 = 0.9997, X2 = 2.0004, X3 = -1.0004, X4 = 1.0006
Tenth Iteration
X1 = 1.0001, X2 = 1.9998, X3 = -0.9998, X4 = 0.9998
X1 = 0.6000, X2 = 0, X3 = 0, X4 = 0
9
1
X2= 11[25 + 0.6000+0– 3(0)] = 2.3273
X1 = 0.6000, X2 = 2.3273, X3 = 0, X4 = 0
1
X3= 10[-11 – 2(0.6000)+ 2.3273+ 0] = -0.9873
1
X4= 8[15 – 3(2.3273)+ 0.9873] = 0.8789
Second Iteration
Using the value; X1 = 0.6000, X2 = 2.3273, X3 = -0.9873, X4 = 0.8789
X1 = 1.030, X2 = 2.037, X3 = -1.014, X4 = 0.9844
Third Iteration
X1 = 1.0065, X2 = 2.0036, X3 = -1.0025, X4 = 0.9983
Fourth Iteration
X1 = 1.0009, X2 = 2.0003, X3 = -1.0003, X4 = 0.9999
Fifth Iteration
X1 = 1.0001, X2 = 2.0000, X3 = -1.0000, X4 = 1.0000
To two decimal places,
Example 4
Consider the three-by-three system using Jacobi method
2X1– X2 + X3 = -1
X1+ 2X2 –X3 = 6
X1– X2 + 2X3 = -3
Ax = B, Convert to X = Cx + d
Ax = B =>Cx + d
1
X1= 2[-1 + X2 - X3]
1
X2= 2[6 – X1 + X3]
1
X3= 2[-3 – X1 + X2]
10
1
X2= 2[6 – 0+ 0] = 3.0000
1
X3= 2[-3 – 0+ 0] = -1.5000
11
1
X1= [24- 3X2]
4
1
X2 = 4[30- 3X1 + X3]
1
X3 = 4[-24 + X2]
X1 = 6.0000, X2 = 0, X3 =0
1
X2 = 4[30– 3(6)+ 0] = 3.0000
1
X3 = 4[-24 + 3] = -5.2500
12
NEWTON-RAPHSON METHOD
Xn 1 g ( Xn)
That will find the solution of every equation another interactive method that is useful is called the
Newton-Raphson method.
To carry out the iterations we need to find the point where the tangents meet the X-axis.
Figure 1: Newton-Raphson
𝑡ℎ𝑒 𝑐ℎ𝑎𝑛𝑔𝑒 𝑖𝑛 𝑦
The gradient of the tangent: 𝑡ℎ𝑒 𝑐ℎ𝑎𝑛𝑔𝑒 𝑖𝑛 𝑥
dy y0
atx0
dx x0 x1
dy y0
We have atx0 and we need to find x1.
dx x0 x1
dy
Using y0 and atx0 in the formulae isn’t very convenient, so, since y f ( x) wehave
dx
dy y0
y 0 f ( x0 )and atx0 f 1 ( x0 )
dx x0 x1
then,
f ( x0 )
f 1 ( x0 )
x0 x1
13
Rearranging:
f ( x0 ) f (x )
x0 x1 1
x1 x0 1 0
f ( x0 ) f ( x0 )
so,
f ( x0 )
x1 x0
f 1 ( x0 )
f ( x0 )
x2 x1
f 1 ( x0 )
In general, we have
f ( xn)
Xn 1 Xn
f 1 ( xn)
SUMMARY
Example 1
Using the Newton – Raphson Method. Obtain the root of the equation at approximate x = 2 (i.e. xo = 2)
x 3 − 3x − 4 = 0
Solution
f(x) = x 3 − 3x − 4
f ′ (x) = 3x 2 − 3
xo = 2, then
f(xo ) = f(2) = 23 − 3(2) − 4 = −2
14
f(xn )
xn+1 = xn − ,n = 0
f ′ (xn )
f(xo )
x1 = xo −
f ′ (xo )
(−2)
x1 = 2 − = 2.22
9
f(x1 ) = f(2.22) = 0.281
f ′ = f 1 (2.22) = 11.785
f(x1 )
x2 = x1 −
f ′ (x1 )
(0.281)
x2 = 2.22 − = 2.196
11.785
f(x2 ) = f(2.196) = (2.196)3 − 3(2.196) − 4
x 3 + 2x 2 − 2 = 0
Solution
f(x) = x 3 + 2x 2 − 2
f ′ (x) = 3x 2 + 4x
xo = 1
f(xo ) = f(1) = 13 + 2(1)2 − 2 = 1
15
f(x1 ) = f(0.857143) = (0.857143)2 + 2(0.857143)2 − 2
f ′ (x1 ) = f ′ (0.857143) = 3(0.857143)2 + 4(0.857143) = 5.632654367
f(x1 )
x2 = x1 −
f ′ (x1 )
0.099126169
x2 = 0.857143 − = 0.839545
5.632654367
f(x2 ) = f(0.839545) = (0.839545)3 + 2(0.857143)2 − 2 = 0.061129622
f ′ (x2 ) = f ′ (0.839545) = 3(0.839545)2 + 4(0.839545) = 5.472687421
f(x2 )
x3 = x2 −
f ′ (x2 )
0.061129622
x3 = 0.839545 − = 0.828375
5.472687421
f(x3 ) = f(0.828375) = (0.828375)3 + 2(0.828375)2 − 2 = 0.059154536
f ′ (x3 ) = f ′ (0.828375) = 3(0.828375)2 + 4(0.828375) = 5.372115422
f(x3 )
x4 = x3 −
f ′ (x3 )
(−0.059154536)
x4 = 0.828375 − = 0.839386404
5.372115422
f(x4 ) = f(0.839386) = (0.839386)3 + 2(0.839386)2 − 2 = 0.0005429485904
f ′ (x4 ) = f ′ (0.839386) = 3(0.839386)2 + 4(0.893386) = 5.471250571
f(x4 )
x5 = x4 −
f ′ (x4 )
0.0005429485904
x5 = 0.839386 − = 0.839287
5.471250571
f(x5 ) = f(0.8392987) = (0.839287)3 + 2(0.839287)2 − 2 = 0.000001339065412
f ′ (x5 ) = f ′ (0.839287) = 3(0.839287)2 + 4(0.839287) = 5.470356005
x6 = 0.839287
x5 = x6 = 0.839287
x = 0.839287
Example 3
Using the Newton – Raphson method, obtain the root of the equation at xo= 3
16
x 4 + x 2 − 80
Solution
f(x) = x 4 + x 2 − 80
f ′ (x) = 4x 3 + 2x
xo = 3
f(xo ) = f(3) = 34 + 32 − 80 = 10
f ′ (xo ) = f ′ (3) = 4(3)3 + 2(3) = 114
f(xo )
x1 = xo −
f ′ (x0 )
10
x1 = 3 − = 2.9123
114
f(x1 ) = f(2.9123)4 + (2.9123)2 − 80 = 0.417185792
f ′ (x1 ) = f ′ (2.9123) = 4(2.9123)3 + 2(2.9123) = 17.4738
f(x1 )
x2 = x1 −
f ′ (x1 )
0.417185792
x2 = 2.9123 − = 2.9083
17.4738
f(x) = f(2.9083) = (2.9083)4 + (2.9083)2 − 80 = 0.000493483125
f ′ (x) = f ′ (2.9083) = 4(2.9083)3 + 2(2.9083) = 104.2126357
0.000493483125
x3 = 2.9083 − = 2.9083
104.2126357
x2 = x3 = 2.9083
x = 2.9083
Example 4
Use the Newton – Raphson method to estimate the root of the following equation
y = x 3 + 2x 2 − 5x − 1 with xo = −1.9
Solution
17
f(xo )
x1 = xo −
f ′ (xo )
(9.861)
x1 = −1.9 − = 3.106215
−1.77
f(x1 ) = f(3.106215) = 3(3.106215)2 + 2(3.106215)2 − 5(3.106215) − 1
= 32.37057488
f(x3 )
x4 = x3 −
f ′ (x3 )
1.712430708
x4 = 1.748036 − = 1.5945791
11.15903357
f(x4 ) = f(1.594579) = (1.594579)3 + 2(1.594579)2 − 5(1.594579) − 1
= 0.166976993
f ′ (x4 ) = f ′ (1.594579) = 3(1.594579)2 + 4(1.594579) − 5 = 9.006363562
f(x4 )
x5 = x4 −
f ′ (x4 )
18
0.166976993
x5 = 1.594579 − = 1.57603911
9.006362562
x5 = 1.576039
f(x5 ) = f(1.576039) = (1.576039)3 + 2(1.576039)2 − 5(1.576039) – 1
= 0.002324444025
f ′ (x5 ) = f ′ (1.576039) = 3(1.576039)2 + 4(1.576039) − 5
= 8.755852789
f(x5 )
x6 = x5 −
f ′ (x5 )
0.002324444025
x6 = 1.576039 − = 1.576
8.755852789
x5 = x6 = 1.576
x = 1.576 (3 D. P)
Example 5
Solve the equation x 3 + 5x − 7 = 0 using Newton Raphson method
Solution
f(x) = x 3 + 5x − 7
f ′ (x) = 3x 2 + 5
f(0) = 03 + 5(0) − 7 = −7
f(1) = 13 + 5(1) − 7 = −1
f(2) = 23 + 5(2) − 7 = 11
Hence, there will be a root between x = 1 and x = 2; so take x = 1
Therefore, xo = 1, n = 0
f(xo )
x1 = x0 −
f ′ (xo )
f(xo ) = f(x1 ) = 13 + 5(1) − 7 = −1
f ′ (xo ) = f ′ (1) = 3(1)2 + 5 = 8
−1 9
x1 = 1 − ( ) = = 1.125
8 8
f(x1 ) = f(1.125) = (1.125)3 + 5(1.125) − 7 = 0.048828128
19
0.048828125
x2 = 1.125 − = 1.119449378
8.796875
x2 = 1.1194
f(x2 ) = f(1.1194) = (1.1194)3 + 5(1.1194) − 7 = −0.0003287106
f ′ (x2 ) = f ′ (1.1194) = 3(1.1194)2 + 5 = 8.75916908
f(x2 )
x3 = x2 −
f ′ (x2 )
−0.000328710616
x3 = 1.1194 − ( ) = 1.1194
8.75916908
x2 = x3 = 1.1194 (4 D. P)
The nth root of a given number
n
x ≅ √N
n
Then x + h = √N
(x + h)n = N
N − xn
h =
nx n − 1
n N − xn
√N + x +
nx n − 1
Find the square root of 10 to 3 D.P
√10 ≅ 3 = x1
N − xn 10 − 32 1
h = n − 1
= 2 − 1
= = 0.01667
nx 2(3 ) 6
Since N = 10, x = 3, n = 2
x2 = x1 + h = 3 + 0.1667 = 3.1667
10 − (3.1667)2
h = = −0.0044192
2 × 3.1667
x3 = x2 + h
x3 = 3.1667 − 0.0044192 = 3.16228
x4 = x3 + h
10 − (3.16228)2
h = = −0.0000023
2 × 3.16228
x4 = 3.16228 − 0.0000023 = 3.16228
x3 = x4 = 3.162 x = 3.162 (3 D. P)
20
BISECTION METHOD
The bisection method (sometimes called the midpoint method for equations) is a method used to estimate
the solution of an equation.
We approach this problem by writing the equation in the form f(x) = 0 for some function f(x). This
reduces the problem to finding a root for the function f(x).
The Bisection Method also needs a closed interval [a,b] for which the function f(x) is positive at one
endpoint and negative at the other. In other words f(x) must satisfy the condition f(a)f(b) < 0. This means
that this algorithm can not be applied to find tangential roots.
Bisection Algorithm
The idea for the Bisection Algorithm is to cut the interval [a,b] you are given in half (bisect it) on each
iteration by computing the midpoint xmid. The midpoint will replace either a or b depending on if the sign
of f(xmid) agrees with f(a) or f(b).
Step 1: Compute xmid = (a+b)/2
Step 2: If sign(f(xmid)) = 0 then end algorithm
else If sign(f(xmid)) = sign(f(a)) then a = xmid
else b = xmid
Step 3: Return to step 1
• The Bisection Method is a successive approximation method that narrows down an interval that
contains a root of the function f(x)
• The Bisection Method is given an initial interval [a..b] that contains a root (We can use the
property sign of f(a) ≠ sign of f(b) to find such an initial interval)
• The Bisection Method will cut the interval into 2 halves and check which half interval contains a
root of the function
• The Bisection Method will keep cut the interval in halves until the resulting interval is extremely
small
The root is then approximately equal to any value in the final (very small) interval.
21
Figure 2: Bisection Graph
22
Example 1
Find the root of X3 – 2X - 3 = 0 by bisection method if the root lies between 0 and 2 [0, 2]. Take your
answer to 4 dp after three iterations
f(x) = X3 – 2X – 3
a = 0, b = 2
𝑎+𝑏 0+2
Xmid= 2
= 2
=1
f(a) = 03 – 2(0)– 3 = -3
f(b) = 23 – 2(2)– 3 = 1
f(xmid) = 13 – 2(1)– 3 = -4
Iteration a B xmid f(a) f(b) f(xmid)
1 0 2 1 -3 1 -4
2 1 2 1.5 -4 1 -2.262
3 1.5 2 1.75 -2.262 1 -1.140
4 1.75 2 1.875 -1.140 1 -0.158
X4= 1.875
X3 = 1.75
1.75+1.875
X= 2
= 1.8125 (4 dp)
Example 2
Find the root of X2– 3 = 0 by bisection method if the root lies between 0 and 4 [0, 4]
f(x) = X2– 3
a = 0, b = 4
𝑎+𝑏 0+4
Xmid= 2
= 2
=2
f(a) = 02– 3 = -3
f(b) = 42– 3 = 13
f(xmid) = 42– 3 = 1
1 0 4 2 -3 13 1
2 0 2 1 -3 1 -2
23
3 1 2 1.5 -2 1 -0.75
4 1.5 2 1.75 -0.75 1 0.0625
5 1.5 1.75 1.625 -0.75 0.0625 -0.3594
6 1.625 1.75 1.6875 -0.3594 0.0625 -0.1523
X = 1.732051849
X = 1.732052 [6 dp]
Example 3
Find the positive root of X3 – X = 1 by bisection method if the root lies between 1 and 2. Take your
answer to 4 dp after 3 iterations
f(x) = X3 – X – 1 = 1 [1, 2]
a = 1, b = 2
𝑎+𝑏 1+2
Xmid= 2
= 2
= 1.5
f(a) = 13 – 1 – 1 = -1
f(b) = 23 – 2 – 1 = 5
f(Xmid) = 1.53 – 1.5 – 1 = 0.875
Iteration a b xmid f(a) f(b) f(xmid)
1 1 2 1.5 -1 5 0.875
2 1 1.5 1.25 -1 0.875 -0.296875
24
3 1.25 1.5 1.375 -0.2969 0.875 0.224609375
4 1.25 1.375 1.3125 -0.2969 0.224609375 -0.051513671
X3 = 1.375
X4 = 1.3125
1.375 +1.3125
X= = 1.34375
2
X = 1.3438 [4 dp]
Example 4
Solve X3 – 9X + 1 = 0 by bisection method for the root between 2 and 4. Take your answer to 3dp. After
3 iterations
f(x) = X3 – 9X + 1 [2, 4]
a = 2, b = 4
𝑎+𝑏 2+4
f(Xmid) = 2
= 2
=3
f(a) = 23 – 9(2) + 1 = -9
f(b) = 43 – 9(4) + 1 = 29
f(Xmid) = 33 – 9(3) + 1 = 1
1 2 4 3 -9 29 1
2 2 3 2.5 -9 1 -5.875
3 2.5 3 2.75 -5.875 1 -2.953125
4 2.75 3 2.875 -2.953125 1 -1.111328125
2.75 +2.875
X= 2
= 2.8125 [4 dp]
Example 5
Find the positive of X – CosX = 0 by bisection method if the root lies between 0.5 and 1. Take your
answer to 4 dp after 3 iterations
f(x) = X – CosX [0.5, 1]
25
a = 0.5, b = 1
𝑎+𝑏 0.5+1
f(Xmid) = 2
= 2
= 0.75
X = 0.7969[4 dp]
Example 6
Find the positive root of Xex= 1 by bisection method if the root lies between 0 and 1. Take your answer to
4 dp after 3 iterations.
f(x) = Xex– 1 [0, 1]
a = 0, b = 1
𝑎+𝑏 0+1
f(Xmid) = 2
= 2
= 0.5
f(a) = 0 x e0 – 1 = -1
f(b) = 1 x e1 – 1 = 1.718281828
26
X3= 0.625, X4= 0.5625
X3 +X4 0.625 + 0.5625
X= 2
= 2
=0.59375
X = 0.5938 [4 dp]
TRAPEZOIDAL RULE
F x dx 2 y 2 y1 2 y 2 2 y 3 2 y n 1 y n
b h
0
a
Example 1
Evaluate using trapezoidal rule
27
F x 2 sin xdx
0
Solution n= 6
h 15 rad 0.2618
12
Area
h
y 0 2 y1 2 y 2 2 y3 2 y 4 2 y5 y 6
2
0.2618
0 20.2588 20.5 20.7071 20.8660 20.9659 1
2
= 0.994254
28
SIMPSON’S RULE
F x dx 3 y 4 y1 2 y 2 4 y 3 2 y 4 2 y n 2 4 y n 1 y n
b h
0
a
Example 1
Using Simpson’s rule, evaluate
sin x
2.6
0.2 x
dx
Solution
h = 0.4 and
ba b a 2 .6 0.2
h= n 6
n h 0 .4
Y0 Y1 Y2 Y3 Y4 Y5 Y6
X 0.2 0.6 1.0 1.4 1.8 2.2 2.6
area
h
3
y 0 y 6 2 y 2 y4 4 y1 y3 y5
29
0.4
0.99335 0.19827 20.84147 0.54103 40.94107 0.70389 0.36750
3
0.4
1.19162 21.38250 42.01246
3
= 1.6009
Example 2
Using Simpsom’s Rule with strips to estimate
1 1
1 x
0 2
dx Giving your answer to 4d.p.
Solution
A
h
3
y 0 4 y1 2 y 2 4 y3 y 4
1 0
n 4, h 0.25
4
X 0 0.25 0.5 0.75 1
Y 1 0.94118 0.8 0.64 0.5
1 0.25
1 40.94118 20.8 40.64 0.5
1
1 x
0 2
dx
3
= 0.7854 4d.p
Example 3
3 1
Estimate
1 x
dx using Simpson’s rule
A
h
y 0 4 y1 2 y 2 4 y3 y 4
3
n=4, a=1, b=3
30
b a 3 1
h 0.5
n 4
X 1 1.5 2 2.5 3
1 0.5
1 40.66667 20.5 40.4 0.33333
3
1 x
dx
3
= 1.1000 (4d.p)
Example 4
Evaluate the following integral using Simpson’s rule with h=1.0, taking your answer to 2d.p
3
1= 3
x 4 dx
Solution
A = -3, b= 3, h=1.0
ba 33
n= 6
h 1 .0
Y0 Y1 Y2 Y3 Y4 Y5 Y6
X -3 -2 -1 0 1 2 3
F(x) 81 16 1 0 1 16 81
I
h
y0 4 y1 2 y 2 4 y3 2 y 4 4 y5 y6
3
1.0
81 416 21 40 21 416 81
3
294
98.00
3
Example 5
Evaluate the following integral using Simpson’s rule with h= 1.0, taking your answer to 4d.p
6 1
I dx
0 1 x
Solution
a=0, b=6, h=1.0
31
ba 60
n= 6
h 1.0
Y0 Y1 Y2 Y3 Y4 Y5 Y6
X 0 1 2 3 4 5 6
F(x) 1 0.5 0.3333 0.25 0.2 0.1667 0.1429
I
1..0
1 40.5 20.3333 40.25 20.2 40.1667 0.1429
3
1.95884d. p
5.8763
3
Example 5
1.2 1
Evaluate the integral using trapezoidal rule with h= 0.2, taking your answer to 4d.p I 1 x dx
0 2
Solution
a=0, b=1.2, h=0.2
b a 1. 2 0
n= 6
h 0.2
Y0 Y1 Y2 Y3 Y4 Y5 Y6
X 0 0.2 0.4 0.6 0.8 1.00 1.2
F(x) 1 0.9615 0.8621 0.7353 0.6098 0.5000 0.4098
I
h
y 0 2 y1 2 y 2 2 y3 2 y 4 2 y5 y 6
2
0.2
1 20.9615 20.8621 20.7353 20.6098 20.5000 0.4098
2
= 0.8747 4d.p
Using Simpson’s rule
I
h
y 0 4 y1 2 y 2 4 y3 2 y 4 4 y5 y 6
3
0.2
1 40.9615 20.8621 40.7353 20.6098 40.5000 0.4098
3
0.87614d. p
32
FINITE DIFFERENCE
Gregory-Newton interpolation formula using forward finite differences.
Example 1
X 2 4 6 8 10
F(x) 14 88 274 620 1174
x0 4, x1 6, x p 5.5
h x1 x0 6 2 2
x p x0 5.5 4
p 0.75
h 2
FIRST COMPILE THE TABLE OF FORWARD DIFFERENCES
X F(x) F 2 F 3 F
2 14
74
x0 4 88 112
5.5 x p 186 48
x1 6 274 160
346 48
8 620 208
554
10 1174
f p 1 f 0
p
33
p 1 2
f p f 0 pf 0 p
p 1 p 2 3 f
f 0 p 0
2! 3!
f p 1 p p
p 12 p p 1 p 23 f
6
1 2 1 2 3
0.75 0.25160 0.75 0.25 1.2548
f p f 5.5 88 0.75186
1 2 1 2 3
88 139.5 15 1.875 214.375
Example 2
Determine the value of f(-1) from the set of function
X -4 -2 0 2 4 6 8
F(x) 541 55 1 -53 -155 31 1225
X F(x) F 2 F 3 F 4 F
-4 541
-486
x 0 -2 55 432
x p 1 -54 -432
x1 0 1 0 384
-54 -48
2 -53 -48 384
-102 336
4 -155 288 384
186 720
6 31 1008
1194
8 1225
34
x0 2, x1 0, x p 1
h x1 x0 0 2 2
x p x0 1 2 1
p
h 2 2
p p 12 f 0 p p 1 p 2 3 f 0 p p 1 p 2 p 34 f 0
f p f 0 pf 0
1 2 1 2 3 1 2 3 4
1 1 1 1 3 1 1 3 5
0 48 384
2 2 2 2 2 2 2 2 2
55 54
1
2 1 2 1 2 3 1 2 3 4
55 27 0 3 15 10
f p f 1 10
Example 3
Find the polynomial Fx which has the values F0= -6, F1 = -2, F2= 8, F3 =36, F4 =94, F5= 194, F6=348 and
calculate the value of F3.6 by using the difference table.
x F(x) F 2 F 3 F 4 F
0 -6
4
1 -2 6
10 12
2 8 18 0
28 12
x0 3 36 30 0
x p 3.6 58 12
x1 4 94 42 0
100 12
5 194 54
154
6 348
35
X0=3, x1 =4, h=x1-x0=4-3=1
Xp =3.6, p=𝑥𝑝−𝑥0
ℎ
=3.6−3
1
=0.6
LINEAR PROGRAMMING
Linear Programming/linear optimization
Optimisation problem is one requiring the determination of the optimal (maximum or minimum) value of
a given function, called the objective function, subject to a set of stated restrictions or constraints placed
on the variable concerned.
Linear programming is a method of solving an optimization problem when the objective function is a
linear function and the constraints are linear equations or Linear inequalities.
There are two methods for solving linear programming problems, there are:
(i) Graphical Method (ii) Simplex Method
(i)Graphical Method: This method is for solving two variables only. Example are given below
Example 1:
Maximize z = 2x1+ 3x2
Subject to: 3x1 + 6x2 ≤ 24
2x1 + x2 ≤ 10
x1, x2 ≥0
Solution
The coordinates for our plot are:
(i) 3x1 + 6x2 = 24
When x1 = 0, x2 = 4 which gives (0,4)
When x1 = 0, x2 = 8 which gives (8,0)
(ii) 2x1 + x2 = 10
If x1 = 0, x2 = 10, which gives (0, 10)
36
When x1 = 0, x2 = 5, which gives (5, 10)
Hence the coordinates are (0, 4) and (8,0) for the first line (3x1 + 6x2 = 24)
And (0,10) and (5,0) for the first line (3x1 + 6x2 = 24) and (0,10) and (5,0) for second line (2x1 +x2 = 10)
Profit Lines
The profit lines are obtained from the objective function
To maximize Z = 2x1 + 3x2 choose arbitrary Z. Let Z = 6
2x1 + 3x2 = 6
For x1 = 0, x2 = 2 coordinate (0, 2)
For x2 = 0, x1 = 3 coordinate (3, 0)
This gives line PQ
Now, we increase Z to say Z = 12, then
2x1 + 3x2 = 12
For x1 = 0, x2 = 4 coordinate (0, 4)
For x2 = 0, x1 = 6 coordinate (6, 0)
This gives Line AS. Since PQ and AS are parallel lines all such profit lines will be parallel and moving
upward by increasing Z as indicated in the graph. These profit lines will finally leave the feasible region
at point B which gives the optimum results with values of x1 = 4, x2 = 2
Hence maximum Z = 2x1 + 3x2
Z = 2(4) + 3(2) = 14
Example 2:
Maximize Z = x1 + 2x2
Subject to : x2 ≤ 3
x1 + x2 ≤ 5
x1 – 2x2 ≤ 2
x1, x2 ≥ 0
Solution
The coordinates of plot
(i) x2 = 3
(ii) x1 + x2 = 5
37
(iii) x1 – 2x2 = 2
Example 3:
Maximize Z = 6𝑥1 + 9𝑥2
Subject to: 2𝑥1 + 2𝑥2 ≤ 24
𝑥1 + 5𝑥2 ≤ 44
6𝑥1 + 2𝑥2 ≤ 60
𝑥1 , 𝑥2 ≥ 0
Since the problem consists of only two variables 𝑥1 𝑎𝑛𝑑 𝑥2 , we may use a graphical method to obtain the
solution.
Solution
38
2𝑥1 + 2𝑥2 = 24
𝑥1 + 5𝑥2 = 44
6𝑥1 + 2𝑥2 = 60
The coordinates for the plot are obtained as follows:
(i) 2𝑥1 + 2𝑥2 = 24
For 𝑥1 = 0, 𝑥2 = 12 which gives (0, 12)
For 𝑥1 = 12, 𝑥2 = 0 which gives (12, 0)
(ii) 𝑥1 + 5𝑥2 = 44
For 𝑥1 = 0, 𝑥2 = 8.8 which gives (0, 8.8)
For 𝑥1 = 44, 𝑥2 = 0 which gives (44, 0)
39
= 6(4) + 9(8) = 96.
Example 4:
Maximize Z = 𝑥1 + 2𝑥2
Subject to: −3𝑥1 + 4𝑥2 ≤ 8
𝑥1 + 4𝑥2 ≤ 16
3𝑥1 + 2𝑥2 ≤ 18
𝑥1 , 𝑥2 ≥ 0
Coordinates of plot are:
(i) −3𝑥1 + 4𝑥2 = 8
For 𝑥1 = 0, 𝑥2 = 2 which gives (0, 2)
−8 −8
For 𝑥1 = , 𝑥2 = 0 which gives ( , 0)
3 3
(ii) 𝑥1 + 4𝑥2 = 16
For 𝑥1 = 0, 𝑥2 = 4 which gives (0, 4)
For 𝑥1 = 16, 𝑥2 = 0 which gives (16, 0)
40
Let Z = 8
𝑥1 + 2𝑥2 = 8
For 𝑥1 = 0, 𝑥2 = 4 coordinates (0, 4)
For 𝑥1 = 8, 𝑥2 = 0 coordinates (8, 0)
This gives plot TW
Increasing the value of Z further
Let Z = 10
𝑥1 + 2𝑥2 = 10
For 𝑥1 = 0, 𝑥2 = 5 coordinates (0, 5)
For 𝑥1 = 10, 𝑥2 = 0 coordinates (10, 0)
Simplex method
Step I: Convert the inequality constraints to equality constraints. Equate the objective function to zero.
Step 2: Set up an initial tableau for the problem. Check if the tableau is feasible or not. If it is feasible it
means it has a finite optimal solution, and then you can proceed and solve the problem.
Step 3: Apply the simplex criterion I to identify the incoming variable (variable entry the basis) using the
most negative value in the zj - cj row.
Step 4: Also apply the simplex criterion II to identify the outgoing variable (variable leaving the basis) by
taking ratio using the smallest element.
Step 5: Identify the pivot element (i.e. intersection of the row element and column element. The reduce
the pivot element to unity (i.e. 1) by dividing the element by itself.
Step 6: Carry out the iteration process until the tableau is optimal (i.e. zj - cj ≥ 0) for a maximization
problem then stop.
New number = old number − the product of the corresponding entries in the main row and key column
Nc = C− (A x B)
Example 1
Max z 3x1 4 x 2 2 x3
s.t 2 x1 3x2 x3 50
41
3x1 2 x 2 2 x3 40
x1 5 x2 2 x3 60
x1 , x 2 , x3 0
Max z 3x1 4 x 2 2 x3 0
s.t 2 x1 3x 2 x3 x 4 50
3x1 2 x 2 2 x3 x5 40
x1 5 x2 2 x3 x6 60
x1 , x 2 , x3 , x 4 , x5 , x6 0
x1 x2 x3 x4 x5 x6
2 3 1 1 0 0
3 2 2 0 0 0
1 5 2 0 1 1
2 1 0 0
3 = 2 0 +3 1 +1 0 Linearly independent
1 0 0 1
Incoming vector
x1 x2 x3 x4 x5 x6 Resource vector
zj Cj -3 -4 -2 0 0 0 0
Basis
42
x4 2 3 1 1 0 0 50 50
16
3
x5 3 -2 2 0 1 0 40
x6 1 2 0 0 1 60 60
5 12
5
50
Taking ratio 16
3
60
12
5
x1 x2 x3 x4 x5 x6
11 0 2 0 0 4 48
5 5
5
0 1 1 0 3 14
x4 7 5 5
5
x5 17
5 0 14
5 0 1 2
5 64
x2 1
5 1 2
5 0 0 1
5 12
0 0 5 11 0 1 70
7 7 7
1 0 1 5 0 3 10
x1 7 7 7
17 1 13 30
7 7
23
7
43
x5 0 0
0 1 3 1 0 2 10
x2 7 7 7
0 0 0 168
161
5
23
42
161
1760
23
1 0 0 14 1 8 260
x1 23 23 23 23
0 0 1 17 7 13 210
x3 23 23 23 23
0 1 0 4 3 1 140
x2 23 23 23 23
1760
z
23
New value =
New value =
2
115 15 2 11 1 5 5
5 7 5 5 5 7 7
5
11 5
New value = 0 1 11
7
5 7
44
11 5
New value = 48 14 48 22 70
5 7
Example 2
Max 3x1 2 x 2 4 x 3
S.t 4 x 2 x 2 2 x3 20
5 x1 3x 2 2 x 3 18
2 x1 3x 2 3x 3 21
x1 2 x 2 8
x , , x 2, x 3 0
Max 3x1 2 x 2 4 x3 0
S.t : 4 x1 2 x 2 2 x3 x 4 20
5 x1 3x 2 2 x 3 x 5 18
2 x1 3x 2 3x 3 x 6 21
x1 2 x 2 x 7 8
X1 X2 X3 X4 X5 X6 X7
j Cj -3 -2 -4 0 0 0 0 0
Basis
X4 4 2 -2 1 0 0 0 20
X5 5 -3 2 0 1 0 0 18
X6 2 3 3 0 0 1 0 21
X7 1 2 0 0 0 0 1 8
45
X1 X2 X3 X4 X5 X6 X7
−𝟕 2 0 0 0 𝟒 0 28
𝟑 𝟑
Basis
X4 𝟏𝟔 4 0 1 0 𝟐 0 34
𝟑 𝟑
X5 𝟏𝟏 -5 0 0 1 −𝟐 0 4
𝟑 𝟑
X3 𝟐 1 1 0 0 𝟏 0 7
𝟑 𝟑
X7 1 2 0 0 0 0 1 8
X1 X2 X3 X4 X5 X6 X7
0 𝟏𝟕⁄ 0 0 𝟏⁄ 𝟒𝟐⁄ 0 𝟑𝟏𝟐⁄
𝟏𝟏 𝟏𝟏 𝟑𝟑 𝟏𝟏
Basis
X4 0 0 1 0 𝟑𝟏𝟎⁄
𝟏𝟏
X1 1 −𝟏𝟓⁄ 0 0 𝟑⁄ −𝟐⁄ 0 𝟏𝟐⁄
𝟏𝟏 𝟏𝟏 𝟏𝟏 𝟏𝟏
X3 0 1 0 0 𝟔𝟗⁄
𝟏𝟏
X7 0 0 0 1 𝟕𝟔⁄
𝟏𝟏
310 12 69 76
X4 , X1 , X 3 , X7
11 11 11 11
X2 X5 X6 0
312
11
From the results,
X2 = 0, means items two should not be produced.
Example 3
46
Max Z = 2x1 + 6x2 + 4x3
S.t: 2x1 + 5x2 + 2x3 ≤ 38
4x1 + 2x2 + 3x3 ≤ 57
x1 + 3x2 + 5x3 ≤ 57
x1, x2, x3 ≥ 0
Simplex tableau
INITIAL TABLEAU
x1 x2 x3 x4 x5 x6 b
Zj - Cj
Basis -2 -6 -4 0 0 0 0
x4 2 5 2 1 0 0 38
x5 4 2 3 0 1 0 57
x6 1 3 5 0 0 1 57
Taking ratios
47
38
= 7.6
5
57
= 28.5
2
57
= 19
3
x1 x2 x3 x4 x5 x6 b
Zj - Cj
Taking ratios:
38 5
× = 19
5 2
209 5
× = 19
5 11
171 5
× =9
5 19
x1 x2 x3 x4 x5 x6 b
Zj - Cj
48
x5 63/19 0 0 -1/19 1 -11/19 22
Optimal solution
X2 * = 4
X5* = 22
x3 * = 9
x1* = x4* = x6*= 0
Zmax* = 60
49