L2 Piv Partiala Eng
L2 Piv Partiala Eng
Gauss method with partial pivoting at every step for to solve the systems of linear equations
where A ∈ Rn×n is the matrix of system(1) and b ∈ Rn is the free term of system (1).
The target is to determine, if it is possible, x ∈ Rn , where x is the unique solution of the system (1).
Presentation of the method:
We consider the augmented matrix (A | b) = (aij ) 1≤i≤n , where ai,n+1 = bi , 1 ≤ i ≤ n.
1≤j≤n+1
The Gauss method consists of processing the augmented matrix (A | b) such that, in n − 1 steps the matrix
A becomes upper-triangular:
a(n)
(n) (n)
(n) (n)
a a12 ... a1,n−1 a1,n 1,n+1
11
0 a(n) (n) (n)
a(n)
22 ... a2,n−1 a2,n 2,n+1
. . .. .. = A(n) , where A(1) = (A | b).
(2) ..
..
.
... .
(n)
(n) (n)
an−1,n+1
0 0 ... an−1,n−1 an−1,n
(n) a(n)
0 0 ... 0 an,n n,n+1
(k) (k)
If akk 6= 0, 1 ≤ k ≤ n − 1, where the element akk is called pivot, for to obtain the matrix (2) we apply the
following formulas:
(k)
aij
1 ≤ i ≤ k, i ≤ j ≤ n + 1
(3)
(k+1)
aij = 0 1 ≤ j ≤ k, j + 1 ≤ i ≤ n
(k)
(k) a
a − (k) · a (k)
ik
k + 1 ≤ i ≤ n, k + 1 ≤ j ≤ n + 1.
ij kj akk
The solution components of system (1) are directly obtained by back substitution
(n)
xn = an,n+1 a(n) if a(n)
(4) nn , nn 6= 0,
for i = n − 1, n − 2, ..., 1
n
(n) (n) (n)
X
(5) xi = ai,n+1 − aij · xj aii .
j=i+1
(k)
FAt every step ”k” we search, on the column k, under the row ”k”, the element aik ,k , k ≤ ik ≤ n,
with property
(k) (k)
a
ik k = max ik .
a
k≤i≤n
Remarks:
(k)
1) If aik ,k = 0, then the system (1) does not have unique solution.
(k)
2) If aik ,k 6= 0 and ik 6= k then we interchange the row k with row ik in the matrix A(k) . Next, we apply
the formulas (3) and, finally (4).
1
Pseudocod Algorithm
1. read n, aij , 1 ≤ i ≤ n, 1 ≤ j ≤ n + 1
2. for k = 1, 2, ..., n − 1 execute
2.1. piv ← |akk |
2.2. lin ← k
2.3. for i = k + 1, k + 2, ..., n execute
2.3.1. if piv < |aik | then
2.3.1.1. piv ← |aik |
2.3.1.2. lin ← i
2.4. if piv = 0 then
2.4.1. write ’The system does not have unique solution’
2.4.2. return
2.5. if lin 6= k then
2.5.1. for j = k, k + 1, ..., n + 1 execute
2.5.1.1. aux ← akj
2.5.1.2. akj ← alin,j
2.5.1.3. alin,j ← aux
2.6. for i = k + 1, k + 2, ..., n execute
2.6.1. aik ← aik /akk
2.6.2. for j = k + 1, k + 2, ..., n + 1 execute
2.6.2.1. aij ← aij − aik · akj
3. dacă ann = 0 then
3.1. write ’The system does not have unique solution’
3.2. return
4. an,n+1 ← an,n+1 /ann
5. for i = n − 1, n − 2, ..., 1 execute
5.1. S ← 0
5.2. for j = i + 1, i + 2, ..., n execute
5.2.1. S ← S + aij · aj,n+1
5.3. ai,n+1 ← (ai,n+1 − S)/aii
6. write 0 xi =0 , ai,n+1 , 1 ≤ i ≤ n.
Example: Solve the following linear systems using the Gauss method with partial pivoting at every step
2x1 + 2x2 + 3x3 + x4 = 6 −2x1 + x3 = 1
( (
2x + 3y − z = 4
3x 1 +
a) x + x = 03x 2 + 2x 3 + x 4 = 2 x 1 + 4x 2
b) 2x − 3x = −3 + x 4 = −3 c) x − 2y + z = 6
1 4 1 4 −x − 12y + 5z = 10.
x1 + x2 + x3 = 2 −2x1 + x3 + x4 = 2