<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Rakesh,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Can you find the condition number of your matrix A? </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hong</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> petsc-users <petsc-users-bounces@mcs.anl.gov> on behalf of Rakesh Halder <rhalder@umich.edu><br>
<b>Sent:</b> Thursday, June 25, 2020 2:43 PM<br>
<b>To:</b> petsc-users@mcs.anl.gov <petsc-users@mcs.anl.gov><br>
<b>Subject:</b> [petsc-users] Inaccurate Matrix Inversion using MatMatSolve</font>
<div> </div>
</div>
<div>
<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 cellspacing="0" border="0" style="font-family:"Liberation Sans"; font-size:x-small">
<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 height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
5.23E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.86E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">2.67E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">4.58E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">3.55E-02</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
6.37E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">5.86E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">5.07E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.64E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.36E-02</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
-4.07E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">3.99E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">5.50E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.77E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-3.21E-02</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
1.96E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-5.53E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">4.02E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-5.37E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.80E-02</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
1.51E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.70E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-1.57E-02</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-3.75E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-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 cellspacing="0" border="0" style="font-family:"Liberation Sans"; font-size:x-small">
<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 height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
9.97E-01</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">2.77E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-1.66E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.25E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-1.10E-03</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
-6.79E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">9.99E-01</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-1.72E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">6.24E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">1.16E-03</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
2.70E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-3.98E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">9.98E-01</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-1.51E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">6.82E-04</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
-3.35E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-4.82E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-1.03E-03</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">9.99E-01</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">9.80E-05</td>
</tr>
<tr style="font-family:"Liberation Sans"; font-size:x-small">
<td height="17" align="right" style="font-family:"Liberation Sans"; font-size:x-small">
-9.50E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-8.70E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">8.37E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">-3.68E-04</td>
<td align="right" style="font-family:"Liberation Sans"; font-size:x-small">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>
</div>
</body>
</html>