Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I calculate inverse of sparse matrix in Eigen library

I have a question about Eigen library in C++. Actually, I want to calculate inverse matrix of sparse matrix. When I used Dense matrix in Eigen, I can use .inverse() operation to calculate inverse of dense matrix. But in Sparse matrix, I cannot find inverse operation anywhere. Does anyone who know to calculate inverse of sparse matrix? help me.

like image 518
kujungmul Avatar asked Sep 19 '14 08:09

kujungmul


People also ask

Is the inverse of a sparse matrix sparse?

linear algebra - Inverse of sparse matrix is not generally sparse - Mathematics Stack Exchange.

What is sparse matrix give an example?

The matrix which has a greater number of zero values in comparison to the non-zero values is known as a sparse matrix. In the above example we have 4 X 4 matrix where only 5 values are non-zero and rest of the value are zero. Total space taken by 4 X 4 matrix is 4 X 4 X 2 = 32 bytes.

What is sparse matrix in C++?

C++ProgrammingServer Side Programming. A sparse matrix is a matrix in which majority of the elements are 0. An example for this is given as follows. The matrix given below contains 5 zeroes. Since the number of zeroes is more than half the elements of the matrix, it is a sparse matrix.


1 Answers

You cannot do it directly, but you can always calculate it, using one of the sparse solvers. The idea is to solve A*X=I, where I is the identity matrix. If there is a solution, X will be your inverse matrix. The eigen documentation has a page about sparse solvers and how to use them, but the basic steps are as follows:

SolverClassName<SparseMatrix<double> > solver;
solver.compute(A);
SparseMatrix<double> I(n,n);
I.setIdentity();
auto A_inv = solver.solve(I);
like image 159
MatthiasB Avatar answered Oct 11 '22 12:10

MatthiasB