This is a model for how to work out one of your homework problems using Jupyter notebook. The problem in question will be exercise 12 from section 1.3 of our textbook. The statement is as follows.

We are given vectors

\begin{equation} {\bf a}_1 = \begin{bmatrix} \phantom{-}1 \\ -2\\ \phantom{-}2 \end{bmatrix},\quad {\bf a}_2 = \begin{bmatrix} 0\\ 5\\ 5 \end{bmatrix},\quad {\bf a}_3 = \begin{bmatrix} 2\\ 0\\ 8 \end{bmatrix} \end{equation}

and are asked to decide whether the vector

\begin{equation} {\bf b}= \begin{bmatrix} -5\\ 11\\ -7 \end{bmatrix} \end{equation}

is a linear combination of ${\bf a}_1$, ${\bf a}_2$ and ${\bf a}_3$. This means:

Do there exist coefficients $x_1$, $x_2$ and $x_3$ such that \begin{equation} x_1{\bf a}_1 + x_2{\bf a}_2 + x_3{\bf a}_3 = {\bf b}? \end{equation}

Or to put it differently, in linear system / matrix language:

  • Denote by ${\bf A}$ the matrix obtained by gluing the ${\bf a}_i$ as columns, i.e.
$$ {\bf A}= \begin{pmatrix} \phantom{-}1&0&2\\ -2&5&0\\ \phantom{-}2&5&8 \end{pmatrix}, $$
  • Denote
$$ {\bf x}= \begin{bmatrix} x_1\\ x_2\\ x_3 \end{bmatrix}, $$
  • Does the equation
$$ {\bf A} {\bf x} = {\bf b} $$

have a solution ${\bf x}$?

We have already seen an example of how to work through this. First, form the extended matrix

$$ {\bf E} = \begin{pmatrix}{\bf A}&{\bf b}\end{pmatrix} = \begin{pmatrix} \phantom{-}1&0&2&-5\\ -2 & 5 & 0 & 11\\ \phantom{-}2 & 5 & 8 & -7 \end{pmatrix} $$

and then simply outsource the work to SymPy! See below.

In [7]:
from sympy import *
from sympy.solvers.solveset import linsolve
In [8]:
x1, x2, x3 = symbols('x1, x2, x3')
In [9]:
linsolve(Matrix(([1, 0, 2, -5], [-2, 5, 0, 11], [2, 5, 8, -7])), (x1, x2, x3))
Out[9]:
$\displaystyle \emptyset$

That empty-set symbol means the system does not have a solution, i.e. the answer to the original question (of whether ${\bf b}$ is a linear combination of ${\bf a}_i$, $i=1,2,3$) is no.

That's all there is to it.

In [ ]: