function x=inv_gaussjordan(a)
  n=length(a);
  np1=n+n;
  carpan=0;
  C=a;
  I=eye(n);
  for i=1:n
    for k=n+1:np1
      C(i,k)=I(k-n,i);
    end
  end
  C
  for k=1:np1
    %gauss jordan elimination
    for j=k+1:np1
      C(k,j)=C(k,j)/C(k,k);
    endfor
    for i=1:n
      if i~=k 
         carpan=C(i,k);
          C(i,k)=0;
          for j=k+1:np1
            C(i,j)=C(i,j)-carpan*C(k,j); 
          endfor
       endif    
    endfor
  endfor
  for i=1:n
    for j=n+1:np1
   C(i,i)=1;   
   x(i,j-n)=C(i,j);
  endfor
  end  

