15,666,844 members
See more:
I was coding a matrix inversion algorithm

It works with almost all of the matrixes except one with zeros in the diagonal entries

Like:

8 9 0
0 0 8
0 9 10

and similar

Python
```if Argument_Matrix[i][i] != 0:
Argument_Matrix[i] /= Argument_Matrix[i][i]```

because of this step of normalizing the diagonal element as it cause division by zero error

What I have tried:

I have looked up some solution but none are full proof and cant deal some edge cases (like the one above) or are just a big long list of if statements
Posted
Updated 11-Oct-22 21:05pm

## Solution 1

Assuming the input matrix is non-singular, there are many well-proven algorithms for matrix inversion.

To overcome your immediate problem of zeros on the main diagonal, you should read up on `pivoting` in the context of matrix manipulation. While you're at it, have a look at `condition number`.

Animesh jain 2022 12-Oct-22 5:57am
the matrix in the example is non singular and I am using one of the proven algorithms(gauss jordan matrix inversion)

don't know much about pivoting but the usual solution on the internet is to transform the matrix so remove zeros from the diagonal entries but they are not full prove

Like one posted on geeksforgeeks (https://www.geeksforgeeks.org/finding-inverse-of-a-matrix-using-gauss-jordan-method/) cant solve the matrix in the example