I understand that FF primarily solves linear systems of the form Ax = b . However, my current work requires explicitly computing matrix inverses — for example, A = C^{-1} D , where both C and D are matrices. Can FF support this functionality?
With the interface with lapack if it has been installed correctly on your computer.
You have to invoke load "lapack", then the inverse is called with ^-1. It works on an array with two indices (not on a sparse matrix), thus if you start from a sparse matrix you have to convert it to an array.
Example (from Getting Problem to get Superconvergence results in Hybrid Higher Order (HHO) Method in Poisson Equation - #6 by fb77 HHO-reduced.edp line 91). If A is a square sparse matrix of size ns
real[int,int] Arr(ns,ns);
real[int,int] Arrinv(ns,ns);
//Arr=A;//not possible in this form
for (int i=0;i<ns;i++){
for (int j=0;j<ns;j++){
Arr(i,j)=A(i,j);
}
}
Arrinv=Arr^-1;//inverse with lapack
matrix Ainv=Arrinv;//recover a sparse matrix
You can solve successively the system Ax=b for b base element. If A is a square sparse matrix of size ns
matrix Ainv(ns,ns);
for (int j=0;j<ns;j++){
real[int] vec(ns);
vec=0.;
vec(j)=1.;
real[int] solvec=A^-1*vec;
for (int i=0;i<ns;i++){
Ainv(i,j)=solvec(i);
}
}
In any case, this will be possible only if the matrix is small.