# About Solving Inverse Matrix

**URL:** <https://community.freefem.org/t/about-solving-inverse-matrix/4246>\
**Category:** General Discussion\
**Created:** [March 31, 2026, 2:15am UTC](https://community.freefem.org/t/about-solving-inverse-matrix/4246 "2026-03-31T02:15:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [March 31, 2026, 9:14am UTC](https://community.freefem.org/t/about-solving-inverse-matrix/4246/2 "2026-03-31T09:14:29Z")

</div>

This can be done in two ways:

1. 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](https://community.freefem.org/t/getting-problem-to-get-superconvergence-results-in-hybrid-higher-order-hho-method-in-poisson-equation/4242/6) HHO-reduced.edp line 91). If `A` is a square sparse matrix of size `ns`

```auto
  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

```

1. You can solve successively the system `Ax=b` for `b` base element. If `A` is a square sparse matrix of size `ns`

```auto
  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.

---

_[View the full topic](https://community.freefem.org/t/about-solving-inverse-matrix/4246)._
