You are on page 1of 2

Example for Gaussian Elimination with Pivoting

   
0 0 1 1 x1 0
 −1 1 0 0   x2   1 
Solve the linear system    =  . Use the pivot candidate with the largest absolute value.
 1 3 1 0   x3   2 
2 1 1 1 x4 4

Gaussian Elimination for matrix A:

Initialize L,U, p. Then select pivot for column 1:


     
0 0 0 0 0 0 1 1 1
 0 0 0 0   −1 1 0 0   2 
L=  0 0 0
, U =
 1 3 1 0 ,
 p= 
0   3 
0 0 0 0 2 1 1 1 4

Move pivot for column 1 in position: interchange rows 1 and 4


     
0 0 0 0 2 1 1 1 4
 0 0 0 0   −1 1 0 0   2 
L=  0 0 0 0 ,
 U = , p= 
 3 
 1 3 1 0 
0 0 0 0 0 0 1 1 1

Elimination in column 1. Then select pivot for column 2


 
2 1 1 1
  
0 0 0 0 4
3 1 1
 −1 0 0 0   0
2 2 2
  2 
L= 2 , U =

,

p= 
 1 0 0 0   0 5 1
− 12  3 
2 2 2 
0 0 0 0 0 0 1 1 1

Move pivot for column 2 in position: interchange rows 2 and 3


 
2 1 1 1
  
0 0 0 0 4
 1 0 0 0 

0 5 1
− 12 
  3 
L= 2 2 2
 −1 0 0 0 , U = , p=
  
3 1 1   2 
2  0 2 2 2
0 0 0 0 0 0 1 1 1

Elimination in column 2. Then select pivot for column 3


 

0 0 0 0
 2 1 1 1 
4

1 5 1
0 0 0   0 − 12   3 
  
L= 2 2 2
 −1 3 0 0 , U = , p=
 
 0 1 4   2 
2 5 0 5 5
0 0 0 0 0 0 1 1 1

Move pivot for column 3 in position: interchange rows 3 and 4


 

0 0 0 0
 2 1 1 1 
4

 1 0 0 0 

0 5 1
− 12 
  3 
L= 2 , U =
 2 2 , p= 
 0 0 0 0    1 
 0 0 1 1 
− 12 35 0 0 0 0 1 4 2
5 5
Elimination in column 3
 
  2 1 1 1  
0 0 0 0 4
5 1
1  0 − 12
 

2 0 0 0  2 2   3 
L= , U = , p= 
 0 0 0 0   0 0 1 1   1 
− 12 3 1
 
5 5 0 0 0 0 3 2
5

The last pivot is 35 . This is nonzero, so the algorithm succeeded. Therefore A is nonsingular.
 
1 0 0 0
 1 1 0 0 
Finally put 1’s on the diagonal of L, yielding L =  2
 0 0 1 0 .

− 12 35 15 1
Given b, use L,U, p to solve linear system:
 
b p1
Solve Ly =  ...  by forward substitution:
 

b pn
      
1 0 0 0 y1 4 4
 1 1 0 0   y2   2   0 
Solving  2  =  gives y= 
 0 0 1 0   y3   0   0 
− 21 3
5
1
5 1 y4 1 3

Solve Ux = y by back substitution:


      
2 1 1 1 x1 4 1
5 1
 0
2 2 − 12   x2   0 
= 
 2 
Solving 
 0

  0  gives x= 
 −5 
0 1 1   x3
3 x4 3 5
0 0 0 5

How to do this in Matlab:

>> A = [0 0 1 1; -1 1 0 0; 1 3 1 0; 2 1 1 1]
A =
0 0 1 1
-1 1 0 0
1 3 1 0
2 1 1 1
>> [L ,U , p ] = lu (A , ’ vector ’)
L =
1 0 0 0
0.5 1 0 0
0 0 1 0
-0.5 0.6 0.2 1
U =
2 1 1 1
0 2.5 0.5 -0.5
0 0 1 1
0 0 0 0.6
p =
4 3 1 2
>> b = [0;1;2;4];
>> y = L \ b ( p )
y =
4
0
0
3
>> x = U \ y
x =
1
2
-5
5

You might also like