Problem 14, Section 2.9

This is meant to be parallel to your homework problem 13 (from the same section 2.9), using Python to confirm whatever work you do by hand.

Problem 14 asks that you find a basis for the span of the five vectors

$$ \begin{bmatrix} \phantom{-}1\\ -1\\ -2\\ \phantom{-}5 \end{bmatrix},\ \begin{bmatrix} \phantom{-}2\\ -3\\ -1\\ \phantom{-}6 \end{bmatrix},\ \begin{bmatrix} \phantom{-}0\\ \phantom{-}2\\ -6\\ \phantom{-}8 \end{bmatrix},\ \begin{bmatrix} -1\\ \phantom{-}4\\ -7\\ \phantom{-}7 \end{bmatrix},\ \begin{bmatrix} \phantom{-}3\\ -8\\ \phantom{-}9\\ -5 \end{bmatrix} $$

and to determine the dimension of that span.

Recall from section 2.8 that a basis for a vector space is a linearly-independent set of vectors that spans the vector space. The same section 2.8 also shows you how to compute a basis (in Example 7 therein): just take the pivot columns of the matrix!

So you'll be able to do that as usual, by collecting the vectors above into a matrix

$$ A= \begin{bmatrix} \phantom{-}1 & \phantom{-}2 & \phantom{-}0 & -1 &\phantom{-}3 \\ -1 & -3 & \phantom{-}2 & \phantom{-}4 & -8\\ -2 & -1 & -6 & -7 & \phantom{-}9\\ \phantom{-}5 & \phantom{-}6 & \phantom{-}8 & \phantom{-}7 & -5 \end{bmatrix} $$

as columns and then doing row operations on that matrix. Here, we'll do two things: first ask Python to find the echelon form and hence show us the pivot columns, and then also just give us a basis for the column space of the matrix. We'll then compare the results.

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

So that picked out the first two columns as a basis for the column space, and also told us that the dimension of the space is 2. Let's also check via echelon forms.

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

Bam! Same answer: note that there are two pivot columns, namely the first two. So we got back the same basis as before.

You of course didn't have to apply both of these methods, but it's good to know they agree. Note, though, that while the dimension of the span of the vectors will always come out a 2, there's no such thing as the basis of a vector space: there are always infinitely many choices for a basis, assuming the vector space doesn't consist of the zero vector alone. For instance, if

$$ v_1,\ \cdots,\ v_k $$

is a basis for your vector space, then so is

$$ 2v_1,\ v_2,\ \cdots,\ v_k. $$

Or consider this: if you were to take the five vectors I gave you initially and jumble them, their span would stay the same (since the span only depends on the set of vectors, not on how you order them). So you can take your matrix $A$ and permute its columns; that new column will then have a different set of pivot columns, etc.

Let's do this. First, let me swap, say, the 2nd and 5th columns of $A$.

In [15]:
A_swapped = A.elementary_col_op(op='n<->m', col1=1, col2=4)
In [16]:
A_swapped
Out[16]:
$\displaystyle \left[\begin{matrix}1 & 3 & 0 & -1 & 2\\-1 & -8 & 2 & 4 & -3\\-2 & 9 & -6 & -7 & -1\\5 & -5 & 8 & 7 & 6\end{matrix}\right]$

Note that I had to tell Python to swap columns 1 and 4 because the row / column numbering starts at 0, not 1. So "our" 2 and 5 are Python's 1 and 4.. Anyway, now we'll get a different basis for our column space:

In [17]:
A_swapped.columnspace()
Out[17]:
$\displaystyle \left[ \left[\begin{matrix}1\\-1\\-2\\5\end{matrix}\right], \ \left[\begin{matrix}3\\-8\\9\\-5\end{matrix}\right]\right]$

Those are the first and last vectors that we initially listed. Still two of them (that's the dimension no matter what), but a different basis.