1

I have just printed the matrix of size n*n

Code is (Assume that all matrices are already defined):

public class ReadContents { 
    public static void main(String args[]) {
        System.out.println();
        System.out.println("The Matrix Is:");
        double mat[][]=new double[col][col];

        for(k=0;k<col;k++) {
            for(p=0;p<col;p++) {
                mat[k][p]=SubMULTIPL_1[k][p]-ADD[k][p];
                System.out.printf("%2.2f  ",mat[k][p]);
            }

            System.out.println();
        }
    }

But, I am having the problem of finding the inverse of n*n square matrix
where n=1,2,3..........infinite.

Any help would be appreciated.

thejartender
  • 9,339
  • 6
  • 34
  • 51
raghav
  • 35
  • 4
  • 7

2 Answers2

2
  • Some Java matrix math libraries can do the job.

  • Not every matrix is invertible perhaps you should test if this condition is met.

Community
  • 1
  • 1
Ghassen Hamrouni
  • 3,138
  • 2
  • 20
  • 31
2

You probably don't want the inverse.

I'm betting that you really want to know how to solve a system of equations. I'd recommend that you look at LU decomposition rather than inverse or Gaussian elimination. It's more stable.

You'll have a hard time inverting a matrix if the determinant of the matrix is zero or VERY small.

duffymo
  • 305,152
  • 44
  • 369
  • 561