Tutorial
Tutorial#
You 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}\).
Find the of \(A\)
Hence find the values of \(a\) for which \(A\) is singular.
For the following values of \(a\), when possible obtain \(A ^ {- 1}\) and confirm the result by computing \(AA^{-1}\):
\(a = 0\);
\(a = 1\);
\(a = 2\);
\(a = 3\).
sympy
is once again the library you will use for this. You will start
by defining the matrix \(A\):
import sympy as sym
a = sym.Symbol("a")
A = sym.Matrix([[a, 1, 1], [1, a, 1], [1, 1, 2]])
You can now create a variable determinant
and assign it the value of the
determinant of \(A\):
determinant = A.det()
determinant
A matrix is singular if it has determinant 0. You can find the values of \(a\) for which this occurs:
sym.solveset(determinant, a)
Thus, it is not possible to find the inverse of \(A\) for \(a\in\{0, 1\}\). However for \(a = 2\):
A.subs({a: 2})
A.subs({a: 2}).inv()
To carry out matrix multiplication you use the @
symbol:
A.subs({a: 2}).inv() @ A.subs({a: 2})
and for \(a = 3\):
A.subs({a: 3}).inv()
A.subs({a: 3}).inv() @ A.subs({a: 3})
Important
In this tutorial you have
Created a matrix;
Calculated the of the matrix;
Substituted values in the matrix;
Inverted the matrix.