Solving matrix equations

Find this content useful?

Matrix inverse algorithm

The inverse of a matrix can be calculated through a clear algorithm

  • Construct the matrix of minors
  • Apply the cofactor matrix
  • Take the transpose of the resulting matrix
  • Divide by the determinant of the original matrix

Augmented matrices

A system of equations of the form $$ \begin{align} ax + by + cz &= p \\ dx + ey + fz &= q \\ gx + hy + iz &= r \end{align} $$ can be rewritten as a matrix equation $$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i\end{array} \right)\left(\begin{array}{c}x \\ y \\ z\end{array}\right) = \left(\begin{array}{c}p \\ q \\ r\end{array}\right) $$

Through a series of row operations, we can simplify this equation to determine the values of $x,y,z$. However, to ease this process, we often write the system as an augmented matrix:

$$\left(\begin{array}{ccc|c} a & b & c & p\\ d & e & f & q \\ g & h & i & r\end{array} \right) $$

To proceed, we will now attempt to reduce the left hand side of the matrix to the identity matrix, in doing so, the right hand side will become the solution; this is because executing a row operation is the same as multiplication by an elementary matrix and the product of the series of row operations will be the inverse matrix

The first two row operations will be $$\begin{align} r'_2 &= r_2  -\frac{d}{a}r_1 \\ r'_3 &= r_3 - \frac{g}{a}r_1\end{align}$$

These operations will produce a rather messy matrix; but one which will help elucidate the process:

$$\left(\begin{array}{ccc|c} a & b & c & p\\ 0 & e-\frac{db}{a} & f - \frac{dc}{a} & q-\frac{dp}{a} \\ 0 & h-\frac{gb}{a} & i -\frac{gc}{a}& r-\frac{gp}{a}\end{array} \right)$$

We have created two zeros in the bottom triangle of the matrix, our next goal will be to produce a third zero, by subtracting copies of row 2 from row 3; in this case the row operation will be

$$r_3'  = r_3 - \frac{ha-gb}{ea-db}r_2$$

The resulting matrix is very messy:

$$\left(\begin{array}{ccc|c} a & b & c & p\\ 0 & e-\frac{db}{a} & f - \frac{dc}{a} & q-\frac{dp}{a} \\ 0 & 0 &\alpha & \beta\end{array} \right)$$

where $\alpha = i - \frac{gc}{a} - \frac{ha-gb}{ea-db}(f-\frac{dc}{a})$ and $\beta = r-\frac{gp}{a} - \frac{ha-gb}{ea-db}(q-\frac{dp}{a})$

Once we have zeroed the entire bottom triangle, it is possible to very easily solve the problem via a process called back-substitution. For example, $z = \frac{\beta}{\alpha}$, from which we can now work out the value of $y$ and then the value of $x$.

 

 

 

Solving matrix equations 1

By solving a matrix equation determine the unique solution for the following simultaneous equations $$ \begin{align} 2x + 3y + 4z &= 19\\ x + y + 2z &= 9\\ 3x - y + z &= 8 \end{align} $$
solution - press button to display

The set of equations can be rewritten as $$ \left(\begin{array}{ccc}2 & 3& 4 \\ 1 & 1 & 2 \\ 3 & -1 & 1\end{array}\right)\left(\begin{array}{c}x \\ y \\ z\end{array}\right) = \left(\begin{array}{c}19 \\ 9 \\ 8\end{array}\right) $$

Before attempting to directly solve the matrix equation, we will calculate the determinant to find out whether the system has a unique solution

$$ \begin{align} \left|\begin{array}{ccc}2 & 3& 4 \\ 1 & 1 & 2 \\ 3 & -1 & 1\end{array}\right| &= 2\left|\begin{array}{cc}1 & 2 \\ -1 & 1\end{array}\right|- 3\left|\begin{array}{cc}1 & 2 \\ 3 & 1\end{array}\right| +4\left|\begin{array}{cc}1 & 1 \\ 3 & -1\end{array}\right| \\ &= 2(3) - 3(-5) + 4(-4) \\ &= 5\end{align}$$

As the determinant is non-zero, we know the system has a unique solution and that the matrix is invertible. We can then either reduce the system of equations using row operations or just directly invert the matrix.

Let us reduce the augmented matrix using row operations; this method tends to be useful when presented with larger systems of equations and in the case where the determinant is zero.

Our augmented matrix is

$$ \left(\begin{array}{ccc|c}2 & 3& 4 & 19\\ 1 & 1 & 2 & 9\\ 3 & -1 & 1& 8\end{array}\right) $$

Performing the row operation $r'_3 = r_3 - 3r_2$ gives $$ \left(\begin{array}{ccc|c}2 & 3& 4 & 19\\ 1 & 1 & 2 & 9\\ 0 & -4 & -5& -19\end{array}\right) $$

