<div dir="ltr"><div>Hi all,</div><div><br></div><div>I'm using PETSc for matrix calculations as part of a model order reduction code. An algorithm I'm using requires that I compute the explicit inverse of a matrix, as it needs to be used in matrix-matrix products. <br></div><div><br></div><div>The matrix is small (I'll show a 5x5 example), and I first find the LU factorization of it as follows:</div><div><br></div><div>  MatGetOrdering(A,MATORDERINGNATURAL,&perm,&iperm);<br>  MatFactorInfoInitialize(&info);<br>  MatLUFactor(A,perm,iperm,&info);</div><div><br></div><div>I then find the inverse of it:</div><div><br></div><div>  MatMatSolve(A,I,B);</div><div><br></div><div>Where I is the identity matrix, and B is the inverse. The subroutine does calculate an inverse, although not accurately; the matrix A I looked at is:</div><div><br></div><div>



        
        
        <span></span>
        
        
        



<table style="font-family:"Liberation Sans";font-size:x-small" cellspacing="0" border="0">
        <colgroup width="85" span="5"></colgroup>
        <tbody style="font-family:"Liberation Sans";font-size:x-small"><tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">5.23E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.86E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">2.67E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">4.58E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">3.55E-02</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">6.37E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">5.86E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">5.07E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.64E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.36E-02</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">-4.07E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">3.99E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">5.50E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.77E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-3.21E-02</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">1.96E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-5.53E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">4.02E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-5.37E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.80E-02</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">1.51E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.70E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-1.57E-02</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-3.75E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-5.64E-02</td>
        </tr>
</tbody></table>



</div><div><br></div><div>And when I take the product A*B, I don't recover the identity matrix, but rather:</div><div><br></div><div>



        
        
        <span></span>
        
        
        



<table style="font-family:"Liberation Sans";font-size:x-small" cellspacing="0" border="0">
        <colgroup width="85" span="5"></colgroup>
        <tbody style="font-family:"Liberation Sans";font-size:x-small"><tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">9.97E-01</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">2.77E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-1.66E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.25E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-1.10E-03</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">-6.79E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">9.99E-01</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-1.72E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">6.24E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">1.16E-03</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">2.70E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-3.98E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">9.98E-01</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-1.51E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">6.82E-04</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">-3.35E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-4.82E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-1.03E-03</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">9.99E-01</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">9.80E-05</td>
        </tr>
        <tr style="font-family:"Liberation Sans";font-size:x-small">
                <td style="font-family:"Liberation Sans";font-size:x-small" height="17" align="right">-9.50E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-8.70E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">8.37E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">-3.68E-04</td>
                <td style="font-family:"Liberation Sans";font-size:x-small" align="right">9.99E-01</td>
        </tr>
</tbody></table>



</div><div><br></div><div>I believe this is causing large inaccuracies in my program, as the diagonal and off-diagonal entries have large errors associated with them. I am wondering if there is a way to perhaps tighten the tolerance of the subroutine, or if there are other methods I can use. I would like to avoid using KSP and solving for the inverse vector-by-vector if possible.</div><div><br></div><div>Thanks,</div><div><br></div><div>Rakesh Halder<br></div></div>