Section 4 Matrix Equations
A matrix equation is an equation of one or more matrices (or vectors). The goal with these equations is often to find the vector (or matrix) that makes the statement true.
Let's take a look at a specific example before we start talking about solving equations of this type.
Subsection 4.1 Some General Thoughts
The above equation is the product of a matrix \(A \) by , unknown, vector \(\mathbf{x} \) that equals vector \(\mathbf{b} \text{.}\) While as it is stated, there is no particular question, the goal with an equation like this is often to find \(\mathbf{x} \text{.}\) Another way to think about it is; "What vector does \(A \) "send" to \(\mathbf{b} \) ?".
-
Another important observation is how else we can frame the left hand side of the above equation. Consider this next example as we build more intuition about matrix equations.
Example 4.1.
Using a pencil and paper approach, find the product,
\begin{equation*} \underbrace{ \begin{bmatrix} 1 & 2 \\ 3 & 5 \end{bmatrix} }_A \underbrace{ \begin{bmatrix} a \\ b \end{bmatrix} }_\mathbf{x} \end{equation*}SolutionMatrix \(A \) (on the left) has two columns, and matrix \(\mathbf{x} \) (on the right) has two rows. So these two matrices can be multiplied the way that the product has been structured. To preform the product, we will start with the first row \(A \) and dot it with the first (only) column of \(\mathbf{x} \text{.}\) We will then do the same with the second row of \(A \text{.}\)
\begin{equation*} \begin{bmatrix} 1 & 2 \\ 3 & 5 \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \end{equation*}\begin{equation*} \begin{bmatrix} 1(a) + 2(b) \\ 3(a) + 5(b) \end{bmatrix} \end{equation*}If we take the conclusion from the last example and include it in the original equation we get the following result,
\begin{equation*} \begin{bmatrix} 1(a) + 2(b) \\ 3(a) + 5(b) \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \end{equation*}This can be rewritten as,
\begin{equation*} \begin{matrix} 1(a) + 2(b) & = & 1 \\ 3(a) + 5(b) & = & 1 \end{matrix} \end{equation*}showcasing that the original matrix equation was a reframing of a system of equations.
-
The next section will talk about solving the above equation. But before we break into that, let's explore the some of the equation intuition that we have already.
Example 4.2.
Consider the following algebraic equation,
\begin{equation*} 2x=5 \end{equation*}Solve for all (the) value of \(x \) that makes the above statement true.
SolutionThe first thought that comes to mind is, "divide 2 across". And while this thinking is on the right track, we should consider again where division came from. The operation that we are using here is multiplication and we are going to multiply by the number that we "transform" 2 into 1. We want 1 since it will leave us with the product of 1 and \(x \text{,}\) that reduces to \(x \text{.}\)
"multiply by the number that we "transform" 2 into 1" is to say, multiply by the multiplicative inverse of 2. Now the multiplicative inverse of 2 is the number that we multiply 2 by to get 1. We know this to be \(\frac{1}{2} \) but this idea of an inverse is going to be key moving forward with matrices.
So to answer the posed question. Multiply both side of the equation by the multiplicative inverse of 2 (\(\frac{1}{2} \)). This gives us
\begin{equation*} 2x = 5 \Rightarrow \frac{1}{2} 2x = \frac{1}{2}5 \Rightarrow 1x = \frac{1}{2}5 \Rightarrow x = \frac{5}{2} \end{equation*}Now what we saw in the above example is that inverses can be used to solve algebraic equations. So, if inverses also exist for matrices, we could apply the same plan. It turns out that some matrices have inverses and some do now. This will be an important point of consideration. More on this later.
- Sometimes when working with matrix equations we choose to write them in a more "compact" form. That is we may write, \(A\mathbf{x}=\mathbf{b} \text{,}\) and indicate elsewhere what \(A \text{,}\) \(\mathbf{x} \) and \(\mathbf{b} \) are.
Subsection 4.2 Brief Look at Solving
In this section we are going to take a look at how we might solve a matrix equation like the one above. This will give us a chance to explore matrix inverses as well as some of the general challenges. We will also take the chance to consider the system of equations "form" of the problem as well.
Let's start by reviewing the matrix equation.
or,
or,
Let's start with,
If matrix \(A \) is invertible, (Let's call this unknown object \(A \) inverse, and give it the symbols, \(A^{-1} \)). Then we could solve for \(\mathbf{x} \) by,
There are a few things to unpack here:
How do we know if \(A \) has an inverse?
If \(A \) does have an inverse, how do we find it?
What is \(I \) ?
Let's take a look at each of the above questions one at a time.
What is \(I \) ?
Definition 4.3.
The Identity Matrix (denoted \(I \)) is a square matrix that is the multiplicative identity for matrices. That is, any product with \(I \) will remain unchanged. For the \(3 \times 3 \) case,
Checkpoint 4.4.
Using pencil and paper, multiply,
How do we know if \(A \) has an inverse?
We should get out in front of this and say that there is a ton of theory surrounding inverses of matrices. The many note that we need to make here is, "How do we know if a matrix is invertible?".
There is, in fact, a theorem that outlines the many different connections between the linear algebra concepts and invertible matrices. Of all the items in this theorem, we are going to use the "determinant check" as our way of determining if a matrix is invertible.
Definition 4.5.
Given a square matrix \(A \) The determinant of \(A \) is a scalar value made from the entries of the matrix. It is denoted \(|A| \) or \(\textrm{det}(A) \text{.}\) For a \(2 \times 2 \) matrix,
Theorem 4.6.
A square matrix \(A \) is invertible if and only if the determinant of \(A \) is not zero.
Example 4.7.
Use the determinant to check each of the following for invertibility.
- \(\displaystyle \begin{bmatrix} 1 & 7 \\ -1 & 10 \end{bmatrix} \)
- \(\displaystyle \begin{bmatrix} 1 & 2 \\ 9 & 18 \end{bmatrix} \)
- \(\displaystyle \begin{bmatrix} 1 & 7 & 33 \\ -4 & 10 & -18 \end{bmatrix} \)
- \(\textrm{det}\left( \begin{bmatrix} 1 & 7 \\ -1 & 10 \end{bmatrix} \right) = 17\) so invertible.
- \(\textrm{det}\left( \begin{bmatrix} 1 & 2 \\ 9 & 18 \end{bmatrix} \right) = 0 \) so not invertible.
- \(\begin{bmatrix} 1 & 7 & 33 \\ -4 & 10 & -18 \end{bmatrix} \) not square so disqualified.
How do we know if \(A \) has an inverse?
Now that we have a way to determine if a matrix is invertible, and some of the other tools that we need to address solving the equation. Let's find the inverse of \(A \) .
Definition 4.8.
Given a \(2 \times 2\) matrix \(A \) the inverse of \(A \) (denoted \(A^{-1} \)) is the matrix,
This matrix is the matrix such that \(A^{-1}A = I \) as well as \(AA^{-1} = I \text{.}\)
Example 4.9.
Find the inverse of \(A \) .
In the last example, we found that \(\textrm{det}\left( \begin{bmatrix} 1 & 7 \\ -1 & 10 \end{bmatrix} \right) = 17\text{,}\) so we know that this matrix does have a inverse. Now we can use the above definition to find \(A \) inverse.
Subsection 4.3 Solving Matrix Equation Example
Now with everything in place, we can solve the equation that we posed in the beginning of this section.
First we need to check if the matrix, \(\begin{bmatrix} 1 & 2 \\ 3 & 5 \end{bmatrix} \text{,}\) is invertible. It is square (\(2 \times 2\)) so we can use one of the many checks, but we will stick with the determinant.
Now that we have established that the matrix is invertible, let's find the inverse.
Now that we have the inverse, we can solve the given equation by multiplying it on the left-hand-side of both sides of the equal sign.
So, \(a = -5\) and \(b = -2 \text{.}\) It should also be noted that this is what we would get if we were to solve the equation,
for \(a\) and \(b\text{.}\)
Next let's briefly take a look at how we would solve the above matrix equation with Python. We will solve the same equation two different ways. Take a look at both of the methods, as they include code that can be used in many different contexts.
One note about Numpy and working with arrays. The entires of a Numpy array often need to be extracted individually. In the first of the two examples below, there is code for how this is done. As a bit of a preview, this next code-box will include how that is done. One more note. Python starts counting at 0. So the entry in the upper left corner would be in 0 row and 0 column place.
Access Numpy array entries. Let
# Include the numpy module. import numpy as np # Assign matrix A and vector b. A = np.array([[-5, 2], [3, -1]]) print(A[0,0]) # This would print -5 print(A[0,1]) # This would print 2 print(A[1,0]) # This would print 3 print(A[1,1]) # This would print -1
Now to solve matrix equations in the case that the matrix is invertible.
Solving Matrix Equations with Python (step-by-step approach)
# Include the numpy module. import numpy as np # Assign matrix A and vector b. A = np.array([[1, 2], [3, 5]]) b = np.array([[1], [0]]) # Find the inverse of A. We will call it AI. AI = 1 / (A[0,0] * A[1,1] - A[0,1] * A[1,0]) * np.array([[A[1,1] , -A[1,0]],[-A[1,0],A[0,0]]]) # Compute the solution. x = np.dot(AI,b) # print x print(x)
In this next code-block we will use Numpy's linalg submodule. This submodule can be very helpful when working with linear algebra concepts. You will see that we will need to import it as well as numpy at the top. As we work more with Python, more and more modules will be imported so that we can use a multitude of tools. Link to numpy.linalg docs
Solving Matrix Equations with Python (numpy linalg way)
# Include the numpy module. import numpy as np from numpy import linalg # Assign matrix A and vector b. A = np.array([[1, 2], [3, 5]]) b = np.array([[1], [0]]) # Solve for x. x = linalg.solve(A,b) # print x print(x)