Solved

Matrix inverse

  • 7 October 2022
  • 5 replies
  • 114 views

Badge +1

Is there any existing library or repository library available to calculate inverse matrix, especially for large scale matrix?

icon

Best answer by Marcel Hunting 14 February 2023, 16:28

View original

5 replies

Userlevel 5
Badge +4

Hi @fwang1986. AIMMS does not have such a library but it is possible to connect to a linear algebra package like Eigen, using an external procedure. I have done so myself and I could share my code but it would require some extra work for me to clean up the code and I am only going to do so if it would be useful.

What do you mean by large scale? Using Eigen it takes a couple of seconds to calculate the inverse of a 1,000 x 1,000 matrix but for a 10,000 x 10,000 matrix it takes a long time.

Why do you need the inverse? The Eigen documentation mentions this disclaimer: “First of all, make sure that you really want this. While inverse and determinant are fundamental mathematical concepts, in numerical linear algebra they are not as useful as in pure mathematics.”.

Badge +1

Hi Marcel,

The matrix I have is 9000 by 9000. But it is a very sparse matrix. It can be quickly inversed using Matlab.

Does Eigen have sparse matrix technique to calculate the inverse faster? Thank you!

Badge +1

Please also shed some lights on how to connect Eigen with AIMMS using external procedure?

Userlevel 5
Badge +4

Hi @fwang1986. I have no experience with calculating an inverse using Matlab so I cannot tell you whether Eigen is faster.

Attached is a zip file that contains three folders:

  • CalcInverse: small AIMMS project with an example to calculate the inverse.
  • EigenLinearAlgebra: AIMMS library that calls an external procedure to calculate the inverse using Eigen. (It is used in the example project.)
  • src: Visual Studio project with source code to calculate the inverse using Eigen. It retrieves the matrix from AIMMS and passes back the inverse matrix to AIMMS.

You have to build the DLL containing the external procedure yourself using Visual Studio. For that you need to download Eigen from here and then copy the Eigen sub-folder from the Eigen package to the src folder.

The external procedure prGetInverse in the AIMMS library has an argument ‘isPD’ which can be set to 1 to indicate that the matrix is positive definite. In that case a different method will be used which should be faster than the standard method.

The example loads the data for a 1,000x1,000 matrix by default. It also contains a case file for a 10,000x10,000 matrix.

Badge +1

Thank you very much, Marcel. This is really helpful. 

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator