Problem 18, Section 4.3

Here's how I'd work out problem 18 from section 4.3, which is a computational analogue (marked in the textbook by [M]) of your homework problem 16 from the same section. This will be fairly quick and painless..

We are asked to find a basis for the span of the vectors

$$ \left[ \begin{array}{r} -8\\ 7\\ 6\\ 5\\ -7 \end{array} \right], \left[ \begin{array}{r} 8\\ -7\\ -9\\ -5\\ 7 \end{array} \right], \left[ \begin{array}{r} -8\\ 7\\ 4\\ 5\\ -7 \end{array} \right], \left[ \begin{array}{r} 1\\ 4\\ 9\\ 6\\ -7 \end{array} \right], \left[ \begin{array}{r} -9\\ 3\\ -4\\ -1\\ 0 \end{array} \right]. $$

Since SymPy returns precisely that (return a basis) if you feed it a matrix and ask for the column space, let's just squeeze those vectors together into a matrix and issue that command.

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

There we go: columns 1, 2 and 4 form a basis. You know what though? Let's have a quick sanity check. The above computation tells me that the column space of my matrix $A$ is $3$-dimensional, and hence the rank of the matrix is $3$. Remember the Rank-Nullity theorem?

The rank of a matrix and the dimension of its nullspace add up to the number of columns.

The "sanity check" will be to also retrieve the nullspace of $A$ and verify that it indeed has dimension $5-3=2$.

In [4]:
A.nullspace()
Out[4]:
$\displaystyle \left[ \left[\begin{matrix}- \frac{5}{3}\\- \frac{2}{3}\\1\\0\\0\end{matrix}\right], \ \left[\begin{matrix}- \frac{4}{3}\\- \frac{1}{3}\\0\\1\\1\end{matrix}\right]\right]$

Yep, as expected,

$$ \dim\mathrm{Col}~A + \dim\mathrm{Null}~A = 3 + 2 = 5 = \# (\text{ columns of }A). $$