6.2 Pivoting Strategies
6.2 Pivoting Strategies
Linear systems of
Equations
(Pivoting)
Sec:6.1 Linear systems of Equations
From section 1.2, recall that the division by a small number or multiplication by a large
number can magnify the round-off error. Here an example from section 1.2:
𝒂 𝒋𝒊
𝑹𝒋 − 𝑹𝒊 → 𝑹𝒋 , 𝒊+ 𝟏 ≤ 𝒋 ≤ 𝒏
𝒂 𝒊𝒊
Elementary row
operations
In general 𝑥 = 𝑎 𝑖 , 𝑛 +1 − ∑ 𝑎𝑖 , 𝑗 𝑥 𝑗
𝑗 =𝑖+ 1
𝑖 , 𝑖 =𝑛 − 1 , 𝑛 − 2 , … , 2 , 1.
𝑎𝑖 , 𝑖
Sec:6.2 Linear systems of Equations (Pivoting)
Remark
Based on the previous discussion, we conclude that the Gaussian elimination method
may become unreliable when the nonzero pivot element is relatively too small.
In the next example, even for small systems, we will see that round-off error can dominate the
calculations when the pivot element is relatively too small.
Solution: The augmented matrix of the linear system using four-digit rounding is:
5.291
𝐸2− −2
𝐸1 → 𝐸2
|
0.3 ∗ 10
( 0 .3 ∗1 0− 2
5.291 |
59.14 5 9.17
− 6.130 46.78 ) (
0 .3 ∗1 0− 2
0
59.14 5 9.17
− 104300 − 104400 )
Sec:6.2 Linear systems of Equations (Pivoting)
Note: In the previous example, the pivot element is very small compared to 5.291. Thus,
the evaluation of the multiplier enlarged the round-off error and ruined the
approximation.
Note: In order to avoid large round-off error, we need to ensure that the pivot element is
not relatively too small.
Sec:6.2 Linear systems of Equations (Pivoting)
Example
[ ] 𝑏= 1
[]
− 20
𝐴= 10 1
1 1 0
Partial Pivoting
Before forward elimination starts, it is
advantageous to determine the coefficient
Suppose has the largest absolute value in the with the largest absolute value in the
column below the pivot element. Then we column below the pivot element. The rows
perform the row swapping: can then be swapped so that the largest
element is the pivot element.
Sec:6.2 Linear systems of Equations (Pivoting)
Example
[ ] []
𝑏= 1
− 20
𝐴= 10 1
1 1 0
R1R3 R2-(1/2)R1R2
R3-(1/4)R1R3
R4-(6/8)R1R4
R2R4
R3R4 Row
Operations
Row
Operations
Sec:6.2 Linear systems of Equations
Solution: The augmented matrix of the linear system using four-digit rounding is:
𝑅2 𝑅1
( | ) ( 5.291
|
6.130 4 6.78
)
−2
0 .3 ∗1 0 59.14 5 9.17 ↔
−2
5.291 − 6.130 46.78 0 .3 ∗ 1 0 59.14 59.17
−2
0.3 ∗ 10
𝐸2− 𝐸1 → 𝐸2
( 5.291
0 .3 ∗ 1 0− 2 |
6.130 4 6.78
59.14 59.17 ) 5.291
( 5.291
0 |
− 6.130 4 6.78
59.14 59.14 )
Sec:6.2 Linear systems of Equations
Remark
Although the Gaussian elimination with partial pivoting is a valid method for solving
many linear systems, it can be unreliable for solving some types of linear systems. For
instance, when the coefficient matrix is badly scaled; that is some of its elements are too
large compared to the other elements, the Gaussian elimination with partial pivoting may
fail. In such a case, other pivoting strategies shall be used.
Pivoting Strategies
Partial Pivoting
Complete Pivoting
Sec:6.2 Linear systems of Equations
(Pivoting
Sec:6.2 Linear systems of Equations
)
function x = gauss_elimination_pivoting(A, b)
% Get the size of the matrix A
[n, m] = size(A);
[ ] []
𝑏= 1
for i = 1:n-1
− 20
𝐴= 10 1
% Find the maximum element in the current column
1 1 0 [~, maxIndex] = max(abs(Ab(i:n, i)));
maxIndex = maxIndex + i - 1;
% Forward elimination
for j = i+1:n
factor = Ab(j, i) / Ab(i, i);
Ab(j, i:n+1) = Ab(j, i:n+1) - factor * Ab(i, i:n+1);
end
end
% Back substitution
x = zeros(n, 1);
x(n) = Ab(n, n+1) / Ab(n, n);
for i = n-1:-1:1
x(i) = (Ab(i, n+1) - Ab(i, i+1:n) * x(i+1:n)) / Ab(i, i);
end
end
Sec:6.2 Linear systems of Equations (Pivoting
)
function x = gauss_elimination_pivoting(A, b)
% Get the size of the matrix A
Find the row interchanges that are required [n, m] = size(A);
to solve the following linear systems using
% Check if A is a square matrix
Partial Pivoting if n ~= m
error('Matrix A must be square');
end
% Forward elimination
for j = i+1:n
factor = Ab(j, i) / Ab(i, i);
Ab(j, i:n+1) = Ab(j, i:n+1) - factor * Ab(i, i:n+1);
end
end
% Back substitution
x = zeros(n, 1);
x(n) = Ab(n, n+1) / Ab(n, n);
for i = n-1:-1:1
x(i) = (Ab(i, n+1) - Ab(i, i+1:n) * x(i+1:n)) / Ab(i, i);
end
end