4

I would like to calculate an inverse of matrix in java. Are there any already existing packages which calculate inverse of matrix. I found similar question, but the answers in the questions are not so strongly recommending to use anyof the packages. Even i could not follow the method they are using. I have a large matrix of 10000s of rows and columns. I would like to calculate inverse of it.

Community
  • 1
  • 1
thetna
  • 6,903
  • 26
  • 79
  • 113

4 Answers4

3

Apache Commons Math have support for linear algebra

JustDanyul
  • 13,813
  • 7
  • 53
  • 71
2

I think you should give a shot to JAMA

The documentation presents an inverse function for matrices http://math.nist.gov/javanumerics/jama/doc/

Seeing the size of your matrix though, You WILL have to factorize it first .

jlengrand
  • 12,152
  • 14
  • 57
  • 87
1

The la4j (Linear Algebra for Java) library supports matrix inversion. Here is the short example:

Matrix a = new Basic2DMatrix(new double[][]{
   { 1.0, 2.0, 3.0 },
   { 4.0, 5.0, 6.0 },
   { 7.0, 8.0. 9.0 }
});

Matrix b = a.invert(Matrices.DEFAULT_INVERTOR); // uses Gaussian Elimination 
Vladimir Kostyukov
  • 2,492
  • 3
  • 21
  • 30
-1

there is a example in github used Linear Algebra for Java

Matrix a =                                               
             factory.createMatrix(new RandomMatrixSource(SIZE,SIZE));
MatrixInverter inverter = a.withInverter(LinearAlgebra.GAUSS_JORDAN);
         Matrix e = inverter.inverse(factory); 
xingfe123
  • 79
  • 3