Section 4.6 Determinant of a Matrix
Not every matrix has an inverse. For example, consider the matrix \(A = \begin{bmatrix}1 & 1 \\1 & 1 \end{bmatrix}\text{.}\) If you try to find its inverse in MATLAB you get an error message:
>> A = [1 1; 1 1]; >> B = inv(A)
\(\color{red}{\text{Warning: Matrix is singular to working precision.}}\)
\(\color{red}{\text{B =}}\)
\(\color{red}{\text{Inf Inf}}\)
\(\color{red}{\text{Inf Inf}}\)
Why does this matrix not have an inverse? Well, suppose an inverse B did exist. It would have to satisfy that A*B = I, so:
\begin{equation*}
\begin{bmatrix}1 & 1 \\ 1 & 1 \end{bmatrix} * \begin{bmatrix}b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} = \begin{bmatrix}1 & 0 \\ 0 & 1 \end{bmatrix}
\end{equation*}
If you write out the matrix multiplication you obtain four equations, namely:
\begin{equation*}
b_{11} + b_{21} = 1; b_{12} + b_{22} = 0; b_{11} + b_{21} = 0; b_{12} + b_{22} = 1.
\end{equation*}
Clearly, these equations contradict each other and that’s why the matrix A cannot have an inverse.
How can you tell whether a matrix has an inverse? That’s where the determinant comes in. The determinant of a matrix is a function that computes a number associated with a square matrix. It turns out, this number tells you about the matrix being invertible.
For the inverse of a matrix to exist, the matrix must be square and its determinant must be non-zero.
The determinant of a matrix \(A\)
- is written as
det(A)
or|A|
- is useful in determining whether a solution to a system of equations exists
Linear algebra teaches you how to calculate the determinant of a matrix by hand (for example, using Cramer’s Rule.) Thankfully, MATLAB can also find the determinant of a matrix.
In MATLAB:
>> A = [8 5 3; 1 2 5; 2 9 4]; %3x3 matrix
>> d = det(A)
d =
-251
Since the determinant of A is nonzero, the matrix has an inverse:
>> A^-1
ans =
0.1474 -0.0279 -0.0757
-0.0239 -0.1036 0.1474
-0.0199 0.2470 -0.0438
Now let’s take a look at what happens for a matrix whose determinant is zero (also called a singular matrix).
>> A = [8 5 3; 1 2 5; 1 2 5]; % 3x3 singular matrix
>> det(A)
ans =
0
>> A^-1
\(\color{red}{\text{Warning: Matrix is singular to working precision.}}\)
\(\color{red}{\text{ans =}}\)
\(\color{red}{\text{Inf Inf Inf}}\)
\(\color{red}{\text{Inf Inf Inf}}\)
\(\color{red}{\text{Inf Inf Inf}}\)