Lecture Note 2 Spring 20

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Spring 2019-20

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
term in the equation above it.

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 upper triangular form. The back substitution is then used to solve the
system in reverse order.

2.2 Pivotal Elimination Method

Computers and calculators use fixed number of digits in its calculation and we may need to
round the numbers. This introduces error 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.

Page 1 of Lecture 2
Spring 2019-20

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
(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=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
1002×102 y≈1003×10 2
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
m2= ≈0 . 0007092
4 . 230
The replacement of (E4) by ( E 4 −m2×E 3) reduces the system t0
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.

Page 2 of Lecture 2
Spring 2019-20

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
(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.2 : The currents running through an electrical system are given by the
following system of equations.  The three currents, I1, I2, and I3, are measured in amps. 
8 I 1+ 3 I 2−5 I 3=3
10 I 1 +7 I 2+ 2 I 3=4 .
6 I 1 + 4 I 2 +7 I 3=8
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.
Oper I1 I2 I3 Constan Eqn #  
t
8 3 -5 3 E1
10 7 2 4 E2
  6 4 7 8 E3
E2/10 1.000 0.700 0.200 0.400 E4 1st Piv eqn
E1/8 1.000 0.375 -0.625 0.375 E5
E3/6 1.000 0.667 1.167 1.333 E6  
E5-E4 0 -0.325 -0.825 -0.025 E7
E6-E4 0 -0.033 0.967 0.933 E8
E7/(-0.325) 0 1 2.538 0.0769 E9 2nd Piv eqn
E8/(-0.03) 0 1 - -31.1 E10
32.233
E9/2.538 0 0 34.771 31.177
E10/(- 0 0 1 0.897 3rd Piv eqn
32.233)
The triangular form of the system can be summarized as
I 1+ 0.7 I 2 +0.2 I 3 =0.4
I 2+ 2.538 I 3=0.077
I 3=0.8907
Solving by back substitution, we have, I 3=0.8907
I 2=0.077−2.538 ( 0.890 )=−2.182
I 1=0.4−0.7 (−2.182 )−0.2 ( 0.8907 )=1.759
b. Justification: E 1: 8 (1.759 )+3 (−2.182 ) −5 ( 0.8907 )=3.01 ≅ 3
E 2 :10 ( 1.759 ) +7 (−2.182 ) +2 ( 0.8907 ) =4.02 ≈ 4
E 3 :6 ( 1.759 ) +4 (−2.182 )+7 ( 0.8907 )=8.01 ≈ 8
c. >> A=[8 3 -5; 10 7 2; 6 4 7];

Page 3 of Lecture 2
Spring 2019-20

>> b=[3; 4; 8];


>> Solution = A\b
Solution = 1.7500, -2.1829, 0.8902
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 results. 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

Iterative method for linear system is similar as the method of fixed-point iteration for an
equation in one variable. 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.
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:

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 z n )
10
−1
y n+ 1= ( 24−x n+ z n )
10
1
z n+1= ( 10−x n−2 y n )
10
Gauss-Seidel iterative method is more efficient than Jacobi’s iterative method and explained
through an example.

2.3.2. Gauss-Seidel Iterative Method

Page 4 of Lecture 2
Spring 2019-20

In this method, the values 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 z n )
10
−1
y n+ 1= ( 24−x n+1 + z n )
10
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.

6 x+5 y +3 z=7 Eq(1)


Example 2.2: Given the linear system 8 x−3 y +2 z=16 Eq(2) .
10 x−7 y−8 z=15 Eq(3)
a. Reduce the above system to diagonally dominant form.
b. Write the corresponding Gauss-Seidel iteration formula.
c. Compute two iterations to estimate the roots to 2 d.p. with x 0=1.5 , y 0=−1 and z 0=1
.
d. Write MATLAB code to iterate the above formula four times.

Solution:
a. Eq(2) 8 x−3 y +2 z=16 , ⌊ 8 ⌋ ≥ ⌊−3 ⌋+ ⌊ 2 ⌋
Eq(1)-Eq(2) −2 x+ 8 y+ z =−9 , ⌊ 8 ⌋ ≥ ⌊−2 ⌋ + ⌊ 1 ⌋
Eq(2)-Eq(3) −2 x+ 4 y +10 z=1 , ⌊ 10 ⌋ ≥ ⌊−2 ⌋ + ⌊ 4 ⌋

1
b. Gauss-Seidel formula x n+1= [ 16+3 y n−2 z n ]
8
1
y n+ 1=[−9+2 x n+1−z n ]
8
1
z n+1= [1+2 x n+1−4 y n +1 ]
10

c. Starting with initial values x 0=1.5 , y 0=−1 , z 0=1

1
When n=0, we have x 1= [ 16+3 (−1 ) −2 ( 1 ) ] =1.375
8
1
y 1= [− 9+2 (1.375 )−1 ] =−0.906
8
1
z 1= [ 1+2 (1.375 )−4 (−0.906 ) ]=0.737
10
1
For n=1, we have x ❑2= [ 16+3 (−0.906 )−2 ( 0.737 ) ] =1.476
8
1
y 2= [− 9+2 (1.476 )−−0.906 ] =−0.848
8
1
z 2= [ 1+2 (1.476 )−4 (−0.848 ) ]=0.734
10
Solution to 2 d.p. is x=1.48 , y=−0.85, z=0.73 .

Page 5 of Lecture 2
Spring 2019-20

d. >> x(1)=1.5;
>> y(1)=-1;
>> z(1)=1;
>> iter(1)=0;
>> for n=1:4
iter(n+1)=n;
x(n+1)=(16+3*y(n)-2*z(n))/8;
y(n+1)=(-9+2*x(n+1)-z(n))/8;
z(n+1)=(1+2*x(n+1)-4*y(n+1))/10;
end
>> Solution = [iter',x',y',z']
Solution =
0 1.5000 -1.0000 1.0000
1.0000 1.3750 -0.9063 0.7375
2.0000 1.4758 -0.8482 0.7345
3.0000 1.4983 -0.8422 0.7366
4.0000 1.5000 -0.8421 0.7368

Exercise-2

1 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.
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.
.

2 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.
3 Consider the linear system: 4 x+2 y + z=7 , 4 x+5 y +3 z=4 , 4 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=-0.75, z=-0.2.
iv Justify your result by direct substitution in the original equations.

Page 6 of Lecture 2
Spring 2019-20

.
v. Write MATLAB codes to iterate the above formula four times.

4. Determine the loop currents I 1 , I 2∧I 3 of the given circuit by solving the linear system
using Gaussian elimination with pivoting.
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

5. 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.

6. 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.

7. 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:

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 obtain in (i) to diagonally dominant form.
iii. Write the corresponding Gauss-Seidel iteration formula.

Page 7 of Lecture 2
Spring 2019-20

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∧z0 =165..
v. Justify your result by direct substitution in the original equations.
vi. Write MATLAB codes to iterate the above formula four times.

8. 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
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.

9. 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.

i. Write a system of equations to represent this 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.

10. 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.

11 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
Page 8 of Lecture 2
Spring 2019-20

12 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

13. 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

40 ( I 3−I 1 ) +2 ( I 3 −I 2 ) + 45 I 3=0 40 Ω I3 45 Ω

i. Write down the system in simplified form.


ii. Solve the system of equations using Gauss-Seidel iteration correct to 2 decimal places.

14. 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

15. 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 .

Page 9 of Lecture 2
Spring 2019-20

iv. Write MATLAB codes to solve by left division (backslash) operator.


Answer: x=1.47 , y=1.24 , z=0.13

Page 10 of Lecture 2

You might also like