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

enter image description here

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);



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.

  • $\begingroup$ 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|\}}$... $\endgroup$ – user550103 Aug 5 '18 at 10:50
  • $\begingroup$ Yes it is a square matrix with 2000*2000 dimension $\endgroup$ – Encipher Aug 5 '18 at 12:37
  • $\begingroup$ Ok. The rank of a matrix? If it's less than 2000, then you have a problem with the invertibility. $\endgroup$ – user550103 Aug 5 '18 at 12:40
  • $\begingroup$ As per my programming the rank should be 2000. If its rank < 2000 that means its determinant are zero right. $\endgroup$ – Encipher Aug 5 '18 at 14:13
  • $\begingroup$ 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. $\endgroup$ – 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 } $$

(It seems to be some sort of stiffness matrix for a differential equation with Neumann boundary conditions, where constant functions are in the null space.)

  • $\begingroup$ Thanks for this explanation.Is there any method to invert this type of matrix? $\endgroup$ – Encipher Aug 8 '18 at 11:09
  • $\begingroup$ This is possible if and only if you can divide by zero. Hence: No. $\endgroup$ – daw Aug 8 '18 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.