Tutorial#

We will solve the following problem using a computer to assist with the technical aspects:

Problem

The matrix \(A\) is given by \(A=\begin{pmatrix}a & 1 & 1\\ 1 & a & 1\\ 1 & 1 & 2\end{pmatrix}\).

  1. Find the determinant of \(A\)

  2. Hence find the values of \(a\) for which \(A\) is singular.

  3. For the following values of \(a\), when possible obtain \(A ^ {- 1}\) and confirm the result by computing \(AA^{-1}\):

    1. \(a = 0\);

    2. \(a = 1\);

    3. \(a = 2\);

    4. \(a = 3\).

sympy is once again the library we will use for this.

We will start by our matrix \(A\):

import sympy as sym

a = sym.Symbol("a")
A = sym.Matrix([[a, 1, 1], [1, a, 1], [1, 1, 2]])

We can now create a variable determinant and assign it the value of the determinant of \(A\):

determinant = A.det()
determinant
\[\displaystyle 2 a^{2} - 2 a\]

A matrix is singular if it has determinant 0. We can find the values of \(a\) for which this occurs:

sym.solveset(determinant, a)
\[\displaystyle \left\{0, 1\right\}\]

Thus it is not possible to find the inverse of \(A\) for \(a\in\{0, 1\}\).

However for \(a = 2\):

A.subs({a: 2})
\[\begin{split}\displaystyle \left[\begin{matrix}2 & 1 & 1\\1 & 2 & 1\\1 & 1 & 2\end{matrix}\right]\end{split}\]
A.subs({a: 2}).inv()
\[\begin{split}\displaystyle \left[\begin{matrix}\frac{3}{4} & - \frac{1}{4} & - \frac{1}{4}\\- \frac{1}{4} & \frac{3}{4} & - \frac{1}{4}\\- \frac{1}{4} & - \frac{1}{4} & \frac{3}{4}\end{matrix}\right]\end{split}\]

To carry out matrix multiplication we use the @ symbol:

A.subs({a: 2}).inv() @ A.subs({a: 2})
\[\begin{split}\displaystyle \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right]\end{split}\]

and for \(a = 3\):

A.subs({a: 3}).inv()
\[\begin{split}\displaystyle \left[\begin{matrix}\frac{5}{12} & - \frac{1}{12} & - \frac{1}{6}\\- \frac{1}{12} & \frac{5}{12} & - \frac{1}{6}\\- \frac{1}{6} & - \frac{1}{6} & \frac{2}{3}\end{matrix}\right]\end{split}\]
A.subs({a: 3}).inv() @ A.subs({a: 3})
\[\begin{split}\displaystyle \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right]\end{split}\]

Important

In this tutorial we have

  • Created a matrix.

  • Calculated the determinant of the matrix.

  • Substituted values in the matrix.

  • Inverted the matrix.