Professional Documents
Culture Documents
Math 351 Handout
Math 351 Handout
Math 351 Handout
Learning Objectives
Unit content
1
SESSION 1-2: MATRICES
It is a very common practice to write the system of n equations in matrix form as Ax b , where
A is an n n , non-singular matrix and x and b are n1 matrices out of which b is known. i.e.,
a11 a12 a1n x1 b1
a a22 a2 n x2 b
A 21 , x , b 2
am1 am 2 ann xn bn
For small n the elementary methods like matrix inversion or Cramers rule given below are very
convenient to get the unknown vector x from the system Ax b .
Let A be a nonsingular matrix of order n and b be an n-vector. The solution x of the system
Ax b is given by:
a) Matrix Inversion as x = A-1.b
det Ai
b) Cramer’s rule as xi , i 1, , n
det A
where Ai is a matrix obtained by replacing the i th column of A by the vector b and
x x1 , x2 , , xn , i.e., Cramer’s Rule or by matrix inversion formula given as x A1b
T
However, for large ' n ' these methods will become computationally very expensive because of
the evaluation of matrix determinants involved in these methods. Hence to make the solution
methods computationally less expensive one has to find alternate means which doesn't require
the evaluation of any determinants or inverses to find x form Ax b .
2
1-2.2 Triangular System of Equations
The system of equations below is an upper triangular system of equations
an 1,n 1 xn 1 an 1, n xn bn 1
ann xn bn
Now the equations are solved starting from the last equation as it has only one unknown.
bn
xn*
ann
Then the second last equation, that is the (n-1)th equation, has two unknowns ( xn and xn 1 ), but
xn* is already known. This reduces the (n-1)th equation also to one unknown and we have:
xn 1
1
an 1,n1
b
n 1 an 1,n xn*
Back substitution hence can be represented for all equations by the formula
bn 1 n
*
xn* and xi bi ai , j x j for i n 1, n 2, ,1
ann ai ,i j i 1
n
Note 0.
j n 1
bn( n1)
xn ( n1)
ann
Then the second last equation, that is the (n-1)th equation, has two unknowns - xn and xn 1 , but
xn is already known. This reduces the (n-1)th equation also to one unknown. Back substitution
3
1 i 1
aij x j for
n
i 1
hence can be represented for all equations by the formula xi i 1 b
aii
i
j i 1
i n, n 1, n 2, ,1
n
Note: 0.
j n 1
The procedure just described above is called the Naïve Gaussian Elimination method or the
Gaussian Elimination without pivoting.
Example 1
25 5 1 106.8
A 64 8 1 , b 177.2
144 12 1 279.2
Solution
Forward Elimination of Unknowns: Since there are three equations, there will be two steps of
forward elimination of unknowns.
Row 1
25 (64) Row 1 2.56 6 gives Row 1 as 64 12.8 2.56 273.408
25 5 1 x1 106.81
0 4.8 1.56 x 96.21
2
144 12 1 x3 279.2
Row 1
25 (144) Row 1 5.76 gives Row 1 as 144 28.8 5.76 615.2256
4
Subtract the result from Row 3
25 5 1 a 1 106.8
0 4.8 1.56 a 96.21
2
0 16.8 4.76 a 3 336.0
Second step: We now divide Row 2 by –4.8 and then multiply by –16.8
Row 2
4.8 (16.8) Row 2 3.5 gives Row 2 as 0 16.8 5.46 336.735
25 5 1 a 1 106.8
0 4.8 1.56 a 96.21
2
0 0 0.7 a 3 0.735
0.735
0.7 x3 0.735 x3 1.050
0.7
x1 0.2900
x 19.70
2
x3 1.050
5
Example 2
Use Naïve Gauss Elimination to solve
10 x1 7 x2 7
3x1 2.099 x2 6 x3 3.901
5 x1 x2 5 x3 6
Solution
10 7 0 x1 7
3 2.099 6 x = 3.901
2
5 1 5 x3 6
Dividing Row 1 by 10 and multiplying by –3, that is, multiplying Row 1 by -0.3, and subtract it
from Row 2 would eliminate a21,
10 7 0 x1 7
0 0.001 6 x = 6.001
2
5 1 5 x3 6
Again dividing Row 1 by 10 and multiplying by 5, that is, multiplying Row 1 by 0.5, and
subtract it from Row 3 would eliminate a31,
10 7 0 x1 7
0 0.001 6 x = 6.001
2
0 2.5 5 x3 2.5
6
Now for the second step of forward elimination, we would use Row 2 as the pivot equation and
eliminate Row 3 – Column 2. Dividing Row 2 by –0.001 and multiplying by 2.5, that is
multiplying Row 2 by –2500, and subtracting from Row 3 gives
10 7 0 x1 7
0 0.001 6 x = 6.001
2
0 0 15005 x3 15005
Back substitution
We can now solve the above equations by back substitution. From the third equation,
15005
15005 x3 15005 x3 1
15005
0.001x2 6 x3 6.001
7 7 x2 0 x3 7 7 1 0 1
10 x1 7 x2 0 x3 7 x1 0
10 10
x1 0
x x2 1
x3 1
Note:
1. Division by zero,
2. Round-off error.
7
1-2.4 Division by zero
It is possible that division by zero may occur during forward elimination steps. For example for
the set of equations
10 x2 7 x3 7
6 x1 2.099 x2 3x3 3.901
5 x1 x2 5 x3 6
during the first forward elimination step, the coefficient of x1 is zero and hence normalization
would require division by zero.
Round-off error:
Naïve Gauss Elimination Method is prone to round-off errors. This is true when there are large
numbers of equations as errors propagate. Also, if there is subtraction of numbers from each
other, it may create large errors. See the example below.
Example 3
Remember the previous example where we used Naïve Gauss Elimination to solve
10 x1 7 x2 7
3x1 2.099 x2 6 x3 3.901
5 x1 x2 5 x3 6
using six significant digits with chopping in your calculations. Repeat the problem, but now use
five significant digits with chopping in your calculations.
Solution
10 7 0 x1 7
3 2.099 6 x = 3.901
2
5 1 5 x3 6
Dividing Row 1 by 10 and multiplying by –3, that is, multiplying Row 1 by -0.3, and subtract it
from Row 2 would eliminate a21,
8
10 7 0 x1 7
0 0.001 6 x = 6.001
2
5 1 5 x3 6
Again dividing Row 1 by 10 and multiplying by 5, that is, multiplying the Row 1 by 0.5, and
subtract it from Row 3 would eliminate a31,
10 7 0 x1 7
0 0.001 6 x = 6.001
2
0 2.5 5 x3 2.5
Now for the second step of forward elimination, we would use Row 2 as the pivoting equation
and eliminate Row 3 – Column 2. Dividing Row 2 by –0.001 and multiplying by 2.5, that is,
multiplying Row 2 by –2500, and subtract from Row 3 gives
10 7 0 x1 7
0 0.001 6 x 2 = 6.001
0 0 15005 x3 15004
Back substitution
We can now solve the above equations by back substitution. From the third equation,
15004
15005 x3 15004 x3 0.99993
15005
0.001x2 6 x3 6.001
9
Substituting the value of x3 and x2 in the first equation, 10 x1 7 x2 0 x3 7
x1 0.35
x x2 1.5
x3 0.99993
x1 0
x x2 1
x3 1
Theorem 1:
Let A be a nxn matrix. Then, if B is a matrix that results from adding or subtracting a multiple of
one row to another row, then det(B) = det(A). (The same is true for column operations also).
Theorem 2:
Let A be a nxn matrix that is upper triangular, lower triangular or diagonal, then
n
det( A) a11 * a22 * * ann aii
i 1
This implies that if we apply the forward elimination steps of Naive Gauss Elimination method,
the determinant of the matrix stays the same according the Theorem 1. Then since at the end of
10
the forward elimination steps, the resulting matrix is upper triangular, the determinant will be
given by Theorem 2.
Example 5
Find the determinant of
25 5 1
A 64 8 1
144 12 1
Solution
Remember earlier in this chapter, we conducted the steps of forward elimination of unknowns
using Naïve Gauss Elimination method on A to give
25 5 1
B 0 4.8 1.56
0 0 0.7
According to Theorem 2
Note:
If you cannot find the determinant of the matrix using Naive Gauss Elimination method due to a
division by zero problems during Naïve Gauss Elimination method, you can apply Gaussian
Elimination with Partial Pivoting. However, the determinant of the resulting upper triangular
matrix may differ by a sign. The following theorem applies in addition to the previous two to
find determinant of a square matrix.
Theorem 3:
Let A be a nxn matrix. Then, if B is a matrix that results from switching one row with another
row, then det( A) det( B) .
11
Example 6
10 7 0
A 3 2.099 6
5 1 5
Solution
Remember from that at the end of the forward elimination steps of Gaussian elimination with
partial pivoting, we obtained
10 7 0
B 0 2.5 5
0 0 6.002
Since rows were switched once during the forward elimination steps of Gaussian elimination
with partial pivoting, det A det( B) 150.05
1
Prove that det A
det A1
Proof:
AA1 I det A A det I det A det A1 1 det A
1 1
.
det A1
If A is a nxn matrix and det (A) 0, what other statements are equivalent to it?
1. A is invertible.
2. A1 exists.
3. Ax b has a unique solution.
4. Ax 0 solution is x 0
5. AA1 I A1 A .
12
SESSION 2-2: Techniques for improving Naïve Gauss Elimination Method
As seen in the example, round off errors were large when five significant digits were used as
opposed to six significant digits. So, one way of decreasing round off error would be to use
more significant digits, that is, use double or quad precision. However, this would not avoid
division by zero errors in Naïve Gauss Elimination. To avoid division by zero as well as reduce
(not eliminate) round off error, Gaussian Elimination with partial pivoting is the method of
choice.
The Gaussian elimination with partial pivoting and the Naïve Gauss elimination methods are the
same, except in the beginning of each step of forward elimination; a row switching is done based
on the following criterion. If there are n equations, then there are n 1 forward elimination
steps. At the beginning of the kth step of forward elimination, one finds the maximum of
akk , ak 1,k , , ank
Then if the maximum of these values is a pk in the pth row, k p n , then switch rows p and k.
The other steps of forward elimination are the same as Naïve Gauss elimination method. The
back substitution steps stay exactly the same as Naïve Gauss Elimination method.
Example 4
10 x1 7 x2 7
3x1 2.099 x2 6 x3 3.901
5 x1 x2 5 x3 6
using five and six significant digits with chopping in the calculations. Using five significant
digits with chopping, the solution found was
x1 0.35
x x2 1.5
x3 0.99993
x1 0
x x2 1
x3 1
13
Find the solution using Gaussian elimination with partial pivoting using five significant digits
with chopping in your calculations.
Solution
10 7 0 x1 7
3 2.099 6 x = 2.901
2
5 1 5 x3 6
Now for the first step of forward elimination, the absolute values of first column elements are
10 , 3 , 5 or 10, 3, 5.
So the largest absolute value is in the Row 1. So as per Gaussian Elimination with partial
pivoting, the switch is between Row 1 and Row 1 to give
10 7 0 x1 7
3 2.099 6 x = 3.901
2
5 1 5 x3 6
Dividing Row 1 by 10 and multiplying by –3, that is, multiplying the Row 1 by -0.3, and subtract
it from Row 2 would eliminate a21 ,
10 7 0 x1 7
0 0.001 6 x = 6.001
2
5 1 5 x3 6
Again dividing Row 1 by 10 and multiplying by 5, that is, multiplying the Row 1 by 0.5, and
subtract it from Row 3 would eliminate a31 ,
10 7 0 x1 7
0 0.001 6 x 6.001
2 =
0 2.5 5 x3 2.5
Now for the second step of forward elimination, the absolute value of the second column
elements below the Row 2 is 0.001 , 2.5 or 0.001, 2.5
14
So the largest absolute value is in Row 3. So the Row 2 is switched with the Row 3 to give
10 7 0 x1 7
0 2.5 5 x 2 = 2.5
0 0.001 6 x3 6.001
Dividing row 2 by 2.5 and multiplying by –0.001, that is multiplying by 0.001 2.5 0.0004 ,
and then subtracting from Row 3 gives
10 7 0 x1 7
0 2.5 5 x = 2 .5
2
0 0 6.002 x3 6.002
Back substitution
6.002
6.002 x3 6.002 x3 1
6.002
2.5 5 x2 2.5 5
2.5 x2 5 x3 2.5 x2 1
2.5 2.5
10 x1 7 x2 0 x2 7
7 7 x2 0 x3 7 7 1 0 1 7 7 0 0
x1 0
10 10 10 10
So the solution is
x1 0
x x2 1
x3 1
This, in fact, is the exact solution. By coincidence only, in this case, the round off error is fully
removed.
15
2-2.2 LU Decomposition
We already studied two numerical methods of finding the solution to simultaneous linear
equations – Naïve Gauss Elimination and Gaussian Elimination with Partial Pivoting. To
appreciate why LU Decomposition could be a better choice than the Gaussian Elimination
techniques in some cases, let us discuss first what LU Decomposition is about.
For any non-singular matrix A on which one can conduct Naïve Gaussian Elimination or
forward elimination steps, one can always write it as A LU
where
L = Lower triangular matrix
U = Upper triangular matrix
Then if one is solving a set of equations Ax b , it will imply that LUx b since A LU .
Multiplying both side by L1 , we have
L1LUx L1b
IUx L1b since L1L I ,
Ux L1b since IU U
Let L1b z then Lz b (1)
And Ux z (2)
So we can solve equation (1) first for z and then use equation (2) to calculate x .
n3
The computational time required to decompose the A matrix to LU form is proportional to ,
3
where n is the number of equations (size of A matrix). Then to solve the Lz b , the
n2
computational time is proportional to . Then to solve the Ux z , the computational time is
2
n2
proportional to . So the total computational time to solve a set of equations by LU
2
n3
decomposition is proportional to n2 .
3
Finding the inverse of the matrix A reduces to solving n sets of equations with the n columns of
the identity matrix as the RHS vector. For calculations of each column of the inverse of the A
16
matrix, the coefficient matrix A matrix in the set of equation Ax b does not change. So if we
use LU Decomposition method, the A LU decomposition needs to be done only once and the
use of equations (1) and (2) still needs to be done ‘n’ times.
So the total computational time required to find the inverse of a matrix using LU decomposition
n3 4n 3
is proportional to n( n 2 ) .
3 3
In comparison, if Gaussian elimination method were applied to find the inverse of a matrix, the
n3 n 2 n 4 n3
time would be proportional to n .
3 2 3 2
n 4 n 3 4n 3
For large values of n,
3 2 3
In these methods the coefficient matrix A of the given system of equation Ax b is written as a
product of a Lower triangular matrix L and an Upper triangular matrix U, such that A LU
where the elements of L (lij 0; for i j ) and the elements of U (uij 0; for i j ) that is,
min( i , j )
Now using the rules of matrix multiplication aij k 1
lik ukj , i, j 1, ,n
This gives a system of n 2 equations for the n2 n unknowns (the non-zero elements in L and
U). To make the number of unknowns and the number of equations equal one can fix the
diagonal element either in L or in U such as '1's then solve the n 2 equations for the remaining n 2
unknowns in L and U. This leads to the following algorithm:
Algorithm
17
The factorization A LU , where L lij nn
is a lower triangular and U uij nn
an upper
triangular, can be computed directly by the following algorithm (provided zero divisions are not
encountered):
Algorithm
k 1
For k 1 to n do specify lkk or ukk and compute the other such that lkk ukk akk lkmumk .
m 1
1 k 1
Compute the kth column of L using lik ik limumk
a k i n , and compute the kth
ukk m 1
1 k 1
row of U using ukj kj lkmumj
a k j n
lkk m 1
End
Note:
If forward elimination steps of Naïve Gauss elimination methods can be applied on a non-
singular matrix, then A can be decomposed into LU as
1. The elements of the U matrix are exactly the same as the coefficient matrix one obtains at
the end of the forward elimination steps in Naïve Gauss Elimination.
2. The lower triangular matrix L has 1 in its diagonal entries. The non-zero elements below
the diagonal in L are multipliers that made the corresponding entries zero in the upper
triangular matrix U during forward elimination.
18
Solving Ax=b in pure matrix Notations
Solving systems of linear equations (AX=b) using LU factorization can be quite cumbersome,
although it seem to be one of the simplest ways of finding the solution for the system, Ax=b. In
pure matrix notation, the upper triangular matrix, U, can be calculated by constructing specific
permutation matrices and elementary matrices to solve the Elimination process with both partial
and complete pivoting.
1 0 0 1 0 0
m 1 a ( j 1)
Where M 1
21 , M 0 1 with m ij known as the
0 2
0 ij
a jj
mn1 0 1 0 mn 2 1
multiplier
In solving Gaussian elimination without partial pivoting to triangularize A, the process yields the
factorization, MA U .In this case, the system Ax = b is equivalent to the triangular system
Ux Mb b where M M k 1M k 2 M k 3 ...M1
The elementary matrices M1 and M2 are called first and second Gaussian transformation matrix
respectively with M k being the k th Gaussian transformation matrix.
Generally, to solve Ax b using Naïve Gaussian elimination without partial pivoting by this
approach, a permutation matrix is introduced to perform the pivoting strategies:
First We find the factorization MA U by the triangularization algorithm using partial pivoting.
We then solve the triangular system by back substitution as follows Ux Mb b .
Example
1 0 0 1 0 0 s1 2
2
If n 3, P1 0 0 1 , M 1 m21 1 0 , then s2 M 1Ps
1 1 s2
0 1 0 m
31 0 1 s3 2
19
b1
1 1 b2 then the entries of s
(2)
If Ps are given by:
b
3
2
s1 b1
s2 2 m21b1 b3
s3 2 m31b1 b2
In the same way, to solve Ax = b Using Gaussian Elimination with Complete Pivoting, we
modify the previous construction to include another permutation matrix, Q such that when post
multiplied by A, we can perform column interchange. This results in M ( PAQ) U
Example 1
Find the LU decomposition of the matrix
25 5 1
A 64 8 1
144 12 1
Solution
1 0 0 u11 u12 u13
A LU 21 1 0 0 u22 u23
31 32 1 0 0 u33
The U matrix is the same as found at the end of the forward elimination of Naïve Gauss
elimination method, that is
Forward Elimination of Unknowns: Since there are three equations, there will be two steps of
forward elimination of unknowns.
25 5 1
64 8 1
144 12 1
First step: Divide Row 1 by 25 and then multiply it by 64 and subtract the results from Row 2
20
25 5 1
64
Row 2 ( Row 1) 0 4.8 1.56
25
144 12 1
64
Here the multiplier , m21
25
Divide Row 1 by 25 and then multiply it by 144 and subtract the results from Row 3
25 5 1
144
Row 3 ( Row 1) 0 4.8 1.56
25
0 16.8 4.76
144
Here the multiplier , m31 , hence the first Gaussian transformation matrix is given by:
25
1 0 0 1 0 0
M 1 m21 1 0 2.56 1 0 And the corresponding product is given by:
m31 0 1 5.76 0 1
1 0 0 25 5 1 25 5 1
A M 1 A 2.60 1 0 64 8 1 0 4.8 1.56 (by a single multiplication)
(1)
5.76 0 1 144 12 1 0 16.8 4.76
Second step: We now divide Row 2 by -4.8 and then multiply by -16.8 and subtract the results
from Row 3
25 5 1 25 5 1
16.8
Row 3 ( Row 2) 0 4.8 1.56 which produces U 0 4.8 1.56
4.8
0 0 0.7 0 0 0.7
16.8
Here the multiplier, m32 , hence the 2nd Gaussian transformation matrix is given by:
4.8
1 0 0 1 0 0
M 2 0 1 0 0 1 0 And the corresponding product is given by:
0 m32 1 0 3.5 1
1 0 0 25 5 1 25 5 1
A (2)
M 2 A 0
(1)
1 0 0 4.8 1.56 0 4.8 1.56 U
(by a single multiplication)
21
To find 21 and 31 , what multiplier was used to make the a 21 and a 31 elements zero in the first
step of forward elimination of Naïve Gauss Elimination Method It was
64
21 m21 2.56
25
144
31 m31 5.76
25
To find 32 , what multiplier was used to make a 32 element zero. Remember a 32 element was
made zero in the second step of forward elimination. The A matrix at the beginning of the
second step of forward elimination was
25 5 1
0 4.8 1.56
0 16.8 4.76
So
16.8
m32 3.5
4.8
32
Hence
1 0 0 1 0 0
L m21 1 0 2.56 1 0
m31 m32 1 5.76 3.5 1
Confirm LU A .
1 0 0 25 5 1 25 5 1
LU 2.56 1 0 0 4.8 1.56 64 8 1
5.76 3.5 1 0 0 0.7 144 12 1
Example 2
Use LU decomposition method to solve the following linear system of equations.
25 5 1 x1 106.8
64 8 1 x 177.2
2
144 12 1 x3 279.2
22
Solution
Recall that Ax b and if A LU then first solving Lz b and then Ux z gives the solution
vector x .
1 0 0 25 5 1
A LU 2.56 1 0 0 4.8 1.56
5.76 3.5 1 0 0 0.7
1 0 0 z1 106.8
2.56 1 0 z 177.2
2
5.76 3.5 1 z 3 279.2
to give
z1 106.8
2.56 z1 z2 177.2
5.76 z1 3.5 z2 z3 279.2
z1 106.8
z2 177.2 2.56 z1 177.2 2.56(106.8) 96.2
z3 279.2 5.76 z1 3.5 z2 279.2 5.76(106.8) 3.5(96.21) 0.735
Hence
z1 106.8
z z2 96.21
z3 0.735
This matrix is same as the right hand side obtained at the end of the forward elimination steps of
Naïve Gauss elimination method. Is this a coincidence?
23
25 5 1 x1 106.8
0 4.8 1.56 x -96.21
2
0 0 0.7 x3 0.735
25 x1 5 x2 x3 106.8
4.8 x2 1.56 x3 96.21
0.7 x3 0.735
0.735
From the third equation 0.7 x3 0.735 x3 1.050
0.7
106.8 5 x2 x3
25 x1 5 x2 x3 106.8 x1
25
106.8 5 19.70 1.050
0.2900
25
x1 0.2900
x 19.70
2
x3 1.050
Example 2.2
Solve
0 1 1 2
Ax b with A 1 2 3 and b 6
1 1 1 3
(a) using partial pivoting and (b) using complete pivoting.
Solution:
(a) Partial pivoting:
We compute U as follows:
24
Step 1:
0 1 0 1 2 3 1 0 0
P1 1 0 0 ; P1 A 0 1 1 ;
M 1 0 1 0 ;
0 0 1 1 1 1 1 0 1
1 2 3
A M 1 P1 A 0 1 1 ;
(1)
0 1 2
Step 2 :
1 0 0 1 2 3 1 0 0
P2 0 1 0 ; P2 A 0 1 1 ; M 2 0 1 0 ;
(1)
0 0 1 0 1 2 0 1 1
1 2 3
U A(2) M 2 P2 A M 2 P2 M 1P1 A 0 1 1
(1)
0 0 1
Note : Defining P P2 P1 and L P( M 2 P2 M 1 P1 ) 1 , we have PA LU .
We compute b as follows:
Step1:
0 1 0 6 1 0 0 6
P1 1 0 0 ;
1 2 ;
Pb M 1 0 1 0 ;
1 2 ;
M 1Pb
0 0 1 3 1 0 1 3
Step 2 :
1 0 0 6 1 0 0 6
P2 0 1 0 ; P2 M1 Pb
1
2 ; M 2 0 1 0 ; b M 2 P2 M 1Pb
1 2 ;
0 0 1 3 0 1 1 1
1 2 3 x1 6
Ux b 0 1 1 x 2 and x x x 1
2 1 2 3
25
(b) Complete pivoting: We compute U as follows:
Step 1:
0 1 0 0 0 1 3 2 1 1 0 0
P1 1 0 0 ; Q1 0 1 0 ; P1 AQ1 1 1 0 ; M 1 13 1 0 ;
0 0 1 1 0 0 1 1 1 1 0 1
3
1 2 3
A M 1 P1 AQ1 0 3 13
(1) 1
0 1 2
3 3
Step 2 :
1 0 0 1 0 0 3 1 2 1 0 0
P2 0 0 1 ; Q2 0 0 1 ;
P2 A Q2 0 3 3 ;
(1) 2 1
M2 0 1 0;
0 1 0 0 1 0
1 1
0 3 3 0 2 1
1
3 1 2
U A M 2 P2 A Q2 M 2 P2 M 1P1 AQ1Q2 0 23 13
(2) (1)
1
0 0 2
Note : Defining P P2 P1 , Q Q1Q2 and L P ( M 2 P2 M 1P1 ) 1 , we have PAQ LU .
We compute b as follows:
Step1:
0 1 0 6 1 0 0 6
1
P1 1 0 0 ; 1 2 ;
Pb M 1 3 1 0 ; M 1 Pb
1 0
0 0 1 3 1 0 1 1
3
Step 2 :
1 0 0 6 1 0 0 6
P2 0 0 1 ;
1 1 ;
P2 M 1 Pb M 2 0 1 0 ; M 1 Pb
1 0 ;
0 1 0 0 1 1
0 2 1
6
b M 2 P2 M 1 Pb 1
1
1
2
The solution of the system
3 1 2 y1 6
Uy b 0 23 13 y2 1
0 0 1 y 1
2 3 2
is y1 y2 y3 1 . Because xk , k 1, 2,3 is simply the rearrangement of yk , we have
x1 x2 x3 1 .
26
2-2.4 Finding the inverse of a square matrix using LU Decomposition
A matrix B is the inverse of A if AB I BA . First assume that the first column of B (the
inverse of A is b11 b21 bn1 then from the above definition of inverse and definition of
T
matrix multiplication.
b11 1
b 0
A 21
bn1 0
b12 0
b 1
A 22
bn 2 0
Similarly, all columns of B can be found by solving n different sets of equations with the column
of the right hand sides being the n columns of the identity matrix.
Example 3
Use LU decomposition to find the inverse of
25 5 1
A 64 8 1
144 12 1
Solution
Knowing that
1 0 0 25 5 1
A LU 2.56 1 0 0 -4.8 -1.56
5.76 3.5 1 0 0 0.7
25 5 1 b11 1
64 8 1 b 0
21
144 12 1 b31 0
27
First solve Lz c , that is
1 0 0 z1 1
2.56 1 0 z 0
2
5.76 3.5 1 z 3 0
to give
z1 1
2.56 z1 z2 0
5.76 z1 3.5 z2 z3 0
z1 1
z 2 0-2.56z1 0 2.56 1 256
z3 0 5.76 z1 3.5 z2 0 5.76 1 3.5 2.56 3.2
Hence
z1 1
z z2 2.56
z3 3.2
3.2
b31 4.571
0.7
28
2.56 1.560b31 2.56 1.560(4.571)
b21 0.9524
4.8 4.8
b11 0.04762
b 0.9524
21
b31 4.571
Similarly by solving
and solving
Hence
Exercise
29
SESSION 3-2: Iterative Method
an1 x1 an 2 x2 an 3 x3 ann xn bn
If the diagonal elements are non-zero, each equation is rewritten for the corresponding unknown,
that is, the first equation is rewritten with x1 on the left hand side and the second equation is
rewritten with x 2 on the left hand side and so on as follows:
1
x1 b1 a12 x2 a13 x3 a1n xn
a11
1
x2 b2 a21 x1 a23 x3 a2 n xn
a22
xn 1
1
an 1,n 1
b
n 1 an 1,1 x1 an 1,2 x2 an 1,n xn
xn
1
ann
bn an1 x1 an 2 x2 an ,n 1 xn 1
30
1 n
x1 1 a1 j x j
b
a11 j 1, j 1
1 n
x2 2 a2 j x j
b
a22 j 1, j 2
1 n
xn 1 n 1
an 1,n 1
b an 1 j x j
j 1, j n 1
1 n
xn bn anj x j
ann j 1, j n
1 n
Hence for any row i, xi i aij x j , i 1, 2,
b , n.
aii j 1, j i
1 n
( k 1)
By assuming an initial guess for the xi ’s, one uses xi( k ) bi aij x j , i 1, 2, , n. to
aii j 1, j i
calculate the new values for the xi ’s. At the end of each iteration, one calculates the absolute
xinew xiold
relative approximate error for each xi as a i 100 , where xinew is the recently
xinew
obtained value of xi , and xiold is the previous value of xi .
When the absolute relative approximate error for each xi is less than the pre-specified tolerance,
the iterations are stopped.
Example 1
31
Use Jacobi Method to solve Ax b , where
25 5 1 106.8
A 64 8 1 , b 177.2
144 12 1 279.2
Solution
Iteration #1
Given the initial guess of the solution vector as
x1(0) 1
(0)
x2 2
x3(0) 5
we get
32
3.6720 1.0000
a 1 100 72.76%
3.6720
13.525 2.0000
a 2 100 85.21%
13.525
68.8 5.0000
a 3 100 108.53%
68.8
At the end of the first iteration, the guess of the solution vector is
x1(1) 3.6720
(1)
x2 13.525
(1)
x3 68.8
Iteration #2
The estimate of the solution vector at the end of iteration #1 is
x1(1) 3.6720
(1)
x2 13.525
(1)
x3 68.8
Now we get
33
1.185 3.6720
a 1 100 428.37%
1.185
15.862 13.525
a 2 100 185.27%
15.862
576.032 68.8
a 3 100 111.94%
576.032
x1(2) 1.185
(2)
x2 15.862
x3(2) 576.032
Example 2
Given the system of equations;
12 x1 3x2 5 x3 1
x1 5 x2 3 x3 28
3x1 7 x2 13x3 76
Solution
Rewriting the equations, we get
34
x1(0) 1
(0)
x2 0
x3(0) 1
Iteration #1:
1 3 0 5 1
x1(1) 0.50000
12
28 1 3 1
x2(1) 4.80000
5
76 3 1 7 0
x3(1) 5.6154
13
0.50000 1.0000
a 1 100 67.662%
0.50000
4.8000 0
a 2 100 100%
4.8000
5.6154 1.0000
a 3 100 82.19%
5.6154
Iteration #2:
1 3 4.8000 5 5.6154
x1(2) 14.677
12
28 0.5000 3 5.6154
x2(2) 2.13076
5
76 3 0.5000 7 4.800
x3(2) 3.14615
13
35
14.677 0.50000
a 1 100 96.59%
14.677
2.13076 4.8000
a 2 100 125.27%
2.13076
3.14615 5.6154
a 3 100 78.484%
3.14615
an1 x1 an 2 x2 an 3 x3 ann xn bn
is rewritten as
a11 x1 b1 a12 x2 a13 x3 a1n xn
a21 x1 a22 x2 b2 a23 x3 a2 n xn
Again in the matrix notation, the coefficient matrix A of the system Ax b , is split into
A L D U where D has the diagonal elements of A and L & U respectively have the lower
diagonal and upper diagonal elements of A then the Gauss-Seidel scheme can be written as
( L D) x Ux b
( L D) x ( k ) Ux ( k 1) b
giving x( k ) ( L D)1Ux( k 1) ( L D)1 b .
i.e., the Gauss-Seidel iterative matrix and the corresponding vector are given as
TGS ( L D)1U and cGS ( L D)1 b respectively.
36
Example 1
25 5 1 106.8
A 64 8 1 , b 177.2
144 12 1 279.2
Solution
Iteration #1
x1 1
x 2
2
x3 5
we get
37
3.6720 1.0000
a 1 100 72.76%
3.6720
7.8510 2.0000
a 2 100 125.47%
7.8510
155.36 5.0000
a 3 100 103.22%
155.36
At the end of the first iteration, the guess of the solution vector is
x1(1) 3.6720
(1)
x2 7.8510
x3(1) 155.36
Iteration #2
x1(1) 3.6720
(1)
x2 7.8510
x3(1) 155.36
Now we get
38
12.056 3.6720
a 1 100 69.542%
12.056
54.882 7.8510
a 2 100 85.695%
54.882
798.34 155.36
a 3 100 80.54%
798.34
x1(2) 12.056
(2)
x2 54.882
x3(2) 798.34
Conducting more iterations gives the following values for the solution vector and the
corresponding absolute relative approximate errors.
As seen in the above table, the solution is not converging to the true solution of
x1 0.29048, x2 19.690, x3 1.0858
If a system of equations has a coefficient matrix that is not diagonally dominant, it may or may
not converge. Fortunately, many physical systems that result in simultaneous linear equations
have diagonally dominant coefficient matrix, which then assures convergence for iterative
methods such as Gauss-Seidel method of solving simultaneous linear equations.
39
Example 2
12 x1 3x2 5 x3 1
x1 5 x2 3 x3 28
3x1 7 x2 13x3 76
Solution
12 3 5
A 1 5 3
3 7 13
is diagonally dominant as
and the inequality is strictly greater than for at least one row. Hence the solution should
converge using Gauss-Seidel method.
40
x1(0) 1
(0)
x2 0
x3(0) 1
Iteration #1:
1 3 0 5 1
x1(1) 0.50000
12
28 0.5 3 1
x2(1) 4.90000
5
76 3 0.50000 7 4.9000
x3(1) 3.0923
13
0.50000 1.0000
a 1 100 67.662%
0.50000
4.9000 0
a 2 100 100%
4.9000
3.0923 1.0000
a 3 100 67.662%
3.0923
Iteration #2:
1 3 4.9000 5 3.0923
x1(2) 0.14679
12
28 0.14679 3 3.0923
x2(2) 3.7153
5
76 3 0.14679 7 4.900
x3(2) 3.8118
13
41
0.14679 0.50000
a 1 100 240.62%
0.14679
3.7153 4.9000
a 2 100 31.887%
3.7153
3.8118 3.0923
a 3 100 18.876%
3.8118
The maximum absolute relative approximate error is 240.62%. This is greater than the value of
67.612% we obtained in the first iteration. Is the solution diverging? No, as you conduct more
iterations, the solution converges as follows.
x1 1
x 3
2
x3 4
Example 3
3x1 7 x2 13x3 76
x1 5 x2 3x3 28
12 x1 3x2 5 x3 1
find the solution using Gauss-Seidal method. Use x1 , x2 , x3 1 0 1 as the initial guess.
T T
Solution
42
Rewriting the equations, we get
x1(0) 1
(0)
x2 0
x3(0) 1
the next six iterative values are given in the table below
You can see that this solution is not converging and the coefficient matrix is not diagonally
dominant. The coefficient matrix
3 7 13
A 1 5 3
12 3 5
43
However, it is the same set of equations as the previous example and that converged. The only
difference is that we exchanged first and the third equation with each other and that made the
coefficient matrix not diagonally dominant.
So it is possible that a system of equations can be made diagonally dominant if one exchanges
the equations with each other. But it is not possible for all cases. For example, the following set
of equations.
x1 x2 x3 3
2 x1 3x2 4 x3 9
x1 7 x2 x3 9
Example 4
Find an approximation to the solution of Ax b by performing two iterations of the Gauss-
4 2 1 1
Seidel method where A , b and x (0) .
1 1 2 1
Solution
Using xi k
1
aii
i 1 2
bi j 1 aij xjk j i 1 aij xjk 1 , i 1, 2, k 1, 2, , we have
4 0 0 2
D , Aoff
0 1 1 0
k 1
1 1 1 1 4 9
x1(1) 1 [0, 2] , x2(1) 1 2 1, 0
4 1 4 1 4
1 4
x1
9 4
k 2
1 1 4 7 8
x1(2) 1 [0, 2] 7 8, x2 1 2 [1, 0]
(2)
23 8
4 9 4 9 4
7 8
x2
23 8
44
3-1.3 Successive Over-Relaxation Method
If the Gauss-Seidel iteration equations (*) is written as
i 1
1n
i ij i
xi( k ) xi( k 1)
aij xi( k 1) , i 1, , n
(k )
b a x
j 1 aii
j i
Then multiplying the second term of the right hand side of the above by , we have
i 1
n
i ij i
xi( k ) xi( k 1)
aij xi( k 1) , i 1, , n
(k )
b a x
aii j 1 j i
(**)
i 1 n
xi( k ) bi aij xi( k ) aij xi( k 1) (1 ) xi( k 1) , i 1, , n
aii j 1 j i 1
which gives the SOR iteration equations where the factor is called the acceleration parameter
or relaxation factor, which generally lies in the range 0 2 . The determination of the
optimum value of for maximum rate of convergence is again a matter of discussion and is not
considered. When 1 gives the Gauss-Seidel iteration, 0 1 we have under relaxation
and 1 2 we have over relaxation.
From (**), we can write the matrix notation for the SOR method as follows:
x ( k ) x ( k 1) D 1 Lx ( k ) Ux ( k 1) b Dx ( k 1)
I D L x 1 (k )
D 1 U D x ( k 1) x ( k 1) D 1b
D L x( k ) U D x( k 1) Dx( k 1) b
Therefore,
x k D L
1
1 D U x k 1
D L b
1
i.e., the SOR iterative matrix and the corresponding vector are given as
TSOR D L
1
1 D U and c SOR D L b respectively.
1
Example 1
Find an approximation to the solution of Ax b by performing two iterations of the SOR
4 2 1 1
method where A , b and x (0) with 1.2 .
1 1 2 1
Solution
Using xi k
aii
b
i
i 1
j 1 ij
2
a xjk - j i 1 aij xjk 1 (1 ) xi k 1 , i 1, 2, k 1, 2, , we have
45
4 0 0 2
D , Aoff
0 1 1 0
k 1
1.2 1 0.5
x1(1) 1 [0, 2] 0.2 0,5, x2 1.2 2 1, 0 0.2 2.8
(1)
4 1 1
0.5
x1
2.8
k 2
1.2 0.5 1.28
x1(2) 1 [0, 2] 0.1 1.28, x2 1.2 2 [1, 0]
(2)
0.56 3.376
4 2.8 2.8
1.28
x2
3.376
Similarly, e( k 1) x x( k 1) . Therefore e( k 1) Te( k ) or e( k ) Te( k 1) T 2e( k 2) T k e(0) .
46
n
Similarly e( k ) cr rk r
r 1
Therefore e( k ) will tend to the null vector as k tends to infinity, for arbitrary e(0) , if and only if
r 1 for all r. In other words the iteration will converge for arbitrary x (0) if and only if, the
spectral radius (T ) of T is less than unity.
As a corollary to this result a sufficient condition for convergence is that T 1 . To prove this
we have that T r r r . Hence
T r r r r r
r r T r
But for any matrix norm that is compatible with a vector norm r , T r T r .
It follows from this that a sufficient condition for convergence is that T 1 . It is not a
necessary condition because the norm of T can exceed one even when (T ) 1 .
47
SYSTEM OF NON-LINEAR EQUATIONS
Introduction
Learning Objectives
content
48
SESSION 1-3: Fixed Points for Functions of Several Variables
The general of a system of nonlinear equations is
f1 ( x1 , x2 , , xn ) 0
f 2 ( x1 , x2 , , xn ) 0
f n ( x1 , x2 , , xn ) 0
where each function f i maps n-dimensional space, R n , into the real line R. The above system
can be defined alternatively by defining the function F (x) 0 , where F : Rn Rn ,
x ( x1 , x2 , , xn ) and F ( x1 , x2 , , xn ) f1 ( x1 , x2 , , xn ), f 2 ( x1 , x2 , , xn ), , f n ( x1, x2 , , xn ) .
xn( k ) g n x1( k 1) , x2( k 1) , , xn( k 1)
The following theorem provides conditions for the iterative process to converge.
Theorem
49
component function g i , then the sequence x ( k ) defined by for each i = 1,
k 0
2, 3,... converges to the unique fixed point pD , for any x (0) in D , and
Kj
x( j) p x (1) x (0) .
1 K
Example 1
3x1 cos( x2 x3 ) 12 0
x 81( x2 0.1) sin x3 1.06 0
2
1
2
e x1x2 20 x3 1033 0
f1 ( x1 , x2 , , xn ) 3x1 cos( x2 x3 ) 12
f 2 ( x1 , x2 , , xn ) x12 81( x2 0.1) 2 sin x3 1.06
f3 ( x1 , x2 , , xn ) e x1x2 20 x3 1033
F ( x1 , x2 , , xn ) f1 ( x1 , x2 , , xn ), f 2 ( x1 , x2 , , xn ), , f n ( x1 , x2 , , xn )
3 x1 cos( x2 x3 ) 12 , x12 81( x2 0.1) 2 sin x3 1.06, e x1x2 20 x3 1033
Example 2
3x1 cos( x2 x3 ) 12 0
x12 81( x2 0.1) 2 sin x3 1.06 0
e x1x2 20 x3 1033 0
If the ith equation is solved for xi , the system can be changed into the fixed point problem
x1 13 cos( x2 x3 ) 16 ,
x2 19 x12 sin x3 1.06 0.1,
x3 201 e x1x2 1060
3
.
50
Let G : R3 R3 be defined by G(x) g1 (x), g2 (x), g3 (x) where
g1 ( x1 , x2 , x3 ) 13 cos( x2 x3 ) 16 ,
g 2 ( x1 , x2 , x3 ) 19 x12 sin x3 1.06 0.1,
g3 ( x1 , x2 , x3 ) 201 e x1x2 1060
3
.
g1 ( x1 , x2 , x3 ) 13 cos( x2 x3 ) 16 12 ,
g 2 ( x1 , x2 , x3 ) 1
9 x12 sin x3 1.06 0.1
1
9 1 sin1 1.06 0.1 0.90,
g3 ( x1 , x2 , x3 ) 1
20 e x1x2 1060
3
1
20 e 1060
3
0.61
so 1 gi ( x1 , x2 , x3 ) 1, for each i 1, 2,3. Thus, G(x) D whenever x D .
g 2 x1 1 g 2
0.238, 0,
x1 9 x sin x 1.06 9 0.218
2 x2
1 3
g 2 cos x3 1
0.119,
x3 18 x 2 sin x 1.06 18 0.218
1 3
g3 x g3 x
2 e x1x2 201 e 0.14, 1 e x1x2
x1 20 x2 20
Since the partial derivatives are bounded on D, the above Theorem implies that these functions
are continuous on D. Consequently, G is continuous on D. Moreover, for every x D
gi (x)
0.281 for each i 1, 2,3 and j 1, 2,3, and the condition in the second part of
x j
Theorem 9.7 holds for K 0.843 . It can be shown that for each i = 1, 2, 3 and j = 1,
2, 3 is continuous on D. Consequently, G has a unique fixed point on D and the nonlinear system
has a solution in D.
51
Example 3
3x1 cos( x2 x3 ) 12 0
x12 81( x2 0.1) 2 sin x3 1.06 0
e x1x2 20 x3 1033 0
Solution
If the ith equation is solved for xi , the system can be changed into the fixed point problem as
x1 13 cos( x2 x3 ) 16 ,
x2 19 x12 sin x3 1.06 0.1,
x3 201 e x1x2 1060
3
.
x1( k ) 13 cos x2( k 1) x3( k 1) 16 ,
x
2
( k 1)
x2( k ) 1
9 1 sin x3( k 1) 1.06 0.1,
( k 1) ( k 1)
x3( k ) 201 e x1 x2
1060
3
.
x ( k ) x ( k 1) 105
52
(0.843)5
x (5) p 0.423 1.15
1 0.843
x (3) 0.50000000,1.234 105 , 0.52359814
(0.843)5
x (5) p (1.20 105 ) 5.5 105
1 0.843
x (5) p 2 108
x1( k ) 13 cos x2( k 1) x3( k 1) 16 ,
x
2
x2( k ) 1
9
(k )
1 sin x3( k 1) 1.06 0.1,
x3( k ) 201 e x1
(k ) (k )
x2
1060
3
.
53
where each of the entries aij (x) is a function from R n R . The procedure requires that A(x)
be found so that G(x) x A(x)1 F (x) gives quadratic convergence to the solution F (x) 0 ,
provided that A(x) is non-singular at the fixed point.
Theorem
n
Since G(x) x A(x)1 F (x) , gi (x) xi bij (x) f j (x) ;
j 1
n
f j b
1 bij (x) (x) ij (x) f j (x) , if i k ,
gi (x) j 1 xk xk
So n
xk f b
bij (x)
j
(x) ij (x) f j (x) , if i k.
j 1 xk xk
n f j
0 1 bij (p) (p)
j 1 xk
n f j
so b (p) x
j 1
ij (p) 1
k
n f j
0 bij (p) (p)
j 1 xk
n f j
So b (p) x
j 1
ij (p) 0
k
54
f1 (x) f1 (x) f1 (x)
x x2 xn
1
f 2 (x) f 2 (x) f 2 (x)
J (x) x1 x2 xn
f n (x) f n (x) f n (x)
x x2 xn
1
A(p)1 J (p) I
so J (p) A(p)
Example 1
3x1 cos( x2 x3 ) 12 0
x12 81( x2 0.1) 2 sin x3 1.06 0
e x1x2 20 x3 1033 0
Solution
3 x3 sin x2 x3 x2 sin x2 x3
J ( x1 , x2 , x3 ) 2 x1 162( x2 0.1) cos x3
x1 x2
x2e x1e x1x2 20
and
55
where
h1( k 1)
h( k 1) J x ( k 1) , x ( k 1) , x ( k 1) 1 F x ( k 1) , x ( k 1) , x ( k 1) .
2( k 1) 1 2 3 1 2 3
h3
3 x3( k 1) sin x2( k 1) x3( k 1) x2 sin x2( k 1) x3( k 1) h1( k 1)
( k 1) ( k 1)
2 x1 162( x2( k 1) 0.1) cos x3( k 1) h2( k 1)
x ( k 1) e x1( k 1) x2( k 1) x ( k 1) e x1( k 1) x2( k 1)
2 1 20 h3
3x1( k 1) cos( x2( k 1) x3( k 1) ) 12
( k 1) 2
which is equal to x1 81( x2( k 1) 0.1) 2 sin x3( k 1) 1.06
x1( k 1) x2( k 1)
e 20 x3( k 1) 1033
must be solved. The results obtained using the above iterative procedure is as shown below
Examples
x 2 10 x y 2 8
1. The nonlinear system F( x, y ) 2 0 can be transformed into the fixed point
xy x 10 y 8
x 10
x 2 y 2 8
problem G( x, y) xy 2 x 8
y 10
56
Solution
(a)
i x y g1(x,y) g2(x,y) Tol
0 0 0 0.8 0.8
1 0.8 0.8 0.928 0.9312 0.8
2 0.928 0.9312 0.972832 0.97327 0.1312
3 0.972832 0.97327 0.989366 0.989435 0.044832
4 0.989366 0.989435 0.995783 0.995794 0.016534
5 0.995783 0.995794 0.998319 0.998321 0.006417
6 0.998319 0.998321 0.999328 0.999329 0.002536
7 0.999328 0.999329 0.999732 0.999732 0.00101
8 0.999732 0.999732 0.999893 0.999893 0.000403
9 0.999893 0.999893 0.999957 0.999957 0.000161
10 0.999957 0.999957 0.999983 0.999983 6.44E-05
11 0.999983 0.999983 0.999993 0.999993 2.58E-05
12 0.999993 0.999993 0.999997 0.999997 1.03E-05
13 0.999997 0.999997 0.999999 0.999999 4.12E-06
14 0.999999 0.999999 1 1 1.65E-06
(b)
i x y g1(x,y) g2(x,y) Tol
0 0 0 0.8 0.88
1 0.8 0.88 0.94144 0.967049 0.88
2 0.94144 0.967049 0.982149 0.990064 0.14144
3 0.982149 0.990064 0.994484 0.99693 0.040709
4 0.994484 0.99693 0.998287 0.999045 0.012335
5 0.998287 0.999045 0.999467 0.999703 0.003803
6 0.999467 0.999703 0.999834 0.999907 0.00118
7 0.999834 0.999907 0.999948 0.999971 0.000367
8 0.999948 0.999971 0.999984 0.999991 0.000114
9 0.999984 0.999991 0.999995 0.999997 3.56E-05
10 0.999995 0.999997 0.999998 0.999999 1.11E-05
11 0.999998 0.999999 1 1 3.46E-06
(c)
From (a) and (b) it is seen that Gauss-Seidel Method accelerate convergence.
e xy 20 z 1033 0
57
to a fixed point problem and use both functional iteration and the Gauss-Seidel variant of
functional iteration to approximate the root to within 105 in the l norm, starting the
12 , 0, 6
T
initial estimate x0 y0 0.1 and z0 0.1 . [Note the exact root is ]
Solution
58
Using the Gauss-Seidel variant of functional iteration we have the following table:
3. Starting with the initial guess x0 y0 1.0 , use fixed point (functional iteration to
approximate the solution to the system 2 x2 y 2 4.32, x2 y 2 0 by performing 5
iterations.
4. Consider the nonlinear system
2 x xy 1 0
2 y xy 1 0
which has a unique root x (1, 1)T . Starting with the initial estimate x0 y0 0 ,
compare the methods of functional iteration, Gauss-Seidel Newton when approximating
the root of this system (perform 5 iterations in each case).
Solution
Using the Newton’s iterative method x( k ) x( k 1) J 1 ( x( k 1) ) F ( x( k 1) ), for k 1, with
x(0) x0 , y0 2, 14 , we have
1
2 2 1 0.25
x (1) x (0) J 1 ( x (0) ) F ( x (0) )
0.25 4 2 0.25
2 1 2 1 0.25 2 1 0.75 1.90625
0.25 8 4 2 0.25 0.25 8 0.50 0.3125
1
1 1.90625 1.8125 1 0.00879
x (2)
x J ( x )F ( x )
(1) (1)
(1)
0.3125 3.8125 2.5 1.70312
1.90625 1 2.5 1 0.00879 2.10773
0.3125 8.34375 3.8125 1.8125 1.70312 0.68232
59
6. Use Newton’s Method to approximate the two solutions of the nonlinear system
ye x 2, x2 y 2 4 by computing 2 iterations for each of the given initial estimates
(a) x0 , y0 0.6, 3.7
(b) x0 , y0 1.9, 0.4
7. Use Newton’s Method to approximate the solution of the nonlinear system
x 2 y 2 0.6 y 0.16 0
x 2 y 2 x 1.6 y 0
Using the more accurate initial estimate of x0 , y0 0.3,0.1 , repeat the process using
the modified Newton’s method whereby the Jacobian is evaluated and held constant for
subsequent iterations. Compare the two results.
8. Use the modified Newton’s method (i.e., by evaluating the Jacobian and keeping at a
constant value throughout) to find the root of the system e x y 0, cosh( y) x 72
starting with the initial estimate x 2.4, y 0.1 computing two iterations.
60
PART II
2 Interpolation
2.1 Problem Statement and Applications
x0 f0
x1 f1
x2 f2
.. ..
. .
xk fk
.. ..
. .
xn fn
In the above table, fk , k = 0, · · · , n are assumed to be the values of a certain function f (x), evaluated
at xk , k = 0, · · · , n in an interval containing these points. Note that only the functional values are
known, not the function f (x) itself. The problem is to find fu corresponding to a nontabulated inter-
mediate value x = u.
Such a problem is called an Interpolation Problem. The numbers x0 , x1 , · · · , xn are called the nodes.
Interpolation Problem
The Interpolation problem is also a classical problem and dates back to the time of Newton and Kepler,
who needed to solve such a problem in analyzing data on the positions of stars and planets. It is also of
61
2.2 Existence and Uniqueness
It is well-known that a continuous function f (x) on [a, b] can be approximated as close as possible by means
of a polynomial. Specifically, for each > 0, there exists a polynomial P (x) such that |f (x) − P (x)| < for
all x in [a, b]. This is a classical result, known as Weierstrass Approximation Theorem.
Knowing that fk , k = 0, · · · , n are the values of a certain function at xk , the most obvious thing then
to do is to construct a polynomial Pn (x) of degree at most n that passes through the (n + 1) points:
Indeed, if the nodes x0 , x1 , ..., xn are assumed to be distinct, then such a polynomial always
Because x0 , x1 , · · · , xn are distinct, it can be shown [Exercise] that the matrix of the above system is
nonsingular. Thus, the linear system for the unknowns a0 , a1 , · · · , an has a unique solution, in view of the
62
This means that Pn (x) exists and is unique.
Once we know that the interpolating polynomial exists and is unique, the problem then becomes how to
construct an interpolating polynomial; that is, how to construct a polynomial Pn (x) of degree at most n,
such that
Pn (xi ) = fi , i = 0, 1, · · · , n.
It is natural to obtain the polynomial by solving the linear system (3.1) in the previous section. Unfortunately,
the matrix of this linear system, known as the Vandermonde Matrix, is usually highly ill-conditioned,
and the solution of such an ill-conditioned system, even by the use of a stable method, may not
be accurate. There are, however, several other ways to construct such a polynomial, that do not require
Suppose n = 1, that is, suppose that we have only two points (x0 , f0 ), (x1 , f1 ), then it is easy to see that
P1 (x0 ) = f0 , P1 (x1 ) = f1 .
63
For convenience, we shall write the polynomial P1 (x) in the form
x − x0 x − x0
where, L1 (x) = , and L1 (x) = .
x1 − x0 x1 − x0
Note that both the polynomials L0 (x) and L1 (x) are polynomials of degree 1.
To generate polynomials of higher degrees, let’s define the set of polynomials {Lk (x)} recursively, as follows:
is an interpolating polynomial.
(x − x1 ) · · · (x − xn )
L0 (x) =
(x0 − x1 ) · · · (x0 − xn )
(x − x0 )(x − x2 ) · · · (x − xn )
L1 (x) =
(x1 − x0 )(x1 − x2 ) · · · (x1 − xn )
..
.
(x − x0 )(x − x1 )(x − x2 ) · · · (x − xn−1 )
Ln (x) =
(xn − x0 )(xn − x1 )(xn − x2 ) · · · (xn − xn−1 )
Also, note that
In general
Thus
64
Pn (x0 ) = L0 (x0 )f0 + L1 (x0 )f1 + · · · + Ln (x0 )fn = f0
The polynomial Pn (x) defined by (3.3) is known as the Lagrange Interpolating Polynomial.
0 7
1 13
2 21
4 43
(x − 1)(x − 2)(x − 4)
L0 (x) =
(−1)(−2)(−4)
(x − 0)(x − 2)(x − 4)
L1 (x) =
1 · (−1)(−3)
(x − 0)(x − 1)(x − 4)
L2 (x) =
2 · 1 · (−2)
(x − 0)(x − 1)(x − 2)
L3 (x) =
4·3·2
Thus, P3 (3) = 7L0 (3) + 13L1 (3) + 21L2(3) + 43L3 (3) = 31.
1 3 1
Now, L0 (3) = , L1 (3) = −1, L2 (3) = , L3 (3) = .
4 2 4
So, P3 (3) = 7L0 (3) + 13L1 (3) + 21L2 (3) + 43L3 (3) = 31.
Verify: Note that f (x) in this case is f (x) = x2 + 5x + 7, and the exact value of f (x) at x = 3 is 31.
65
i xi f (xi )
1
0 2
2
1
1 2.5
2.5
1
2 4
4
We want to find f (3).
(x − x1 )(x − x2 ) (x − 2.5)(x − 4)
L0 (x) = = = (x − 2.5)(x − 4)
(x0 − x1 )(x0 − x2 ) (−0.5)(−2)
(x − x0 )(x − x2 ) (x − 2)(x − 4) 1
L1 (x) = = =− (x − 2)(x − 4)
(x1 − x0 )(x1 − x2 ) (0.5)(−1.5) 0.75
(x − x1 )(x − x0 ) 1
L2 (x) = = (x − 2.5)(x − 2)
(x2 − x1 )(x2 − x0 ) 3
1 1 1
L0 (x) +
P2 (x) = f (x0 )L0 (x) + f (x1 )L1 (x) + f (x2 )L2 (x) = L1 (x) + L2 (x)
2 2.5 4
1 1 1 1 1 1 1 .5
P2 (3) = L0 (3) + L1 (3) + L2 (3) = (−0.5) + + = 0.3250
2 2.5 4 2 2.5 0.75 4 3
1
Verify: (The value of f (x) at x = 3 is 3 = 0.3333).
If f (x) is approximated by an interpolating polynomial Pn (x), we would like to obtain an expression for the
Note that, since Pn (xi ) = f (xi ), E(xi ) = 0, i = 0, 1, 2, · · · , n), that is, there are no errors of interpo-
Theorem 2.2 (Interpolation-Error Theorem) Let Pn (x) be the interpolating polynomial that interpo-
lates at (n + 1) distinct numbers in [a, b], and let f (x) be (n + 1) times continuously differentiable on [a, b].
Then for every x̄ in [a, b], there exists a number ξ = ξ(x̄) (depending on x̄) such that
f (n+1) (ξ(x̄)) Y
n
En (x̄) = f (x̄) − Pn (x̄) = (x̄ − xi ). (2.4)
(n + 1)! i=0
66
Proof: If x̄ is one of the numbers x0 , x1 , · · · , xn : then the result follows trivially. Because, the error in this
case is zero, and the result will hold for any arbitrary ξ.
(xk − x0 ) · · · (xk − xn )
g(xk ) = f (xk ) − Pn (xk ) − [f (x̄) − Pn (x̄)]
(x̄ − x0 ) · · · (x̄ − xn )
= Pn (xk ) − Pn (xk ) − [f (x̄) − Pn (x̄)] × 0 (2.6)
=0
(Note that the numerator of the fraction appearing above contains the term (xk − xk ) = 0).
Furthermore,
(x̄ − x0 ) · · · (x̄ − xn )
g(x̄) = f (x̄) − Pn (x̄) − [f (x̄) − Pn (x̄)] ∗
(x̄ − x0 ) · · · (x̄ − xn )
= f (x̄) − Pn (x̄) − f (x̄) + Pn (x̄) (2.7)
=0
Thus, g(t) becomes identically zero at (n + 2) distinct points: x0 , x1 , · · · , xn , and x̄. Furthermore, g(t) is
Therefore, by generalized Rolle’s theorem, [ ], there exists a number ξ(x̄) in (a, b) such that g (n+1) (ξ) =
0.
Then
dn+1 (t − x0 )(t − x1 ) · · · (t − xn )
dtn+1 (x̄ − x0 )(x̄ − x1 ) · · · (x̄xn )
1 dn+1
= · n+1 [(t − x0 )(t − x1 ) · · · (t − xn )]
(x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn ) dt
1
= (n + 1)!
(x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn )
67
(note that the expression within [ ] is a polynomial of degree n + 1).
(n+1) (n+1)
Also, Pn (t) = 0, because Pn is a polynomial of degree at most n. Thus, Pn (ξ) = 0.
So,
(f (x̄) − Pn (x̄))
g (n+1) (ξ) = f (n+1) (ξ) − (n + 1)! (2.8)
(x̄ − x0 ) · · · (x̄ − xn )
f (n+1) (ξ)
Since g (n+1) (ξ) = 0, from (2.8), we have En (x̄) = f (x̄) − Pn (x̄) = (x̄ − x0 ) · · · (x̄ − xn ).
(n + 1)!
Remark: To obtain the error of interpolation using the above theorem, we need to know the (n + 1)th
derivative of the f (x) or its absolute maximum value on the interval [a, b]. Since in practice this value is
Example 2.3 Let’s compute the maximum absolute error for Example 3.2.
Here n = 2.
f (3) (ξ)
= (x̄ − x0 )(x̄ − x1 )(x̄ − x2 )
3!
To know the maximum value of E2 (x̄), we need to know f (3) (x).
1 1 2 6
f (x) = , f 0 (x) = − 2 , f 00 (x) 3 , f (3) (x) = − 4 .
x x x x
6 6
So, |f (3) (ξ)| < = for 0 < x ≤ 2.
24 16
Since x̄ = 3, x0 = 2, x1 = 2.5, x2 = 4, we have
6 1
|E2 (x̄)| ≤ | × (3 − 2)(3 − 2.5)(3 − 4)| = 0.0625.
16 6
Note that in four-digit arithmetic, the difference between the value obtained by interpolation and the exact
68
2.5 Simplification of the Error Bound for Equidistant Nodes
The error formula in Theorem 3.2 can be simplified in case the tabulated points (nodes) are equally spaced;
because, in this case it is possible to obtain a nice bound for the expression: (x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn ).
Suppose the nodes are equally spaced with spacing h; that is xi+1 − xi = h.
h h h h h
a = x0 x1 x2 b = xn
hn+1
|(x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn )| ≤ n!
4
M hn+1 M hn+1
|En (x̄)| = |f (x̄) − Pn (x̄)| ≤ n! = . (2.9)
(n + 1)! 4 4(n + 1)
Example 2.4 Suppose a table of values for f (x) = cos x has to be prepared in [0, 2π] with equal spacing
nodes of spacing h, using linear interpolation, with an error of interpolation of at most 5 × 10−8 . How
Here n = 1.
Thus M = 1.
69
√
Example 2.5 Suppose a table is to be prepared for the function f (x) = x on [1, 2]. Determine the spaceing
h in a table such that the interpolation with a polynomial of degree 2 will give accuracy = 5 × 10−8 .
1 3
Thus, to have an accuracy of = 5 × 10−8 , we must have h < 5 × 10−8 or h3 < 160 × 10−8 .
32
√
This means that a spacing h of about h = 3
160 × 10−8 = 0.0117 will be needed in the Table to guarantee
A major difficulty with the Lagrange Interpolation is that one is not sure about the degree of interpolating
polynomial needed to achieve a certain accuracy. Thus, if the accuracy is not good enough with polynomial
of a certain degree, one needs to increase the degree of polynomial, and computations need to be started
Furthermore, computing various Lagrangian polynomials is an expensive procedure. It is, indeed, desir-
able to have a formula which makes use of Pk−1 (x) in computing Pk (x).
The idea is to obtain the interpolating polynomial Pn (x) in the following form:
For x = x0 , Pn (x0 ) = a0 = f0
70
which gives
f 1 − a0 f1 − f0
a1 = = .
x1 − x0 x1 − x0
It is convenient to introduce the following notation, because we will show how the numbers a0 , ..., an can be
f [xi+1 ] − f [xi ]
f (xi ) = f [xi ] and f [xi , xi+1 ] =
xi+1 − xi
Similarly,
f [xi+1 , ..., xi+k−1 , xi+k ] − f [xi , xi+1 , ..., xi+k−1 ]
f [xi , xi+1 , · · · , xi+k−1 , xi+k ] =
xi+k − xi
a0 = f0 = f (x0 ) = f [x0 ]
ak = f [x0 , x1 , · · · , xk ]. (2.11)
Substituting these expressions of ak in (2.11), the interpolating polynomial Pn (x) now can be written in
Notes:
(i) Each divided difference can be obtained from two previous ones of lower orders.
For example, f [x0 , x1 , x2 ] can be computed from f [x0 , x1 ], and f [x1 , x2 ], and so on. Indeed, they can
71
Table of Divided Differences (n = 4)
x f (x) 1st Divide Difference 2nd Divided Difference 3rd Divided Difference
x0 f0
x1 f1 f [x0 , x1 ] f [x0 , x1 , x2 ]
x2 f2 f [x1 , x2 ] f [x1 , x2 , x3 ] f [x0 , x1 , x2 , x3 ]
x3 f3 f [x2 , x3 ] f [x2 , x3 , x4 ] f [x1 , x2 , x3 , x4 ]
x4 f4 f [x3 , x4 ]
(ii) Note that in computing Pn (x) we need only the diagonal entries of the above table; that is, we need
(iii) Since the divided differences are generated recursively, the interpolating polynomials of successively
higher degrees can also be generated recursively. Thus the work done previously can be used
gainfully.
For example,
and so on.
Thus, in computing P2 (x), P1 (x) has been gainfully used; in computing P3 (x), P2 (x) has been gainfully
used, etc.
Example 2.6 Interpolate at x = 2.5 using the following Table, with polynomials of degree 3 and 4.
72
n x f 1st diff. 2nd diff. 3rd diff. 4th diff 5th diff
5 4.0 0.60206
(Note that in computing P4 (2.5), P3 (2.5) computed previously has been gainfully used).
Inputs:
73
Outputs:
di,0 = 0 = fi , i = 0, 1, 2, · · · , n.
For i = 1, 2, · · · , n do
i = 1, 2, · · · i do
Di,j−1 − Di−1,j−1
Dij −
xi − xi−j
End
The following theorem shows how the nth derivative of a function f (x) is related to the nth divided difference.
The proof is omitted. It can be found in any advanced numerical analysis text book (e.g., Atkins on (1978),
p. 144).
Theorem 2.3 Suppose f is n times continuously differentiable and x0 , x1 , · · · , xn are (n + 1) distinct num-
bers in [a, b]. Then there exists a number ξ in (a, b) such that
f (n) (ξ)
f [x0 , x1 , · · · , xn ] =
n!
Then x − x0 = sh
x − x1 = x − x0 + x0 − x1 = (x − x0 ) − (x1 − x0 ) = sh − h = (s − 1)h
In general, x − xi = (s − i)h.
So,
74
Pn (x) = Pn (x0 + sh) = f [x0 ] + f [x0 , x1 ](x − x0 ) + · · · + f [x0 , x1 , · · · , xn ](x − x0 ) · · · (x − xn−1 )
So,
f [x1 , x2 ] − f [x0 , x1 ]
f [x0 , x1 , x2 ] =
(x2 − x0 )
f (x2 )−f (x1 ) f (x1 )−f (x0 )
x2 −x1 − x1 −x0
= (2.17)
(x2 − x0 )
f (x2 ) − 2f (x1 ) − f (x0 ) ∆2 f0
= =
h × 2h 2h2
75
In general, we have
f [x0 , x1 , . . . , xk ]
1 (2.18)
= ∆k f0 .
k!hk
Proof is by induction on k.
For k = 0, the result is trivially true. We have also proved the result for k = 1, and k = 2.
Assume now that the result is true k = m. Then we need to show that the result is also true for k = m + 1.
f [x0 , · · · , xm ]
Now, f [x0 , · · · , xm+1 ] = f [x1 , · · · , xm+1 ] −
m xm+1 − x0
∆ f1 ∆m f0
m!hm − m!hm ∆m (f1 − f0 ) ∆m+1 f0
= = m+1
=
(m + 1)h m!(m + 1)h (m + 1)!hm+1
We now show how the interpolating polynomial Pn (x) given by (2.14) can be written using forward differ-
ences.
x − x0
where s = .
h
76
Illustration: The Forward Difference Table with n = 4
x f (x) ∆f ∆2 f ∆3 f ∆4 f
x0 f0
x1 f1 ∆f0
x2 f2 ∆f1 ∆2 f0
x3 f3 ∆f2 ∆2 f1 ∆3 f0
x4 f4 ∆f3 ∆2 f2 ∆3 f1 ∆3 f0
x f ∆f ∆2 f ∆3 f
0 1
1 2.7183 1.7183
x − x0 1.5 − 0
Then s = = = 1.5
h 1
(1.5 − 1)(1.5 − 2)
P4 (1.5) = 1.7183 × 1 + (1.5)(1.7183) + (1.5)
2
(1.5 − 1)(1.5 − 2)(1.5 − 3)
×2.8817 +(1.5) × 5.0734 = 4.0852.
6
While interpolating at some value of x near the end of the difference table, it is logical to reorder the nodes
77
so that the end-differences can be used in computation. The backward differences allow us to do so.
∇fn = fn − fn−1 , n = 1, 2, 3, . . . ,
and
∇k fn = ∇(∇k−1 fn ), k = 2, 3, . . .
= fn − 2fn−1 + fn−2 ,
and so on.
The following a relationship between the backward-differences and the divided differences can be obtained.
1
f [xn−k , · · · , xn−1 , xn ] = ∇k fn .
k!hk
Using these backward-differences, we can write the Newton interpolation formula as:
Newton’s Backward-Difference
Interpolations Formula
X
n
−s
Pn (x) = (−1)k 5k f n .
k
k=0
78
NUMERICAL INTEGRATION
Introduction
There are two main reasons for the need to do numerical integration: analytical integration
may be impossible or infeasible, or you may wish to integrate tabulated data rather than
known functions. In this section we outline the main approaches to numerical integration to
x1
evaluate integrals of the form f ( x)dx , which is preferable depending in part of the results
x0
Learning Objectives
Unit content
79
Session 1-1 Trapezoidal Rule
where f (x) is called the integrand, a lower limit of integration and b upper limit of
integration.
In using the basic trapezoidal rule to approximate the value of the integral (1), one replaces the
integrand f (x) by a first order polynomial, i,e,.
b b
I f ( x)dx f1 ( x)dx (2)
a a
where f1 ( x) a0 a1 x .
Hence
b b b
b2 a 2
a
f ( x)dx f1 ( x)dx (a0 a1 x)dx a0 (b a) a1
a a 2
.
(3)
Now if one chooses, (a, f (a)) and (b, f (b)) as the two points to approximate f (x) by a straight
line from (a, f (a)) to (b, f (b)) , then
80
f (a) f1 (a) a0 a1a (4)
a
f ( x)dx
ba
(b a)
ba 2
(7)
f (a) f (b)
(b a )
2
f (a) f (b)
b
f ( x)dx (b a)
a
2
The above is called the single segment form of the trapezoidal rule.
The Trapezoidal rule can also be derived from geometry. In Figure 2 the area under the curve
f1(x) between a and b is a trapezium. The integral
b
1
f ( x)dx Area of trapezoid 2 (Sum of parallel sides) (height)
a
(8)
1 f (a) f (b)
f (b) f (a ) (b a ) (b a )
2 2
81
Example 1:
30
140000
Evaluate the integral I 2000ln 9.8t dt
8 140000 2100t
Solution
f (a) f (b)
a) I (b a)
2 , where a 8 , b 30
140000
f (t ) 2000 ln 9.8t
140000 2100t
140000
f (8) 2000ln 9.8(8) 177.27
140000 2100(8)
140000
f (30) 2000ln 9.8(30) 901.67
140000 2100(30)
177.27 901.67
I (30 8) 11868
2
30
140000
b) The exact value of the above integral is x 2000ln 9.8t dt 11061
8 140000 2100t
so the true error is Et True Value Approximate Value 11061 11868 807
c) The absolute relative true error, t , would then be
True Error 11061 11868
t 100 100 7.2959%
True Value 11061
where h (b a) n .
82
Figure 3: Multiple (n=4) Segment Trapezoidal Rule
h n 1
b
In Example 1, the true error using a single segment trapezoidal rule was large. We can divide the
interval [8, 30] into [8, 19] and [19, 30] intervals and apply Trapezoidal rule over each segment.
140000
f (t ) 2000 ln 9.8t
140000 2100t
140000
f (19) 2000ln 9.8(19) 484.75
140000 2100(19)
f (30) 901.67
83
Hence
f (t )dt (19 8)
8
2
(30 19)
2 11266
Example 2:
30
140000
Evaluate the integral I 2000ln 9.8t dt
8 140000 2100t
Solution
a) The solution using 2-segment Trapezoidal rule is
ba n 1
I f ( a ) 2 f (a ih ) f (b)
2n i 1
b a 30 8
where n 2 , a 8 , b 30 , h 11
n 2
30 8 21 22
I f (8) 2 f (a ih) f (30) f (8) 2 f (19) f (30)
2(2) i 1 4
22
177.27 2(484.75) 901.67 11266
4
84
c) The absolute relative true error, t , would then be
True Error 11061 11266
t 100 100 1.8534%
True Value 11061
n Value Et t % a %
1 11868 -807 7.296 ---
2 11266 -205 1.853 5.343
3 11153 -91.4 0.8265 1.019
4 11113 -51.5 0.4655 0.3594
5 11094 -33.0 0.2981 0.1669
6 11084 -22.9 0.2070 0.09082
7 11078 -16.8 0.1521 0.05482
8 11074 -12.9 0.1165 0.03560
Example 3:
300 x
Use Multiple-segment Trapezoidal Rule to find the area under the curve f ( x) from
1 ex
x 0 to x 10 .
Solution
Using two segments, we get
ba n 1 10 0 21
I f ( a ) 2 f ( a ih ) f (b ) f (0) 2 f (0 5) f (10)
2n i 1 2(2) i 1
10 10
f (0) 2 f (5) f (10) 0 2(10.039) 0.136 50.535
4 4
85
10
300 x
So what is the true value of this integral 1 e
0
x
dx 246.59 ?
246.59 50.535
t 100% 79.506%
246.59
Why is the true value so far away from the approximate values? Just take a look at Figure 5. As
you can see, the area under the “trapezoids” (covers a small the area under the curve. As we add
more segments, the approximated value quickly approaches the true value.
86
10
300 x
Table 2: Values obtained using Multiple-segment Trapezoidal Rule for 1 e
0
x
dx
n Approximate Value Et t
1 0.681 245.91 99.724%
2 50.535 196.05 79.505%
4 170.61 75.978 30.812%
8 227.04 19.546 7.927%
16 241.70 4.887 1.982%
32 245.37 1.222 0.495%
64 246.28 0.305 0.124%
What is the error, then in the multiple-segment Trapezoidal rule? It will be simply the sum of
the errors from each segment, where the error in each segment is that of the single segment
Trapezoidal rule. The error in each segment is
( a h) a
3
h3
E1 f "( 1 ) f "( 1 ), a 1 a h
12 12
( a 2 h) ( a h)
3
h3
E2 f "( 2 ) f "( 2 ), a h 2 a 2h
12 12
87
…
a (n 1)h a (n 2)h
3
h3
En1 f "( n1 ) f "( n1 ), a (n 2)h n1 a (n 1)h
12 12
b a (n 1)h
3
h3
En f "( n ) f "( n ), a (n 1)h n b
12 12
n
h3 n (b a)3 n (b a)3 f "( ) i
Et Ei f "( i ) i 12n2
f "( ) i 1
i 1 12 i 1 12n3 i 1 n
1 n
The term f "( i ) is an approximate average value of the second derivative f "( x), a x b .
n i 1
(b a) 3
f " ( i )
Hence Et i 1
12n 2 n
30
140000
Below is the table for the integral 2000 ln 9.8t dt as a function of the
8 140000 2100t
number of segments. You can visualize that as the number of segments are doubled, the true
error gets approximately quartered
n Value Et t % a %
2 11266 -205 1.854 5.343
4 11113 -51.5 0.4655 0.3594
8 11074 -12.9 0.1165 0.03560
16 11065 -3.22 0.02913 0.00401
For example, for 2-segment Trapezoidal rule, the true error is 205, and a quarter of that error is
51.25. That is close to the true error of 51.5 for the 4-segment Trapezoidal rule.
88
Session 2-1 Simpson’s 1/3rd Rule:
a b a b
Choose (a, f (a)), , f , and (b, f (b)) as the three points of the function to
2 2
evaluate a 0 , a1 and a 2 .
f f2 a0 a1 a2
2 2 2 2
ab
a 2 f (b) abf (b) 4abf abf (a) b f (a)
2
a0 2
a 2ab b 2
2
ab ab
af (a) 4af 3af (b) 3bf (a) 4bf bf (b)
a1 2 2
a 2 2ab b 2
ab
2 f (a) 2 f f (b)
2
a2
a 2ab b
2 2
89
Then
b
b b
x2 x3
I f 2 ( x)dx a0 a1 x a2 x dx a0 x a1 a2
2
a a 2 3 a
b2 a 2 b3 a 3
a0 (b a) a1 a2
2 3
ba ab
b
f
a
2 ( x)dx
6
f (a) 4 f f (b)
2
Since for Simpson’s 1/3rd Rule, the interval a, b is broken into 2 segments, the segment width
ba
is h .
2
h a b
b
f ( x)dx 3 f (a) 4 f f ( b)
rd
Hence the Simpson’s 1/3 rule is given by
a
2
Since the above form has 1/3 in its formula, it is called Simpson’s 1/3rd Rule.
Example 1:
30
140000
Evaluate the integral x 2000 ln 9.8t dt
8 140000 2100t
rd
a) Using Simpson’s 1/3 Rule to find the approximate value of x .
b) Find the true error, E t
c) Find the absolute relative true error, t .
Solution:
ba ab
a) x f (a) 4 f f (b)
6 2
a 8
b 30
ab
19
2
90
140000
f (t ) 2000 ln 9.8t
140000 2100t
140000
f (8) 2000 ln 9.8(8) 177.27m / s
140000 2100(8)
140000
f (30) 2000 ln 9.8(30) 901.67m / s
140000 2100(30)
140000
f (19) 2000 ln 9.8(19) 484.75m / s
140000 2100(19)
ba ab 30 8
x f (a) 4 f f (b) f (8) 4 f (19) f (30)
6 2 6
22
177.2667 4(484.7455) 901.6740 11065.72
6
30
140000
x 2000ln 9.8t dt 11061.34
8 140000 2100t
91
b xn
f ( x)dx f ( x)dx
a x0
where x0 a , xn b
b x2 x4 xn2 xn
f ( x0 ) 4 f ( x1 ) f ( x2 ) f ( x2 ) 4 f ( x3 ) f ( x4 )
b
f ( x)dx ( x
a
2 x0 )
6
( x4 x2 )
6
f ( xn 4 ) 4 f ( xn 3 ) f ( xn 2 ) f ( xn 2 ) 4 f ( xn 1 ) f ( xn )
( xn 2 xn 4 ) ( xn xn 2 )
6 6
Since xi xi 2 2h , i 2, 4, , n
then
f ( x0 ) 4 f ( x1 ) f ( x2 ) f ( x2 ) 4 f ( x3 ) f ( x4 )
b
f ( x)dx 2h
a
6
2h
6
f ( xn 4 ) 4 f ( xn 3 ) f ( xn 2 ) f ( xn 2 ) 4 f ( xn 1 ) f ( xn )
2h 2h
6 6
h
f ( x0 ) 4 f ( x1 ) f ( x3 ) ... f ( xn 1 ) 2 f ( x2 ) f ( x4 ) ... f ( xn 2 ) f ( xn )
3
n 1 n2
h
f ( x0 ) 4 f ( xi ) 2 f ( xi ) f ( xn )
3 i 1 i 2
i odd i even
Hence the multiple segment Simpson’s 1/3rd Rule is given by
ba n 1 n 2
b
f ( x )dx f ( x 0 ) 4 f ( xi ) 2 f ( xi ) f ( x n )
3n i 1 i 2
a
i odd i even
92
Example 2:
30
140000
Approximate the value of the integral x 2000 ln 9.8t dt
8 140000 2100t
rd
a) Using the four segment Simpson’s 1/3 Rule.
b) Find the true error, Et for part (a).
c) Find the absolute relative true error for part (a).
Solution:
ba n 1 n2
x f (t 0 ) 4 f (t i ) 2 f (t i ) f (t n )
3n i 1 i 2
i odd i even
b a 30 8
In this case n 4 , a 8 , b 30 , h 5.5
n 4
140000
f (t ) 2000 ln 9.8t
140000 2100t
So
f (t 0 ) f (8)
140000
f (8) 2000ln 9.8(8) 177.27
140000 2100(8)
140000
f (13.5) 2000 ln 9.8(13.5) 320.25m / s
140000 2100(13.5)
140000
f (19) 2000 ln 9.8(19) 484.75m / s
140000 2100(19)
93
140000
f (24.5) 2000 ln 9.8(24.5) 676.05m / s
140000 2100(24.5)
f (t 4 ) f (t n ) f (30)
140000
f (30) 2000 ln 9.8(30) 901.67m / s
140000 2100(30)
ba n 1 n2
x f (t0 ) 4 f (ti ) 2 f (ti ) f (tn )
3n i 1 i 2
i odd i even
30 8 3 2
f (8) 4 f (ti ) 2 f (ti ) f (30)
3(4) i 1 i 2
i odd i even
11
177.27 4(320.25) 4(676.05) 2(484.75) 901.67 11061.64
6
In this case, the true error is Et 11061.34 11061.64 0.30 and the absolute relative true
11061.34 11061.64
error t 100% 0.0027%
11061.34
Table 1: Values of Simpson’s 1/3rd Rule for Example 2 with multiple segments
n Approximate Value Et t
94
2-4.3 Error in Multiple Segment Simpson’s 1/3rd Rule
The true error in a single application of Simpson’s 1/3rd Rule is given1
(b a) 5 ( 4)
Et f ( ), a b
2880
In Multiple Segment Simpson’s 1/3rd Rule, the error is the sum of the errors in each application
of Simpson’s 1/3rd Rule. The error in n segment Simpson’s 1/3rd Rule is given by
( x2 x0 )5 (4) h5 (4)
E1 f ( 1 ) f ( 1 ), x0 1 x2
2880 90
( x4 x2 )5 (4) h5 (4)
E2 f ( 2 ) f ( 2 ), x2 2 x4
2880 90
( xn 2 xn 4 )5 (4)
f n 21
h5 (4)
En f n 21 , xn 4 n 21 xn 2
1 2880 90
2
( xn xn2 )5 4 h5 (4)
En f n 2 f n , xn 2 n 2 xn
2 2880 90 2
i 1 90 i 1 90n5 i 1 90n 4 n
1
The f (4) in the true error expression stands for the fourth derivative of f.
95
1 n 2 (4)
The term
n i 1
f ( i ) is an approximate average value of f ( 4) ( x), a x b .
(b a ) 5 ( 4 ) 1 n 2 (4)
f ( i ) .
(4)
Hence Et f , where f
90n 4 n i 1
b n
f ( x)dx c f x , where c , x , i 1,
a i 1
i i i i , n are the solution of the system
b n
f m ( x)dx ci f m xi , f m ( x) x m , m 0,1, , 2n 1 .
a i 1
The 2-point Gaussian quadrature rule can be derived by assuming that the expression gives exact
b b b b
values for integrals of individual integrals of 1dx, xdx, x
2
dx, and x dx .
3
These will give
a a a a
1dx b a c
a
1 c2
b2 a 2
b
xdx
a
2
c1 x1 c2 x2
b3 a 3
b
x dx c1 x1 c2 x2
2 2 2
a
3
b4 a 4
b
x dx c1 x1 c2 x2
3 3 3
(14)
a
4
These four simultaneous nonlinear Equations (14) can be solved with a single acceptable
ba ba
solution c1 , c2
2 2
96
b a 1 b a b a 1 b a
x1 , x2 (15)
2 3 2 2 3 2
Hence
b
ba ba 1 ba ba ba 1 ba
a
f ( x)dx
2
f
2
3
2
2
f
2
3
2
(16)
Since two points are chosen, it is called the two-point Gaussian Quadrature Rule. Higher point
versions can also be developed.
f ( x)dx c
a
1 f ( x1 ) c2 f ( x2 ) c3 f ( x3 ) (17)
is called the three-point Gauss Quadrature Rule. The coefficients c1 , c 2 and c3 , and the
function arguments x1 , x 2 and x3 are calculated by assuming the formula gives exact
a
b
expressions for integrating a fifth order polynomial 0 a1 x a 2 x 2 a3 x 3 a 4 x 4 a5 x 5 dx .
a
f ( x)dx c
a
1 f ( x1 ) c 2 f ( x 2 ) . . . . . . . cn f ( xn ) (18)
1 n
g ( x)dx ci g xi , where ci , xi , i 1,
1 i 1
, n are the solution of the system
1 n
gm ( x)dx ci gm xi , gm ( x) x , m 0,1, , 2n 1 .
m
1 i 1
97
The coefficients and arguments are given for the n-point Gaussian Quadrature Rule for
n 2, ,6 in the table below
3 c1 0.555555556 x1 0.774596669
c2 0.888888889 x2 0.000000000
c3 0.555555556 x3 0.774596669
4 c1 0.347854845 x1 0.861136312
c2 0.652145155 x2 0.339981044
c3 0.652145155 x3 0.339981044
c4 0.347854845 x4 0.861136312
5 c1 0.236926885 x1 0.906179846
c2 0.478628670 x2 0.538469310
c3 0.568888889 x3 0.000000000
c4 0.478628670 x4 0.538469310
c5 0.236926885 x5 0.906179846
6 c1 0.171324492 x1 0.932469514
c2 0.360761573 x2 0.661209386
c3 0.467913935 x3 0.238619186
c4 0.467913935 x4 0.238619186
c5 0.360761573 x5 0.661209386
c6 0.171324492 x6 0.932469514
98
1 b
So if the table is given for g ( x )dx integrals, how does one solve
1
f ( x)dx ?
a
ba
b 1
f ( b 2a )t ( a 2 b ) dt
2 1
Note: f ( x)dx
a
The answer lies in that any integral with limits of a, b can be converted into an integral with
limits 1, 1 . Let
x mt c (20)
If x a, then t 1 .
If x b, then t 1 .
such that
ba ba
m , c (22)
2 2
a
f ( x)dx f
1
2
t
2 2
dt (23)
Example 1
1
For an integral f ( x)dx,
1
show that the two-point Gauss Quadrature rule approximates to
1
f ( x)dx c f x c f x , where c
1 1
1 1 2 2 1 1 , c2 1 , x1 and x 2 .
1 3 3
99
Solution
f ( x)dx c f x c f x
1
1 1 2 2 (E1.1)
1 1 1 1
gives exact values for integrals 1dx, xdx, x x dx
2 3
dx, and . Then
1 1 1 1
1
1dx 2 c 1 c2 (E1.2)
xdx 0 c x
1
1 1 c2 x2 (E1.3)
1
2
x dx c1 x1 c2 x 2
2 2 2
(E1.4)
1
3
1
x dx 0 c x c2 x2
3 3 3
1 1 (E1.5)
1
2
Multiplying Equation (E1.3) by x1 and subtracting from Equation (E1.5) gives
c2 x2 x1 x2 2 2
0. (E1.6)
2
I. c2 0 is not acceptable as Equations (E1.2-E1.5) reduce to c1 2; c1 x1 0; c1 x12 ;
3
and c1 x1 0 . But since c1 2 , then x1 0 from c1 x1 0 , but x1 0 conflicts with
3
2
c1 x12 .
3
II. x2 0 is not acceptable as Equations (E1.2-E1.5) reduce to c1 c2 2 ; c1 x1 0;
2
c1 x12 ; c1 x13 0 . Since c1 x1 0 , then c1 or x1 has to be zero but this violates
3
2
c1 x12 0 .
3
100
III. x1 x2 is not as Equations (E1.2-E1.5) reduce to c1 c2 2 ;
acceptable
2
c1 x1 c2 x1 0; c1 x12 c2 x12 ; c1 x13 c2 x13 0 . If x1 0 , then c1 x1 c2 x1 0 gives
3
2
c1 c2 0 and that violates c1 c2 2 . If x1 0 , then violates c1 x12 c2 x12 0
3
That leaves the solution of x1 x2 as the only possible acceptable solution and in fact, it does
not have violations (see it for yourself)
x1 x2 (E1.7)
c1 c2 (E1.8)
c1 c2 1 (E1.9)
2
x1 x 2
2 2
(E1.10)
3
Since Equation (E1.7) requires that the two results be of opposite sign, we get
1 1
x1 , x2
3 3
Hence
1 1
1
f ( x)dx c
1
1 f ( x1 ) c2 f ( x2 ) f
3
f
3
(E1.11)
Example 2
b
For an integral, f ( x)dx, derive the one-point Gaussian Quadrature Rule.
a
101
Solution
f ( x)dx c f x
a
1 1 (E2.1)
1 1
Assuming the formula gives exact values for integrals 1dx, and
1
xdx
1
1dx b a c
a
1
(E2.2)
b2 a 2
b
a xdx
2
c1 x1
b2 a 2
(b a ) x1
2 (E2.3)
ba
x1
2
ba
b
f ( x)dx (b a ) f
a
2
(E2.4)
Example 3
b
What would be the formula for f ( x)dx c
a
1 f (a) c2 f (b) , if you want the above formula to
Solution
102
b2 a 2
b
xdx
a
2
c1a c2b
(E3.1)
b3 a 3
b
a c1a 2 c2b 2
2
x dx
3
b2 a2
a b c1 2
3
a 2 b 2 c 2 b a
3
3
1 ab b 2 2a 2 1 a 2 ab 2b 2
c1 , c2 (E3.2)
6 a 6 b
So
1 ab b 2 2a 2 1 a 2 ab 2b 2
b
a
f ( x)dx
6 a
f (a)
6 b
f (b) (E3.3)
2 x
5
Evaluate 2
3x dx using the above formula.
2
2x 3x dx c1 f (a) c2 f (b)
2
5
Now evaluate 3dx using the above formula
2
103
5 5
The exact value of 3dx is given by 3dx 3x 2 9
5
2 2
Because the formula will only give exact values for linear combinations of x and x 2 , it does not
5
work exactly even for a simple integral of 3dx .
2
Do you see now why we choose a0 a1 x as the integrand for which the formula
b
f ( x)dx c f (a) c
a
1 2 f (b) gives us exact values?
Example 4
Use the two-point Gaussian Quadrature Rule to approximate the value of the integral
30
140000
x 2000 ln 9.8t dt
8 140000 2100t
Solution
First, change the limits of integration from 8, 30 to 1, 1 using Equation 23 gives
30 8 30 8 30 8
30 1 1
Next, get weighting factors and function argument values from Table 1 for the two point rule,
c1 1.000000000 .
x1 0.577350269
c2 1.000000000
x2 0.577350269
104
Now we can use the Gaussian Quadrature formula
1
11 f 11x 19 dx 11 c1 f 11x1 19 c2 f 11x2 19
1
11 f 11(0.5773503) 19 f 11(0.5773503) 19
11 f (12.64915) f (25.35085) 11(296.8317) (708.4811) 11058.44
since
140000
f (12.64915) 2000ln 9.8(12.64915) 296.8317
140000 2100(12.64915)
140000
f (25.35085) 2000ln 9.8(25.35085) 708.4811
140000 2100(25.35085)
11061.34 11058.44
t 100% 0.0262%
11061.34
Example 5
Use the three-point Gauss Quadrature Rule to approximate the value of the integral
30
140000
x 2000 ln 9.8t dt
8 140000 2100t
Solution
First, change the limits of integration from 8, 30 to 1, 1 using Equation (23) gives
30 8 30 8 30 8
30 1 1
105
The weighting factors and function argument values are
c1 0.555555556
x1 0.774596669
c2 0.888888889
x2 0.000000000
c3 0.555555556
x3 0.774596669
since
140000
f (10.47944) 2000ln 9.8(10.47944) 239.3327
140000 2100(10.47944)
140000
f (19.00000) 2000ln 9.8(19.00000) 484.7455
140000 2100(19.00000)
140000
f (27.52056) 2000ln 9.8(27.52056) 795.1069
140000 2100(27.52056)
11061.34 11061.31
t 100% 0.0003%
11061.34
106
Assignment–Direct methods ::Math351-Numerical analysis
The following procedure provides the LU factorization with partial pivoting of a square matrix, A =
(aij )n×n , where L = (lij )n×n is a unit lower triangular and U = (uij )n×n an upper triangular.
Procedure
Starting with k = 1 to n − 1, scan the entries of the kth column of the matrix A(k−1) below the row (k − 1)
to identify the pivot ark ,k , rk such that |ark ,k | = max |aik |. Next form the permutation matrix, Pk , and find
k≤i≤n
an elementary matrix Mk such that A(k) = Mk Pk A(k−1) has zeros below the (k, k) entry on the kth column.
−1
L = P (Mn−1 Pn−1 Mn−2 Pn−2 · · · M2 P2 M1 P1 )
Write
U = Mn−1 Pn−1 Mn−2 Pn−2 · · · M2 P2 M1 P1 A
−1
where P = (Pn−1 Pn−2 · · · P2 P1 ) and P A = LU .
5 7 6 5
7 10 8 7
Given that A =
6 8 10 9 . Using partial pivoting:
5 7 9 10
7. What is the most appropriate direct method in terms of complexity that can best be used to factorize
the system into a unit lower triangular matrix and its corresponding upper triangular matrix? Explain
your answer.
8. To determine the surface shape of an object from images taken of a surface from three different direc-
tions, one needs to solve a set of three equations. The coefficient matrix, A of the system formed is
dependent on the light source directions with respect to the camera. The unknowns, x,y,z are therefore
the incident intensities that will determine the shape of the object. The right hand side values are the
light intensities from the middle of the images.
0.2425 0 −0.9701 x 247
Given the following arrangement, 0 0.2425 −0.9701 y = 248 , solve for the
−0.2357 −0.2357 −0.9428 z 239
incident intencities using partial pivoting.
107