|
17.5 Matrix Inversion
Matrix inversion.
Here is a simple matrix.
In[1]:= m = {{a, b}, {c, d}}
Out[1]= 
This gives the inverse of m. In producing this formula, Mathematica TE implicitly assumes that the determinant a d - b c is nonzero.
In[2]:= Inverse[ m ]
Out[2]= 
Multiplying the inverse by the original matrix should give the identity matrix.
In[3]:= % . m
Out[3]= 
You have to use Together to clear the denominators and get back a standard identity matrix.
In[4]:= Together[ % ]
Out[4]= 
Here is a matrix of rational numbers.
In[5]:= hb = Table[1/(i + j), {i, 4}, {j, 4}]
Out[5]= 
Mathematica TE finds the exact inverse of the matrix.
In[6]:= Inverse[hb]
Out[6]= 
Multiplying by the original matrix gives the identity matrix.
In[7]:= % . hb
Out[7]= 
If you try to invert a singular matrix, Mathematica TE prints a warning message, and returns the inverse undone.
In[8]:= Inverse[ {{1, 2}, {1, 2}} ]

Out[8]= 
If you give a matrix with exact symbolic or numerical entries, Mathematica TE gives the exact inverse. If, on the other hand, some of the entries in your matrix are approximate real numbers, then Mathematica TE finds an approximate numerical result.
Here is a matrix containing approximate real numbers.
In[9]:= m = {{1.2, 5.7}, {4.2, 5.6}}
Out[9]= 
This finds the numerical inverse.
In[10]:= Inverse[ % ]
Out[10]= 
Multiplying by the original matrix gives you an identity matrix with small numerical errors.
In[11]:= % . m
Out[11]= 
You can get rid of the small off-diagonal terms using Chop.
In[12]:= Chop[ % ]
Out[12]= 
When you try to invert a matrix with exact numerical entries, Mathematica TE can always tell whether or not the matrix is singular. When you invert an approximate numerical matrix, Mathematica TE can never tell for certain whether or not the matrix is singular; all it can tell is for example that the determinant is small compared to the entries of the matrix. When Mathematica TE suspects that you are trying to invert a singular numerical matrix, it prints a warning.
Mathematica TE prints a warning if you invert a numerical matrix that it suspects is singular.
In[13]:= Inverse[ {{1., 2.}, {1., 2.}} ]

Out[13]= 
If you work with high-precision approximate numbers, Mathematica TE will keep track of the precision of matrix inverses that you generate.
This generates a numerical matrix with entries of 50-digit precision.
In[14]:= m = N [ Table[ Exp[i j], {i, 6}, {j, 6} ], 50 ] ;
This takes the matrix, multiplies it by its inverse, and shows the first row of the result.
In[15]:= (m . Inverse[m]) [[1]]
Out[15]= 
This gives the accuracy of the result.
In[16]:= Accuracy[ % ]
Out[16]= 
This generates a 50-digit numerical approximation to a Hilbert matrix. Hilbert matrices are notoriously hard to invert numerically.
In[17]:= m = N[Table[1/(i + j - 1), {i, 6}, {j, 6}], 50] ;
The actual numbers given are again correct.
In[18]:= (m . Inverse[m]) [[1]]
Out[18]= 
The accuracy of the result, however, is lower than the original matrix.
In[19]:= Accuracy[ % ]

Out[19]= 
    
|