1.1.naive Gaussian Elimination
1.1.naive Gaussian Elimination
Gaussian Elimination
1
Numerical Analysis MATH351/352
where
a21
a22
a22 a12
a11
a21
a2 n a2 n a1n
a11
This procedure of eliminating x1 , is now repeated for the third equation to the n th equation
to reduce the set of equations as
a11x1 a12 x2 a13 x3 ... a1n xn b1
a22 x2 a23
x3 ... a2 n xn b2
a32 x2 a33
x3 ... a3 n xn b3
. . .
. . .
. . .
an 2 x2 an 3 x3 ... ann
xn bn
This is the end of the first step of forward elimination. Now for the second step of forward
elimination, we start with the second equation as the pivot equation and a22 as the pivot
element. So, to eliminate x2 in the third equation, one divides the second equation by a22
(the pivot element) and then multiply it by a32 . This is the same as multiplying the second
equation by a32 / a22 and subtracting it from the third equation. This makes the coefficient of
x2 zero in the third equation. The same procedure is now repeated for the fourth equation
till the n th equation to give
a11x1 a12 x2 a13 x3 ... a1n xn b1
a22 x2 a23 x3 ... a2 n xn b2
a33 x3 ... a3n xn b3
. .
. .
. .
an3 x3 ... ann
xn bn
The next steps of forward elimination are conducted by using the third equation as a pivot
equation and so on. That is, there will be a total of n 1 steps of forward elimination. At the
end of n 1 steps of forward elimination, we get a set of equations that look like
a11x1 a12 x2 a13 x3 ... a1n xn b1
a22 x2 a23 x3 ... a2 n xn b2
x3 ... a3n xn b3
a33
. .
. .
. .
ann xn bnn 1
n 1
2
Gaussian Elimination MATH351/352
Back Substitution:
Now the equations are solved starting from the last equation as it has only one unknown.
b ( n 1)
x n n( n 1)
a nn
Then the second last equation, that is the (n 1) th equation, has two unknowns: x n and xn1 ,
but x n is already known. This reduces the (n 1) th equation also to one unknown. Back
substitution hence can be represented for all equations by the formula
bii 1 aiji 1 x j
n
j i 1
xi for i n 1, n 2,,1
aiii 1
and
bn( n 1)
xn ( n 1)
a nn
Example 1
The upward velocity of a rocket is given at three different times in Table 1.
Solution
Forward Elimination of Unknowns
Since there are three equations, there will be two steps of forward elimination of unknowns.
First step
Divide Row 1 by 25 and then multiply it by 64, that is, multiply Row 1 by 64/25 2.56 .
25 5 1 106.8 2.56 gives Row 1 as
3
Numerical Analysis MATH351/352
Back substitution
From the third equation
0.7a3 0.76
0.76
a3
0.7
4
Gaussian Elimination MATH351/352
1.08571
Substituting the value of a3 in the second equation,
4.8a2 1.56a3 96.208
96.208 1.56a3
a2
4.8
96.208 1.56 1.08571
4.8
19.6905
Substituting the value of a 2 and a3 in the first equation,
25a1 5a2 a3 106.8
106.8 5a 2 a3
a1
25
106.8 5 19.6905 1.08571
25
0.290472
Hence the solution vector is
a1 0.290472
a 19.6905
2
a3 1.08571
The polynomial that passes through the three data points is then
vt a1t 2 a2 t a3
0.290472t 2 19.6905t 1.08571, 5 t 12
Since we want to find the velocity at t 6, 7.5, 9 and 11 seconds, we could simply substitute
each value of t in vt 0.290472t 2 19.6905t 1.08571 and find the corresponding
velocity. For example, at t 6
v6 0.2904726 19.69056 1.08571
2
129.686 m/s
However we could also find all the needed values of velocity at t = 6, 7.5, 9, 11 seconds
using matrix multiplication.
t 2
vt 0.290472 19.6905 1.08571 t
1
So if we want to find v6, v7.5, v9, v11, it is given by
6 2 7.5 2 9 2 112
v6 v7.5 v9 v11 0.290472 19.6905 1.08571 6 7.5 9 11
1 1 1 1
5
Numerical Analysis MATH351/352
Example 2
Use Naive Gaussian elimination to solve
20 x1 15x2 10 x3 45
3x1 2.249 x2 7 x3 1.751
5x1 x2 3x3 9
Use six significant digits with chopping in your calculations.
Solution
Working in the matrix form
20 15 10 x1 45
3 2.249 7 x = 1.751
2
5 1 3 x3 9
Forward Elimination of Unknowns
First step
Divide Row 1 by 20 and then multiply it by –3, that is, multiply Row 1 by 3 / 20 0.15 .
20 15 10 45 0.15 gives Row 1 as
3 2.25 1.5 6.75
Subtract the result from Row 2
3 2.249 7 1.751
3 2.25 1.5 6.75
0 0.001 8.5 8.501
to get the resulting equations as
20 15 10 x1 45
0 0.001 8.5 x = 8.501
2
5 1 3 x3 9
Divide Row 1 by 20 and then multiply it by 5, that is, multiply Row 1 by 5 / 20 0.25
20 15 10 45 0.25 gives Row 1 as
5 3.75 2.5 11.25
Subtract the result from Row 3
6
Gaussian Elimination MATH351/352
5 1 3 9
5 3.75 2.5 11.25
0 2.75 0.5 2.25
to get the resulting equations as
20 15 10 x1 45
0 0.001 8.5 x = 8.501
2
0 2.75 0.5 x3 2.25
Second step
Now for the second step of forward elimination, we will use Row 2 as the pivot equation and
eliminate Row 3: Column 2.
Divide Row 2 by 0.001 and then multiply it by –2.75, that is, multiply Row 2 by
2.75 / 0.001 2750 .
0 0.001 8.5 8.501 2750 gives Row 2 as
0 2.75 23375 23377.75
Rewriting within 6 significant digits with chopping
0 2.75 23375 23377.7
Subtract the result from Row 3
0 2.75 0.5 2.25
0 2.75 23375 23377.7
0 0 23375.5 23375.45
Rewriting within 6 significant digits with chopping
0 0 23375.5 23375.4
to get the resulting equations as
20 15 10 x1 45
0 0.001 8.5 x 2 = 8.501
0 0 23375.5 x3 23375.4
This is the end of the forward elimination steps.
Back substitution
We can now solve the above equations by back substitution. From the third equation,
23375.5x3 23375.4
23375.4
x3
23375.5
0.999995
Substituting the value of x3 in the second equation
0.001x2 8.5x3 8.501
8.501 8.5 x3
x2
0.001
8.501 8.5 0.999995
0.001
7
Numerical Analysis MATH351/352
8.501 8.49995
0.001
0.00105
0.001
1.05
Substituting the value of x3 and x 2 in the first equation,
20 x1 15x2 10 x3 45
45 15 x2 10 x3
x1
20
45 15 1.05 10 0.999995
20
45 15.75 9.99995
20
29.25 9.99995
20
19.2500
20
0.9625
Hence the solution is
x1
[ X ] x2
x3
0.9625
1.05
0.999995
8
Gaussian Elimination MATH351/352
5x2 6 x3 11
4 x1 5x2 7 x3 16
9 x1 2 x2 3x3 15
will result in division by zero in the first step of forward elimination as the coefficient of x1
in the first equation is zero as is evident when we write the equations in matrix form.
0 5 6 x1 11
4 5 7 x 16
2
9 2 3 x3 15
But what about the equations below: Is division by zero a problem?
5x1 6 x2 7 x3 18
10 x1 12 x2 3x3 25
20 x1 17 x2 19 x3 56
Written in matrix form,
5 6 7 x1 18
10 12 3 x 25
2
20 17 19 x3 56
there is no issue of division by zero in the first step of forward elimination. The pivot element
is the coefficient of x1 in the first equation, 5, and that is a non-zero number. However, at the
end of the first step of forward elimination, we get the following equations in matrix form
5 6 7 x1 18
0 0 11 x 11
2
0 7 9 x3 16
Now at the beginning of the 2nd step of forward elimination, the coefficient of x2 in Equation
2 would be used as the pivot element. That element is zero and hence would create the
division by zero problem.
So it is important to consider that the possibility of division by zero can occur at the
beginning of any step of forward elimination.
Round-off error: The Naive Gaussian 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 Example 2 where we used Naive Gaussian elimination to solve
20 x1 15x2 10 x3 45
3x1 2.249 x2 7 x3 1.751
5x1 x2 3x3 9
using six significant digits with chopping in your calculations? Repeat the problem, but now
use five significant digits with chopping in your calculations.
9
Numerical Analysis MATH351/352
Solution
Writing in the matrix form
20 15 10
x1 45
3 2.249 7 x = 1.751
2
5 1 3
x3 9
Forward Elimination of Unknowns
First step
Divide Row 1 by 20 and then multiply it by –3, that is, multiply Row 1 by 3 / 20 0.15 .
20 15 10 45 0.15 gives Row 1 as
3 2.25 1.5 6.75
Subtract the result from Row 2
3 2.249 7 1.751
3 2.25 1.5 6.75
0 0.001 8.5 8.501
to get the resulting equations as
20 15 10 x1 45
0 0.001 8.5 x = 8.501
2
5 1 3 x3 9
Divide Row 1 by 20 and then multiply it by 5, that is, multiply Row 1 by 5 / 20 0.25 .
20 15 10 45 0.25 gives Row 1 as
5 3.75 2.5 11.25
Subtract the result from Row 3
5 1 3 9
5 3.75 2.5 11.25
0 2.75 0.5 2.25
to get the resulting equations as
20 15 10 x1 45
0 0.001 8.5 x = 8.501
2
0 2.75 0.5 x3 2.25
Second step
Now for the second step of forward elimination, we will use Row 2 as the pivot equation and
eliminate Row 3: Column 2.
Divide Row 2 by 0.001 and then multiply it by –2.75, that is, multiply Row 2 by
2.75 / 0.001 2750 .
0 0.001 8.5 8.501 2750 gives Row 2 as
0 2.75 23375 23377.75
Rewriting within 5 significant digits with chopping
0 2.75 23375 23377
Subtract the result from Row 3
10
Gaussian Elimination MATH351/352
11
Numerical Analysis MATH351/352
45 22.5 9.9995
20
22.5 9.9995
20
12.5005
20
12.500
20
0.625
Hence the solution is
x1
X x2
x3
0.625
1.5
0.99995
Compare this with the exact solution of
x1 1
X x2 1
x3 1
12