Gauss-Jordan elimination
The method of Gauss-Jordan elimination
can be used to find the inverse
of the coefficient matrix .
Once
is available, we can simultaneously solve multiple linear
systems if they are all based on the same coefficient matrix :
|
(102) |
To do so, we first construct the augmented matrix:
|
(103) |
Pre-multiply
(assumed available) to each of its components we
would get
However, as
is unknown, the pre-multiplication by
is actually carried be applying a sequence of elementary row operations
to the augmented matrix until eventually on the left
of the augmented matrix is converted to .
|
(105) |
This conversion is done by the Gaussian elimination to eliminate all
components below the diagonal, followed by a second phase to eliminate
all components above the diagonal:
Alternatively, we could combine the two phases to simply remove all
components in the jth column (
) by
|
(108) |
Note that as the process of the elementary row operations above is applied
to all rows in the augmented matrix, it also generates at the same time the
desired solutions as well as the inverse matrix
.
As each row operation
(
) requires
multiplications, the total complexity for solving the linear system
, the same for computing
, is .
The Matlab code below implements the Gauss-Jordan method for finding the
inverse of a given square matrix :
function Ainv=GaussJordanInv(A) % Find inverse by Gaussian-Jordan elimination
[m n]=size(A);
n=2*m;
A=[A eye(m)]; % construct augmented matrix
Ainv=zeros(m);
v=[1:m]; % row permutation record
for k=1:m % for each row of A
i=v(k); % current row index
p=abs(A(i,i));
ip=k;
for l=k+1:m % find max in ith column below v(k)th row
if abs(A(v(l), v(k)))>p
p=abs(A(v(l), v(k)));
ip=l;
end
end
temp=v(k); % Switch the kth element and imaxth element in r-vector
v(k)=v(ip);
v(ip)=temp;
for i=1:m % Eliminate off-diagonal elements in v(k)th column
if i ~= k
c=A(v(i),k)/A(v(k),k);
for j=k:n
A(v(i),j)=A(v(i),j)-c*A(v(k),j);
end
end
end
end
for k=1:m
i=v(k);
[p ip]=max(abs(A(i,1:m)));
for j=1:m
Ainv(k,j)=A(i,m+j)/A(i,ip);
end
end
end
Example
|
(109) |
|
(110) |
Now we get both and
at the same time:
|
(119) |