Hello guys I am writing program to compute determinant(this part i already did) and Inverse matrix with GEPP. Here problem arises since i have completely no idea how to inverse Matrix using GEPP, i know how to inverse using Gauss Elimination ([A|I]=>[I|B]). I have searched through internet but still no clue, could you please explain me?
Here is my matlab code (maybe someone will find it useful), as of now it solves AX=b and computes determinant:
function [det1,X ] = GEPP( A, b )
%GEPP
perm=0;
n = length(b);
if n~=m
error('vector has wrong size');
end
for j = 1:n
p=j;
% choice of main element
for i = j:n
if abs(A(i,j)) >= abs(A(p,j))
p = i;
end
end
if A(p,j) == 0
error('Matrix A is singular');
end
%rows permutation
t = A(p,:);
A(p,:) = A(j,:);
A(j,:) = t;
t = b(p);
b(p) = b(j);
b(j) = t;
if~(p==i)
perm=perm+1;
end
% reduction
for i = j+1:n
t = (A(i,j)/A(j,j));
A(i,:) = A(i,:)-A(j,:)*t;
b(i) = b(i)-b(j)*t;
end
end
%determinant
mn=1;
for i=1:n
mn=mn*A(i,i);
end
det1=mn*(-1)^perm;
% solution
X = zeros(1,n);
X(n) = b(n)/A(n,n);
if (det1~=0)
for i = 1:n
s = sum( A(i, (i+1):n) .* X((i+1):n) );
X(i) = (b(i) - s) / A(i,i);
end
end
end
It really is no different than doing Gaussian Elimination with Pivoting, but repeating each step to an augmented matrix.
We would set up and do GEPP to both sides of the augmented matrix $[A | I]$.
If the matrices condition number plays nice, we will end up with $[I | A^{-1}]$. Note, I would recommend you also look into the Crout and the Doolittle procedures as better alternatives! Also, it is worth noting that you must be careful with single precision, rounding and numerical issues!
So, lets do a difficult example of what I described above so you can see it in practice (so, just take whichever variant of GEPP you are using and set up the augmented matrix as above and see if you end up with the inverse as I show below).
$$A = \left[\begin{array}{ccccc} 1 & 1/2 & 1/3 & 1/4 & 1/5 \\ 1/2 & 1/3 & 1/4 & 1/5 & 1/6 \\ 1/3 & 1/4 & 1/5 & 1/6 & 1/7 \\ 1/4 & 1/5 & 1/6 & 1/7 & 1/8 \\ 1/5 & 1/6 & 1/7 & 1/8 & 1/9 \end{array}\right]$$
Do pivoted Gaussian Elimination (row reduction):
Setup the augmented matrix $[A | I]$ as:
$$\left[\begin{array}{ccccc|ccccc} 1 & 1/2 & 1/3 & 1/4 & 1/5 & 1 & 0 & 0 & 0 & 0\\ 1/2 & 1/3 & 1/4 & 1/5 & 1/6 & 0 & 1 & 0 & 0 & 0\\ 1/3 & 1/4 & 1/5 & 1/6 & 1/7 & 0 & 0 & 1 & 0 & 0\\ 1/4 & 1/5 & 1/6 & 1/7 & 1/8 & 0 & 0 & 0 & 1 & 0\\ 1/5 & 1/6 & 1/7 & 1/8 & 1/9 & 0 & 0 & 0 & 0 & 1 \end{array}\right]$$
Perform the following GEPP steps:
Our final solution using GEPP gives us (in this case), the desired $[I | A^{-1}]$ as:
$$\left[\begin{array}{ccccc|ccccc} 1 & 0 & 0 & 0 & 0 & 25 & -300 & 1050 & -1400 & 630\\ 0 & 1 & 0 & 0 & 0 & -300 & 4800 & -18900 & 26880 & -12600\\ 0 & 0 & 1 & 0 & 0 & 1050 & -18900 & 79380 & -117600 & 56700\\ 0 & 0 & 0 & 1 & 0 & -1400 & 26880 & -117600 & 179200 & -88200\\ 0 & 0 & 0 & 0 & 1 & 630 & -12600 & 56700 & -88200 & 44100 \end{array}\right]$$