Problem 13, Section 3.3

This is a relatively short document, using Python to work out problem 13 from section 3.3 (which in turn is very similar to problem 12 from the same section, on your homework).

We have to compute the inverse of the matrix

$$ A= \left[ \begin{array}{rrr} 3 & 5 & 4 \\ 1 & 0 & 1 \\ 2 & 1 & 1 \end{array} \right] $$

by computing the adjugate, via Theorem 8 from section 3.3. That theorem says simply that if $A$ is invertible, then you can get its inverse $A^{-1}$ as

$$ A^{-1} = \frac 1{\det A} \mathrm{adj}A $$

(where $\mathrm{adj}A$ is the adjugate of $A$, described right before that Theorem 8).

We'll ask SymPy to do just that: compute the adjugate and divide it by the determinant. We'll then also, separately, ask it to directly compute the inverse and check that we obtain the same result.

In [1]:
from sympy import *
init_printing(use_latex='mathjax')
In [3]:
A=Matrix([[3,5,4],[1,0,1],[2,1,1]])
A
Out[3]:
$\displaystyle \left[\begin{matrix}3 & 5 & 4\\1 & 0 & 1\\2 & 1 & 1\end{matrix}\right]$
In [6]:
A_adj=A.adjugate()
A_adj
Out[6]:
$\displaystyle \left[\begin{matrix}-1 & -1 & 5\\1 & -5 & 1\\1 & 7 & -5\end{matrix}\right]$
In [7]:
A_inv = A_adj/A.det()
A_inv
Out[7]:
$\displaystyle \left[\begin{matrix}- \frac{1}{6} & - \frac{1}{6} & \frac{5}{6}\\\frac{1}{6} & - \frac{5}{6} & \frac{1}{6}\\\frac{1}{6} & \frac{7}{6} & - \frac{5}{6}\end{matrix}\right]$

OK, so that's the inverse by the adjugate method in Theorem 8, section 3.3. How about asking for the inverse directly?

In [8]:
A.inv()
Out[8]:
$\displaystyle \left[\begin{matrix}- \frac{1}{6} & - \frac{1}{6} & \frac{5}{6}\\\frac{1}{6} & - \frac{5}{6} & \frac{1}{6}\\\frac{1}{6} & \frac{7}{6} & - \frac{5}{6}\end{matrix}\right]$

Good: we got the same thing! Why not also check that it is an inverse, by multiplying by $A$ and verifying that we get the identity?

In [9]:
A*A_inv
Out[9]:
$\displaystyle \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right]$
In [10]:
A_inv * A
Out[10]:
$\displaystyle \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right]$

Yep, worked out all right.