Click here to Skip to main content
15,666,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


8 9 0
0 0 8
0 9 10

and similar

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
Updated 11-Oct-22 21:05pm

1 solution

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.
Share this answer
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 ( cant solve the matrix in the example

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900