# Sparse Matrix inversion some time singular some time get a big value

I want to invert a matrix which is a "band" diagonal matrix. The structure of the matrix is

The blue strip represents the elements that are non zero.All other element in white area are of zero value.

I write down the code in java to represent non zero elements.

 import org.ujmp.core.Matrix;

public class Omegatest {
public static void main(String args[])throws Exception{
Matrix omega= Matrix.Factory.zeros(2000,2000);
Matrix Bigomega=Matrix.Factory.zeros(2000,2000);
for(int k1=0;k1<1999;k1++){
omega.setAsDouble(1, k1, k1);
omega.setAsDouble(-1, k1, k1 + 1);
omega.setAsDouble(-1, k1 + 1, k1);
omega.setAsDouble(1, k1 + 1, k1 + 1);
Bigomega = Bigomega.plus(omega);
omega.clear();
}
System.out.println(Bigomega.inv());

}


}

Now whenever I try to invert this matrix, it gives me an error that the matrix is singular.

If I slightly change the code and take two Sparse Matrix instead of normal matrix it gives me a big value like 1902.003 1903.005 in each cells.

I know there is a definite problem in the code.

But first I want to know the mathematical explanation of this two conditions.

Thank you.

• Is it a full rank matrix? In other words, if I am interpreting it correctly, the size of this square matrix is $2000 \times 2000$. If correct, then the rank should be $2000$. Also, you can check whether all the absolute of eigenvalues are positive $|\lambda_i| > 0$ and the condition number is low, i.e., $\frac{\max\{|\lambda_i|\}}{\min\{|\lambda_i|\}}$... – user550103 Aug 5 '18 at 10:50
• Yes it is a square matrix with 2000*2000 dimension – Encipher Aug 5 '18 at 12:37
• Ok. The rank of a matrix? If it's less than 2000, then you have a problem with the invertibility. – user550103 Aug 5 '18 at 12:40
• As per my programming the rank should be 2000. If its rank < 2000 that means its determinant are zero right. – Encipher Aug 5 '18 at 14:13
• yes, if it's low rank, then the determinant will be zero (i.e., some eigenvalues are zero). If the eigenvalues are nearly zero (but not really zero), then the condition number of a matrix might be high which causes the numerical problem with the inversion of a matrix. – user550103 Aug 5 '18 at 14:43

The sum of the elements in each row (or column) is zero, hence the matrix is not invertible. The matrix looks like this $$\pmatrix{ 1 & -1 \\ -1 & 2 & -1 \\ &\ddots& \ddots&\ddots\\ &&\ddots& \ddots&\ddots\\ &&&-1 & 2 & -1 \\ &&&&1 & -1 }$$