Matrix inversion tool

Matrix inversion tool

Matan Ziv-Av matan at svgalib.org
Mon Aug 10 00:57:13 IDT 2015


On Sun, 9 Aug 2015, Shachar Shemesh wrote:

> I should point out that the simplified matrix I was using to prove to 
> myself that the idea has merit is 20x20 (inversed using state of the 
> art in the vi text editing front). The code I'll actually have to run 
> will be 273x273. The Matrix itself is sparsish, so it's really not 
> that bad. Still, to prove things are working I'll have to (probably 
> pre-calculate) several thousand such matrices.

Actually, for this specific problem, implementing Gaussian elimination 
is much better than looking for a library or a tool, and interfacing 
with it.

Untested C-Pseudo code:

Input: A,B: nxn matrices, B=I_n
Output: det(A), B=A^{-1} if A det=1

for(i=0;i<n;i++) {
   for(j=i;j<n;j++) if(A[j][i]==1) {
     ExchangeLines(A,i,j);
     ExchangeLines(B,i,j);
     break;
   }
   if(j==n) return 0;
   for(k=1;k<n;k++) if(A[k][i]==1 && k!=j) {
     AddLines(A,k,j);
     AddLines(B,k,j);
   }
}
return 1;




-- 
Matan.




More information about the Linux-il mailing list