One problem you might run into frequently in MTH309 is solving linear systems of equations, i.e. collections of equations in the unknowns $x_1$, $x_2$, etc. of the form (say)

\begin{align} x_1 + 2x_2 + 3x_3 &= 6\\ 4x_1+5x_2+6x_3 &=15\\ 7x_1+8x_2+9x_3 &=24 \end{align}

Note the matrix of coefficients on the left hand side of the '$=$' signs:

\begin{equation} A= \begin{pmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{pmatrix} \end{equation}

Note also the vector formed by the terms on the right hand sides of the '$=$' signs:

\begin{equation} b= \begin{pmatrix} 6\\ 15\\ 24 \end{pmatrix} \end{equation}

Now squash those into a single extended matrix

\begin{equation} E= \begin{pmatrix} 1 & 2 & 3&6\\ 4 & 5 & 6&15\\ 7 & 8 & 9&24 \end{pmatrix} \end{equation}

This matrix encodes all of the information you need to pin down the system, and hence solve it for the unknowns $x_i$. You'll learn how to do this "by hand", but you can always check your work by computer. Check this out.

In [10]:
from sympy import *
from sympy.solvers.solveset import linsolve
In [11]:
x1, x2, x3 = symbols('x1, x2, x3')
In [12]:
linsolve(Matrix(([1, 2, 3, 6], [4, 5, 6, 15], [7, 8, 9, 24])), (x1, x2, x3))
Out[12]:
$\displaystyle \left\{\left( x_{3}, \ 3 - 2 x_{3}, \ x_{3}\right)\right\}$

That's it! See that answer? It's the solution to your equation. It tells you that

  • $x_3$ can be chosen arbitrarily
  • $x_2$ will then be $3-2x_3$
  • and $x_1$ will be equal to $x_3$

So the solution is not unique: you have one degree of freedom in specifying it.

In conclusion, these are very powerful tools. You can use them to double check your work or to do that work to begin with. We cannot focus on Python and/or Jupyter Notebook in this course because that's not the theme of the course to begin with, but you are strongly advised and encouraged to learn how to use this machinery; if you are not already familiar with it, it will be a significant boost to your skillset.

In [ ]: