Example For Gaussian Elimination With Pivoting
Example For Gaussian Elimination With Pivoting
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
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
>> 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