Preforming the row operation $r'_2 = 2r_2 - r_1$ (to maintain integer values!) yields $$ \left(\begin{array}{ccc|c}2 & 3& 4 & 19\\ 0 & -1 & 0 & -1\\ 0 & -4 & -5& -19\end{array}\right) $$

Preforming the row operation $r'_3 = r_3 - 4r_1$  (to maintain integer values!) yields $$ \left(\begin{array}{ccc|c}2 & 3& 4 & 19\\ 0 & -1 & 0 & -1\\ 0 & 0 & -5& -15\end{array}\right) $$

scaling rows two and three gives

$$ \left(\begin{array}{ccc|c}2 & 3& 4 & 19\\ 0 & 1 & 0 & 1\\ 0 & 0 & 1& 3\end{array}\right) $$

Preforming the row operation $r'_1 = r_1 - (3r_2 + 4r_3)$  yields $$ \left(\begin{array}{ccc|c}2 & 0& 0 & 4\\ 0 & 1 & 0 & 1\\ 0 & 0 & 1& 3\end{array}\right) $$

Finally, scaling row 1 yields $$ \left(\begin{array}{ccc|c}1 & 0& 0 & 2\\ 0 & 1 & 0 & 1\\ 0 & 0 & 1& 3\end{array}\right) $$

It follows that $(x,y,z) = (2,1,3)$

 

 

Solving matrix equations 2

By calculating the inverse matrix, solve the following matrix equation.

$$ \left(\begin{array}{ccc}2 & 3& 4 \\ 1 & 1 & 2 \\ 3 & -1 & 1\end{array}\right)\left(\begin{array}{c}x \\ y \\ z\end{array}\right) = \left(\begin{array}{c}19 \\ 9 \\ 8\end{array}\right) $$

solution - press button to display
Let $M$ denote the $3\times 3$ matrix, 

$$M =  \left(\begin{array}{ccc}2 & 3& 4 \\ 1 & 1 & 2 \\ 3 & -1 & 1\end{array}\right)$$

As before, $\det(M) = 5$

Then to calculate its inverse, we must first find the matrix of minors $$ M_{Minor} = \left(\begin{array}{ccc}\left|\begin{array}{cc}1 & 2 \\ -1 & 1\end{array}\right| & \left|\begin{array}{cc}1 & 2 \\ 3 & 1\end{array}\right|& \left|\begin{array}{cc}1 & 1 \\ 3 & -1\end{array}\right| \\ \left|\begin{array}{cc}3 & 4 \\ -1 & 1\end{array}\right| & \left|\begin{array}{cc}2 & 4 \\ 3 & 1\end{array}\right| & \left|\begin{array}{cc}2 & 3 \\ 3 & -1\end{array}\right| \\ \left|\begin{array}{cc}3 & 4 \\ 1 & 2\end{array}\right| & \left|\begin{array}{cc}2 & 4 \\ 1 & 2\end{array}\right| & \left|\begin{array}{cc}2 & 3 \\ 1 & 1\end{array}\right|\end{array}\right) $$

Calculating these determinants yields

$$M_{Minor} =\left(\begin{array}{ccc}3 & -5 & -4 \\ 7 & -10 & -11 \\ 2 & 0 & -1\end{array}\right) $$

We must now apply the cofactor signs: $$ \left(\begin{array}{ccc} + & - & + \\ - & + & - \\ + & - & + \end{array}\right) $$ Note that these signs aren't applied by matrix multiplication, but by multiplying each term in the matrix by $\pm 1$ $$M_{cofactor} =\left(\begin{array}{ccc}3 & +5 & -4 \\ -7 & -10 & 11 \\ 2 & 0 & -1\end{array}\right) $$

We next transpose this matrix

$$\mbox{Adj}(M) = M^T_{cofactor} = \left(\begin{array}{ccc}3 & -7 & 2 \\ +5 & -10 & 0 \\ -4 & 11 & -1\end{array}\right) $$

This process yields the adjunct or adjugate matrix.

To complete the calculation of the inverse, we now divide the adjunct by the determinant of the original matrix: $$\begin{align} M^{-1} &= \frac{1}{\det M}\mbox{Adj}(M)\\ &= \frac{1}{5}\left(\begin{array}{ccc}3 & -7 & 2 \\ +5 & -10 & 0 \\ -4 & 11 & -1\end{array}\right)\end{align}$$

Our solution is now given by $$\begin{align} \left(\begin{array}{c}x \\ y \\ z\end{array}\right) &= \frac{1}{5}\left(\begin{array}{ccc}3 & -7 & 2 \\ +5 & -10 & 0 \\ -4 & 11 & -1\end{array}\right)\left(\begin{array}{c}19 \\ 9 \\ 8\end{array}\right) \\ &= \left(\begin{array}{c} 2 \\ 1\\ 3\end{array}\right)\end{align} $$