Spring 2024-2025
Numerical Methods for Science and Engineering
Lecture Note 2
Solution of Linear System
2.1 Solution of Linear System by Elimination
Equivalent Systems: Two systems of equations are called equivalent if and only if they have
the same solution set.
Elementary Transformations: A system of equations is transformed into an equivalent
system if the following elementary operations are applied on the system:
(1) two equations are interchanged
(2) an equation is multiplied by a non-zero constant
(3) an equation is replaced by the sum of that equation and a multiple of
any other equation.
Gaussian Elimination
The process which eliminates an unknown from succeeding equations using elementary
operations is known as Gaussian elimination. The equation which is used to eliminate an
unknown from the succeeding equations is known as the pivotal equation. The coefficient of
the eliminated variable in a pivotal equation is known as the pivot. If the pivot is zero, it
cannot be used to eliminate the variable from the other equations. However, we can continue
the elimination process by interchanging the equation with a nonzero pivot.
Solution of a Linear System
A systematic procedure for solving a linear system is to reduce a system that is easier to solve.
One such system is the echelon form. The back substitution is then used to solve the system
in reverse order.
A system is in echelon form or upper triangular form if
(i) all equations containing nonzero terms are above any equation with zeros only.
(ii) the first nonzero term in every equation occurs to the right of the first nonzero term
in the equation above it.
2.2 Pivotal Elimination Method
Computers and calculators use a fixed number of digits in their calculation, and we may need
to round the numbers. This introduces errors in the calculations. Also, when two nearly equal
numbers are subtracted, the accuracy in the calculation is lost. Consider the following example
to study the difficulty faced in the elimination method.
Example 2.1:
The linear system
0.003 x +71.08 y=71.11
4.23 x−8.16 y=34.14
has the exact solution x=10 and y=1 .
Solve the above system using four-digit arithmetic i.e. keeping 4 s.f. at each value by
1
Spring 2024-2025
(a) Gaussian elimination without changing the order.
(b) Gaussian elimination by interchanging the order of the equations.
Solution
Using four-digit arithmetic the system can be written as
0.003000 x +71.08 y=71.11 (E1)
4.230 x−8.160 y=34.14 (E2)
(a) Here a multiplier is m=4.230/0.003=1410.
Multiplying (E1) by 1410 and retaining 4 digits with rounding, we have
4.230 x +100200 y=100300
4.230 x−8.160 y=34.14
Subtracting we get
100208.16 y=100265.86
To 4 digits this can be written as
2 2
1002 ×1 0 y ≈ 1003 ×1 0
This gives-
y=1.000998 ≈ 1.001
Substituting the value of y in (E1), we get
71.11−(71.08)(1.001)
x≈
0.003
−0.04000
≈ ≈−13.33
0.003000
This produces a wrong result.
(b) Interchanging the rows, we can write
4.230 x−8.160 y=34.14 (E3)
0.003000 x +71.08 y=71.11 (E4)
For this system multiplier is
0.003000
m 2= ≈ 0.0007092
4.230
The replacement of (E4) by ( E 4−m2 × E3 ) reduces the system to
4.230 x−8.160 y=34.14
71.09 y ≈71.09
The 4-digits arithmetic gives the solution-
y=1.000 and x=10.00
which is the exact solution of the system.
This example shows that the order in which we treat the equations for elimination affects the
accuracy in the elimination process.
Note that max ¿|0.003|,|4.23|}=4.23 ¿. Thus, in eliminating x, we should use the equation with
maximum numerical coefficient of x.
2.2.1 Gaussian Elimination with Partial Pivoting
Partial Pivoting
In principle, any nonzero value will do as pivot, but in practice pivot should be chosen to
minimize error propagation.
To avoid amplifying previous rounding errors when multiplying the remaining portion of
matrix by elementary elimination matrix, multipliers should not exceed 1 in magnitude.
This can be accomplished by choosing an entry of largest magnitude on or below diagonal
as pivot at each stage.
2
Spring 2024-2025
Such partial pivoting is essential in practice for numerically stable implementation of
Gaussian elimination for general linear systems.
Complete Pivoting
Complete pivoting is a more exhaustive strategy in which largest entry in entire remaining
unreduced submatrix is permuted into diagonal pivot position.
Requires interchanging columns as well as rows, leading to factorization:
PAQ=LU
with L unit lower triangular, U upper triangular, and P and Q permutations.
The numerical stability of complete pivoting is theoretically superior, but pivot search is
more expensive than for partial pivoting.
Numerical stability of partial pivoting is more than adequate in practice, so it is almost
always used in solving linear systems by Gaussian elimination.
Algorithm of partial pivoting:
(a) Select pivotal equation for a variable for elimination (the equation with maximum
numerical coefficient of that variable in the system).
(b) Eliminate the chosen variable from the remaining equations with respect to the pivotal
equation.
(c) Repeat the process for the subsystem.
(d) Using back-substitution find solutions by using pivotal equations.
For convenience of calculations, we made the coefficients of eliminated variable to unity
before elimination. This is illustrated through an example below.
Example 2.3 : The currents running through an electrical system are given by the
following system of equations. The three currents, x 1 , x 2∧x 3 are measured in amps.
4 x 1 + x 2+ 2 x 3=21
2 x1 −2 x 2 +2 x3 =8 .
x 1−2 x 2+ 4 x 3=16
a. Solve the above system to find the currents in this circuit using Gaussian elimination
with partial pivoting.
b. Justify your result by direct substitution in the original equation.
c. Write MATLAB codes to solve by left division (backslash) operator.
Solution: a.
Operations x1 x2 x3 Constant Eqn #
4 1 2 21 E1
2 -2 2 8 E2
1 -2 4 16 E3
E1/4 1.00 0.250 0.500 5.250 E4 1st Piv eqn
0
E1/2 1.00 -1.000 1.000 4.000 E5
0
E3/1 1.00 -2.000 4.000 16.000 E6
0
E5-E4 0 -1.250 0.500 -1.250 E7
E6-E4 0 -2.250 3.500 10.750 E8
E8/(-2.250) 0 1.000 -1.556 -4.778 E9 2nd Piv eqn
3
Spring 2024-2025
E7/(-1.250) 0 1.000 -0.400 1.000 E10
E10-E9 0 0 1.156 5.778 E11
E11/(1.156) 0 0 1 4.998 3rd Piv eqn
The triangular form of the system can be summarized as
x 1+ 0.250 x2 +0.500 x 3=5.250
x 2−1.556 x 3=−4.778
x 3=4.998
Solving by back substitution, we have, x 3=4.998
x 2=−4.778+1.556 ( 4.998 )=2.999
x 1=5.250−0.250 ( 2.999 )−0.5 ( 4.998 )=2.001
b. Justification: E 1 :4 ( 2.001 ) +2.999+ 2 ( 4.998 )=20.999 ≅ 21
E 2 :2 ( 2.001 )−2(2.999)+2 ( 4.998 )=8.000 ≈ 8
E 3 :2.001−2(2.999)+ 4 ( 4.998 )=15.995 ≈ 16
c. >> A = [4,1,2; 2, -2,2;1, -2,4];
>> B = [21; 8; 16];
>> Solution = A\B
Solution = 2.000, 3.000, 5.000
Partial pivoting is adequate for most of the simultaneous equations which arise in practice. But
we may encounter sets of equations where wrong or incorrect solutions may result. To
improve the calculation in such cases total pivoting is used. In total pivoting, maximum
magnitude of the coefficients of the variables is used for the pivot in each elimination.
2.3 Solution of Linear System by Iterative Method
To solve a linear system by iteration, we solve each equation for one of the variables, in turn,
in terms of the other variables. Starting from an approximation to the solution, if convergent,
derive a new sequence of approximations. Repeat the calculations till the required accuracy is
obtained. What motivates us to use iterative schemes is the possibility that inverting A may be very
difficult, to the extent that it may be worthwhile to invert a much ‘easier’ matrix several times, rather
than inverting A directly only once.
An iterative method converges, for any choice of the first approximation, if every equation
satisfies the condition that the magnitude of the coefficient of solving variable is greater than
the sum of the absolute values of the coefficients of the other variables. A system satisfying
this condition is called diagonally dominant. A linear system can always be reduced to
diagonally dominant by elementary operations.
For example, in the system x +2 y+10 z=10 (E1) |1|<|2|+|10|
x−10 y−z =24 (E2) |−10|>|1|+|−1|
11 x +5 y+ 8 z=31 (E3) |8|<|11|+|5|
is not diagonally dominant. Rearranging as (E3) - (E1), (E2), (E1), we have
10 x+ 3 y−2 z =21 |10|>|3|+|−2|
x−10 y−z =24 |−10|>|1|+|−1|
x +2 y+10 z=10 |10|>|1|+|2|
The system reduces to diagonally dominant form.
2.3.1. Jacobi Iterative Method:
4
Spring 2024-2025
In this method, a fixed set of values is used to calculate all the variables and then repeated for
the next iteration with the values obtained previously. The iterative formulas of the above
1
system are x n+1= ( 21−3 y n +2 zn )
10
−1
y n +1=
10
( 24−x n+ zn )
1
z n+1= ( 10−x n−2 y n )
10
The Gauss-Seidel iterative method is more efficient than Jacobi’s iterative method and
explained through an example.
2.3.2. Gauss-Seidel Iterative Method
In this method, the value of each variable is calculated using the most recent approximations
to the values of the other variables. The Gauss-Seidel iterative formulas of the above system
1
are x n+1= ( 21−3 y n +2 zn )
10
−1
y n +1=
10
( 24−x n+1 + z n )
1
z n+1= ( 10−x n+ 1−2 y n+1 )
10
If initial values are not supplied, we can start with initial values-
x 0=0 , y 0=0 , z 0=0.
and perform the iterations until required accuracy is achieved.
8 x 1 +2 x 2+3 x 3=51 Eq(1)
Example 2.4: Given the linear system 2 x 1+5 x 2 + x 3=23 Eq(2)
−3 x 1+ x 2 +6 x 3=20 Eq(3)
a. Reduce the above system to diagonally dominant form.
b. Write the corresponding Gauss-Seidel iteration formula.
c. Compute three iterations to estimate the roots to 2 d.p. with x 0=0 , y 0=0 and z 0=0 .
d. Write MATLAB code to iterate the above formula four times.
Solution:
a. Eq (1) 8 x 1+ 2 x 2 +3 x3 =51 , ⌊ 8 ⌋ ≥ ⌊ 3 ⌋ + ⌊ 3 ⌋
Eq (2) 2 x1 +5 x 2+ x3 =23 , ⌊ 5 ⌋ ≥ ⌊ 2 ⌋ + ⌊ 1 ⌋
Eq (3) −3 x 1+ x 2 +6 x 3=20 , ⌊ 6 ⌋ ≥ ⌊−3 ⌋ + ⌊ 1 ⌋
1
b. Gauss-Seidel formula
n+1
x1 =
8
[ 51−2 x 2−3 x 3 ]
n n
1
n+1
x2 =
5
[ 23−2 x n+1
1 −x 3 ]
n
1
x 3 = [ 20+3 x 1 −x 2 ]
n+1 n+1 n +1
6
c. Starting with initial values x 01=0 , x 02=0 , x 03=0
5
Spring 2024-2025
1
When n=0, we have
1
x 1= [ 51−2 (0)−3(0) ]=6.375
8
1
x 2= [ 23−2(6.375)−0 ] =2.050
1
5
1
x 3= [ 20+ 3(6.375)−2.050 ] =6.179
1
6
1
x 1= [ 51−2 (2.050)−3(6.179) ] =3.545
2
For n=1, we have
8
1
x 2= [ 23−2(3.545)−6.179 ] =1.946
2
5
1
x 3= [ 20+ 3(3.545)−1.946 ] =4.782
2
6
1
x 1= [ 51−2 (1.946)−3(4.782) ] =4.095
2
For n=2, we have
8
1
x 2= [ 23−2(4.095)−4.782 ] =2.006
2
5
1
x 3= [ 20+ 3(4.095)−2.006 ] =5.046
2
6
Solution to 2 d.p. is x 1=4.10 , x 2=2.01 , x3 =5.05 .
d. >> x1(1) = 0;
>> x2(1)=0;
>> x3(1)=0;
>> iter(1)=0;
>> for n=1:4
iter(n+1)=n;
x1(n+1)=(16+3*y(n)-2*z(n))/8;
y1(n+1)=(-9+2*x(n+1)-z(n))/8;
z1(n+1)=(1+2*x(n+1)-4*y(n+1))/10;
end
>> Solution = [iter, 'x1',y1',z1']
Solution =
0 0 0 0
1.0000 6.3750 2.0500 6.1792
2.0000 3.5453 1.9460 4.7816
3.0000 4.0954 2.0055 5.0468
4.0000 3.9811 1.9982 4.9908
Exercise-2
1. A chemist has 3 different acid solutions. The first acid solution contains 10 % acid,
the second contains 40 % and the third contains 60 % acid. The chemist wants to use
all 3 solutions to obtain a mixture of 100 liters containing 45 % acid. The supply of
40 % acid is low. Consequently, 10 % solution must be used twice as much as 40 %
solution. How many liters of each solution should be used?
Answer: 10% acid = 25 unit; 40% acid = 25/2 unit; 60% acid = 125/2 unit
2. A movie theater is filled the capacity of 350. The theater charges 40 taka for children,
6
Spring 2024-2025
70 for students and 125 for adults. There are half as many adults as there are students.
If the total ticket sales were 24150 takas, how many children, students and adults
attended?
3 a . 5 x−4 y+ 3 z =21, 2 x+ 3 y +2 z=20 , 8 x +2 y+ z =13.
b . 3 x−4 y+ 6 z=12 ,7 x + y−5 z=18 , 2 x+ 9 y+ 4 z=14.
.
c .2 x + y−3 z=17 , 5 x−2 y +3 z=6 , x−8 y + z=11.
d . 3 x− y+ 14 z=7 , 2 x +2 y +3 z=0 , x−12 y−18 z=33.
i. Solve the above linear system using Gaussian elimination with pivoting
(partial/total).
ii. Justify your result by direct substitution in the original equations.
iii. Write MATLAB codes to solve by left division (backslash) operator.
4 a . x +8 y +3 z=10 ,3 x−5 y +7 z=4 , 3 x− y−z=1 .
using x 0=0.85 , y 0=0.8∧z 0=0.75
.
b . 2 x+10 y −7 z=20 ,3 x−7 y−5 z=18 , 8 x −5 y −2 z =12.
using x 0=0.6 , y 0 =−0.1∧z 0=−3.
c .5 x +9 y +12 z=9 , 8 x−4 y−11 z=14 ,−2 x +5 y + z=10 .
using x 0=0.75 , y 0=2.5∧z 0=−1.5 .
i. Reduce the above system to diagonally dominant form.
ii. Write the corresponding Gauss-Seidel and Jacobi iteration formula.
iii Compute two iterations to estimate the roots to 3 d.p. with the given initial values.
.
iv. Justify your result by direct substitution in the original equations.
v. Write MATLAB codes to solve by left division (backslash) operator.
5 Consider the linear system: 4 x+ 2 y + z=7 ,6 x +5 y +3 z=4 ,16 x +5 y +7 z=3
.
i. Reduce the above system to diagonally dominant form.
ii. Write the corresponding Gauss-Seidel iteration formula.
iii Compute two iterations to estimate the roots to 2 d.p with the following initial
. values x = 2, y = 1, z= -6.
iv. Justify your result by direct substitution in the original equations.
v. Write MATLAB codes to iterate the above formula four times.
6. Determine the loop currents I 1 , I 2∧I 3 of the given circuit by solving the linear system using
Gaussian elimination with pivoting-
7
Spring 2024-2025
For loop 1: I 1−I 2+ I 3=0
For loop 2: 3 I 1 +2 I 2=7
For loop 3: 2 I 2 + 4 I 3 =8
7. Given the linear system: 10 x+ 5 y+3 z=21 , 6 x +3 y−7 z=22 , 3 x +16 y + 4 z=14.
i. Use Gaussian elimination with partial pivoting to solve the system giving results to
2 d.p.
ii. Reduce the above system to diagonally dominant form and write the corresponding
Gauss- Seidel iteration formula.
iii. Compute one iterations to estimate the solutions to 2 d.p. with x 0=2 , y 0=0.8 , z 0=−1.
iv. Write MATLAB codes to solve by left division (backslash) operator.
8. Given the linear system: 6 x +5 y−8 z=24 ,10 x +3 y +4 z =11, 8 y+3 z=10.
i. Use Gaussian elimination with partial pivoting to solve the system giving results to
2 d.p.
ii. Reduce the above system to diagonally dominant form and write the corresponding
Gauss-Seidel iteration formula.
iii. Compute one iterations to estimate the solutions to 2 d.p. with x 0=1 , y 0=1.5 ,
¿ z 0=−1.
iv. Write MATLAB codes to solve by left division (backslash) operator.
9. Tracy, Danielle and Sherri bought snacks for a birthday party. They each bought the items
shown in the following table at the local convenience store. Find the price of each item.
Number of bags of Number of litres of Number of Cost
potato chips pop chocolate bars ($)
2 9 5 21.00
3 2 10 20.88
8 3 4 13.17
i. Construct the system of linear equation from the above problem.
ii. Reduce the system obtained in (i) to diagonally dominant form.
iii. Write the corresponding Gauss-Seidel iteration formula.
iv. Compute two iterations to estimate the roots to 2 d.p using the following initial values
x 0=0.2 , y 0=1.25∧z 0=1 .65
v. Justify your result by direct substitution in the original equations.
vi. Write MATLAB codes to iterate the above formula four times.
10. Jesse, Maria and Charles went to the local craft store to purchase supplies for making
decorations for the upcoming dance at the high school. Jesse purchased three sheets of craft
8
Spring 2024-2025
paper, four boxes of markers and five glue sticks. His bill, before taxes, was $24.40. Maria
spent $30.40 when she bought six sheets of craft paper, five boxes of markers and two glue
sticks. Charles, purchases totaled $13.40 when he bought three sheets of craft paper, two
boxes of markers and one glue stick. Determine the unit cost of each item.
i. Construct the system of linear equation from the above problem.
ii. Solve the system of linear equation using Gaussian elimination with partial pivoting.
iii. Write MATLAB codes to solve by left division (backslash) operator.
11. Cory, Josh, and Dan went shopping for Halloween treats. Cory bought 3 chocolate
pumpkins, 4 masks and 8 candy witches. He spent $36.65. Josh bought 5 chocolate
pumpkins,3 masks and 10 candy witches. He spent $37.50. Dan bought 4 chocolate
pumpkins, 5 masks and 6 candy witches. He spent $43.45. and algebraically.
i. Write a system of equations to represent this problem.
ii. Calculate the unit price of each item purchased using Gaussian elimination
with pivoting.
iii. Write MATLAB codes to solve by left division (backslash) operator.
Answer: 2.55 , 5.75 , 0.75
12. A local computer company sells three types of laptop computers to three nearby
stores. The number of laptops ordered by each store and the amount owing to the
company for the order is shown in the following table:
Store Laptop A Laptop B Laptop C Amount Owing ($)
Wal-Mart 10 8 6 21 200
Sears 7 9 5 18 700
Target 8 4 3 13 000
i. Write a system of equations to represent the above information.
ii. Solve the system of linear equation using Gaussian elimination with partial pivoting.
iii. Write MATLAB codes to solve by left division (backslash) operator.
13. Consider the linear system: 5 x+ 2 y + z=7 ,2 x−4 y +3 z=6 , 3 x+5 y +7 z=6
i. Reduce the above system to diagonally dominant form.
ii. Write the corresponding Gauss-Seidel iteration formula.
iii. Compute two iterations to estimate the roots to 3 d.p.
iv. Justify your result by direct substitution in the original equations.
v. Write MATLAB codes to iterate the above formula four times.
Answer: x=1.453 , y=−0.389 , z=0.512
14. The following system of equations was generated by applying the mesh current law in the
circuit shown in the adjacent figure.
35 ( I 1−I 2) + 40 ( I 1−I 3 ) =20 35 Ω I2
30 Ω
20 V 2Ω
35 ( I 2−I 1) + 30 I 2 +2 ( I 2−I 3 ) =0 I1
9
40 Ω I3 45 Ω
Spring 2024-2025
40 ( I 3−I 1 ) +2 ( I 3−I 2 ) + 45 I 3 =0
i. Write down the system in simplified form.
ii. Solve the system of equations using Gauss-Seidel iteration correct to 2 decimal places.
15. Given the linear system: 9 x +5 y+ 3 z =20 ,5 x +4 y−7 z=21 , 3 x + 9 y + 4 z=16.
i. Use Gaussian elimination with partial pivoting to solve the system giving results to
2 d.p.
ii. Reduce the above system to diagonally dominant form and write the corresponding
Gauss- Seidel iteration formula.
iii. Compute one iterations to estimate the solutions to 2 d.p. with
x 0=1.5 , y 0=1.6 , z 0=−1.
iv. Write MATLAB codes to solve by left division (backslash) operator.
Answer: x=1.61 , y=1.64 , z=−0.91
16. Given the linear system: 6 x +5 y−8 z=14 ,8 x +3 y +4 z =16 , 2 x +7 y +3 z=12.
i. Use Gaussian elimination with partial pivoting to solve the system giving results to
2 d.p.
ii. Reduce the above system to diagonally dominant form and write the corresponding
Gauss-Seidel iteration formula.
iii. Compute one iterations to estimate the solutions to 2 d.p. with x 0=1.4 , y 0 =1.2 ,
¿ z 0=0.2 .
iv. Write MATLAB codes to solve by left division (backslash) operator.
Answer: x=1.47 , y=1.24 , z =0.1
17. An electronics company produces transistors, resistors, and computer chips. Each
transistor requires four units of copper, one unit of zinc, and two units of glass. Each resistor
requires three, three and one units of the three materials, respectively, and each computer chip
requires two, one, and three units of these materials, respectively. Putting this information into
table form, we get:
Component Copper Zinc Glass
Transistors 4 1 2
Resistors 3 3 1
Computer chips 2 1 3
Supplies of these materials vary from week to week, so the company needs to determine a
different production run each week. For example, one week the total amounts of materials
available are 960 units of copper, 510 units of zinc, and 610 units of glass. Set up the system
of equations modeling the production run, and use Excel, MATLAB, or Mathcad, to solve for
the number of transistors, resistors, and computer chips to be manufactured this week.
18. Andrea sells photographs at art fairs. She prices the photos according to size: small photos
cost $10, medium photos cost $15, and large photos cost $40. She usually sells as many small
photos as medium and large photos combined. She also sells twice as many medium photos as
large. A booth at the art fair costs $300.
If her sales go as usual, how many of each size photo must she sell to pay for the booth?
19. In the spirit of Christmas and New Years' resolutions, suppose that what we were on a diet
10
Spring 2024-2025
and needed to eat precisely 245 calories, 6 grams of protein, and 7 grams of fat for breakfast.
Unfortunately, I open my cupboard to see that all I have is three boxes of cereal: Cheerios,
Cinnamon Toast Crunch, and Rice Krispies. There nutritional information per serving is as
follows:
Cereal Calories Protein Fat
Cheerios 120 4 2
Cinnamon Toast Crunch 130 3 5
Rice Krispies 105 1 2
Now, normally, I would dive in and gorge myself on Cinnamon Toast Crunch because they're
delicious but, I need to stick to my new year’s resolution. Find out the quantities of food.
20. In a 3D Cartesian coordinate system, the equation of a plane is:
ax +by + cz=d .
Given three points, ( 2 ,−3 ,−2 ) , ( 5 , 2 ,1 )∧(−1 , 5 , 4), determine the equation of the plane that
passes through the points.
[Ref. Numerical methods for Engineers and Scientists – Amos Gilat, Vish Subramaniam, Page
159 ex-4.30]
11