Skip to main content
Mathematics LibreTexts

2.5: Solving Matrix Equations AX=B

  • Page ID
    63387
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Learning Objectives
    • T/F: To solve the matrix equation \(AX = B\), put the matrix \([A\; X]\) into reduced row echelon form and interpret the result properly.
    • T/F: The first column of a matrix product \(AB\) is \(A\) times the first column of \(B\).
    • Give two reasons why one might solve for the columns of \(X\) in the equation \(AX=B\) separately.

    We began last section talking about solving numerical equations like \(ax=b\) for \(x\). We mentioned that solving matrix equations of the form \(AX=B\) is of interest, but we first learned how to solve the related, but simpler, equations \(A\vec{x}=\vec{b}\). In this section we will learn how to solve the general matrix equation \(AX=B\) for \(X\).

    We will start by considering the best case scenario when solving \(A\vec{x}=\vec{b}\); that is, when \(A\) is square and we have exactly one solution. For instance, suppose we want to solve \(A\vec{x}=\vec{b}\) where

    \[A=\left[\begin{array}{cc}{1}&{1}\\{2}&{1}\end{array}\right]\quad\text{and}\quad\vec{b}=\left[\begin{array}{c}{0}\\{1}\end{array}\right]. \nonumber \]

    We know how to solve this; put the appropriate matrix into reduced row echelon form and interpret the result.

    \[\left[\begin{array}{ccc}{1}&{1}&{0}\\{2}&{1}&{1}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{ccc}{1}&{0}&{1}\\{0}&{1}&{-1}\end{array}\right] \nonumber \]

    We read from this that

    \[\vec{x}=\left[\begin{array}{c}{1}\\{-1}\end{array}\right]. \nonumber \]

    Written in a more general form, we found our solution by forming the augmented matrix

    \[\left[\begin{array}{cc}{A}&{\vec{b}}\end{array}\right] \nonumber \]

    and interpreting its reduced row echelon form:

    \[\left[\begin{array}{cc}{A}&{\vec{b}}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{cc}{I}&{\vec{x}}\end{array}\right] \nonumber \]

    Notice that when the reduced row echelon form of \(A\) is the identity matrix \(I\) we have exactly one solution. This, again, is the best case scenario.

    We apply the same general technique to solving the matrix equation \(AX=B\) for \(X\). We’ll assume that \(A\) is a square matrix (\(B\) need not be) and we’ll form the augmented matrix

    \[\left[\begin{array}{cc}{A}&{B}\end{array}\right]. \nonumber \]

    Putting this matrix into reduced row echelonform will give us \(X\), much like we found \(\vec{x}\) before.

    \[\left[\begin{array}{cc}{A}&{B}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{cc}{I}&{X}\end{array}\right] \nonumber \]

    As long as the reduced row echelon form of \(A\) is the identity matrix, this technique works great. After a few examples, we’ll discuss why this technique works, and we’ll also talk just a little bit about what happens when the reduced row echelon form of \(A\) is not the identity matrix.

    First, some examples.

    Example \(\PageIndex{1}\)

    Solve the matrix equation \(AX=B\) where

    \[A=\left[\begin{array}{cc}{1}&{-1}\\{5}&{3}\end{array}\right]\quad\text{and}\quad B=\left[\begin{array}{ccc}{-8}&{-13}&{1}\\{32}&{-17}&{21}\end{array}\right] . \nonumber \]

    Solution

    To solve \(AX=B\) for \(X\), we form the proper augmented matrix, put it into reduced row echelon form, and interpret the result.

    \[\left[\begin{array}{ccccc}{1}&{-1}&{-8}&{-13}&{1}\\{5}&{3}&{32}&{-17}&{21}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{ccccc}{1}&{0}&{1}&{-7}&{3}\\{0}&{1}&{9}&{6}&{2}\end{array}\right] \nonumber \]

    We read from the reduced row echelon form of the matrix that

    \[X=\left[\begin{array}{ccc}{1}&{-7}&{3}\\{9}&{6}&{2}\end{array}\right]. \nonumber \]

    We can easily check to see if our answer is correct by multiplying \(AX\).

    Example \(\PageIndex{2}\)

    Solve the matrix equation \(AX=B\) where

    \[A=\left[\begin{array}{ccc}{1}&{0}&{2}\\{0}&{-1}&{-2}\\{2}&{-1}&{0}\end{array}\right]\quad\text{and}\quad B=\left[\begin{array}{cc}{-1}&{2}\\{2}&{-6}\\{2}&{-4}\end{array}\right]. \nonumber \]

    Solution

    To solve, let’s again form the augmented matrix

    \[\left[\begin{array}{cc}{A}&{B}\end{array}\right], \nonumber \]

    put it into reduced row echelon form, and interpret the result.

    \[\left[\begin{array}{ccccc}{1}&{0}&{2}&{-1}&{2}\\{0}&{-1}&{-2}&{2}&{-6}\\{2}&{-1}&{0}&{2}&{-4}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{ccccc}{1}&{0}&{0}&{1}&{0}\\{0}&{1}&{0}&{0}&{4}\\{0}&{0}&{1}&{-1}&{1}\end{array}\right] \nonumber \]

    We see from this that

    \[X=\left[\begin{array}{cc}{1}&{0}\\{0}&{4}\\{-1}&{1}\end{array}\right]. \nonumber \]

    Why does this work? To see the answer, let’s define five matrices.

    \[A=\left[\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}\right],\quad\vec{u}=\left[\begin{array}{c}{1}\\{1}\end{array}\right],\quad\vec{v}=\left[\begin{array}{c}{-1}\\{1}\end{array}\right],\quad\vec{w}=\left[\begin{array}{c}{5}\\{6}\end{array}\right]\quad\text{and}\quad X=\left[\begin{array}{ccc}{1}&{-1}&{5}\\{1}&{1}&{6}\end{array}\right] \nonumber \]

    Notice that \(\vec{u}\), \(\vec{v}\) and \(\vec{w}\) are the first, second and third columns of \(X\), respectively. Now consider this list of matrix products: \(A\vec{u}\), \(A\vec{v}\), \(A\vec{w}\) and \(AX\).

    \[\begin{aligned}A\vec{u}&=\left[\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}\right]\:\left[\begin{array}{c}{1}\\{1}\end{array}\right] \\ &=\left[\begin{array}{c}{3}\\{7}\end{array}\right]\end{aligned} \nonumber \] \[\begin{aligned}A\vec{u}&=\left[\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}\right]\:\left[\begin{array}{c}{-1}\\{1}\end{array}\right] \\ &=\left[\begin{array}{c}{1}\\{1}\end{array}\right]\end{aligned} \nonumber \]
    \[\begin{aligned}A\vec{u}&=\left[\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}\right]\:\left[\begin{array}{c}{5}\\{6}\end{array}\right] \\ &=\left[\begin{array}{c}{17}\\{39}\end{array}\right]\end{aligned} \nonumber \] \[\begin{aligned}AX&=\left[\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}\right]\:\left[\begin{array}{ccc}{1}&{-1}&{5}\\{1}&{1}&{6}\end{array}\right] \\ &=\left[\begin{array}{ccc}{3}&{1}&{17}\\{7}&{1}&{39}\end{array}\right]\end{aligned} \nonumber \]

    So again note that the columns of \(X\) are \(\vec{u}\), \(\vec{v}\) and \(\vec{w}\); that is, we can write

    \[X=\left[\begin{array}{ccc}{\vec{u}}&{\vec{v}}&{\vec{w}}\end{array}\right]. \nonumber \]

    Notice also that the columns of \(AX\) are \(A\vec{u}\), \(A\vec{v}\) and \(A\vec{w}\), respectively. Thus we can write

    \[\begin{align}\begin{aligned}AX&=A\left[\begin{array}{ccc}{\vec{u}}&{\vec{v}}&{\vec{w}}\end{array}\right] \\ &=\left[\begin{array}{ccc}{A\vec{u}}&{A\vec{v}}&{A\vec{w}}\end{array}\right] \\ &=\left[\begin{array}{ccc}{\left[\begin{array}{c}{3}\\{7}\end{array}\right]}&{\left[\begin{array}{c}{1}\\{1}\end{array}\right]}&{\left[\begin{array}{c}{17}\\{39}\end{array}\right]}\end{array}\right] \\ &=\left[\begin{array}{ccc}{3}&{1}&{17}\\{7}&{1}&{39}\end{array}\right]\end{aligned}\end{align} \nonumber \]

    We summarize what we saw above in the following statement:

    The columns of a matrix product \(AX\) are \(A\) times the columns of \(X\).

    How does this help us solve the matrix equation \(AX=B\) for \(X\)? Assume that \(A\) is a square matrix (that forces \(X\) and \(B\) to be the same size). We’ll let \(\vec{x_{1}},\:\vec{x_{2}},\cdots\vec{x_{n}}\) denote the columns of the (unknown) matrix \(X\), and we’ll let \(\vec{b_{1}},\:\vec{b_{2}},\cdots\vec{b_{n}}\) denote the columns of \(B\). We want to solve \(AX=B\) for \(X\). That is, we want \(X\) where

    \[\begin{align}\begin{aligned}AX&=B\\ A\left[\begin{array}{cccc}{\vec{x_{1}}}&{\vec{x_{2}}}&{\cdots}&{\vec{x_{n}}}\end{array}\right]&=\left[\begin{array}{cccc}{\vec{b_{1}}}&{\vec{b_{2}}}&{\cdots}&{\vec{b_{n}}}\end{array}\right] \\ \left[\begin{array}{cccc}{A\vec{x_{1}}}&{A\vec{x_{2}}}&{\cdots}&{A\vec{x_{n}}}\end{array}\right]&=\left[\begin{array}{cccc}{\vec{b_{1}}}&{\vec{b_{2}}}&{\cdots}&{\vec{b_{n}}}\end{array}\right] \end{aligned}\end{align} \nonumber \]

    If the matrix on the left hand side is equal to the matrix on the right, then their respective columns must be equal. This means we need to solve \(n\) equations:

    \[\begin{align}\begin{aligned}A\vec{x_{1}}&=\vec{b_{1}}\\ A\vec{x_{2}}&=\vec{b_{2}} \\ \vdots&=\vdots \\ A\vec{x_{n}}&=\vec{b_{n}}\end{aligned}\end{align} \nonumber \]

    We already know how to do this; this is what we learned in the previous section. Let’s do this in a concrete example. In our above work we defined matrices \(A\) and \(X\), and looked at the product \(AX\). Let’s call the product \(B\); that is, set \(B=AX\). Now, let’s pretend that we don’t know what \(X\) is, and let’s try to find the matrix \(X\) that satisfies the equation \(AX=B\). As a refresher, recall that

    \[A=\left[\begin{array}{cc}{1}&{2}\\{3}&{4}\end{array}\right]\quad\text{and}\quad B=\left[\begin{array}{ccc}{3}&{1}&{17}\\{7}&{1}&{39}\end{array}\right]. \nonumber \]

    Since \(A\) is a \(2\times 2\) matrix and \(B\) is a \(2\times 3\) matrix, what dimensions must \(X\) be in the equation \(AX=B\)? The number of rows of \(X\) must match the number of columns of \(A\); the number of columns of \(X\) must match the number of columns of \(B\). Therefore we know that \(X\) must be a \(2\times 3\) matrix.

    We’ll call the three columns of \(X\) \(\vec{x_{1}},\:\vec{x_{2}}\) and \(\vec{x_{3}}\). Our previous explanation tells us that if \(AX=B\), then:

    \[\begin{align}\begin{aligned}AX&=B \\ A\left[\begin{array}{c}{\vec{x_{1}}}&{\vec{x_{2}}}&{\vec{x_{3}}}\end{array}\right]&=\left[\begin{array}{ccc}{3}&{1}&{17}\\{7}&{1}&{39}\end{array}\right] \\ \left[\begin{array}{ccc}{A\vec{x_{1}}}&{A\vec{x_{2}}}&{A\vec{x_{3}}}\end{array}\right] &=\left[\begin{array}{ccc}{3}&{1}&{17}\\{7}&{1}&{39}\end{array}\right] \end{aligned}\end{align} \nonumber \]

    Hence

    \[\begin{align}\begin{aligned}A\vec{x_{1}}&=\left[\begin{array}{c}{3}\\{7}\end{array}\right] \\ A\vec{x_{2}}&=\left[\begin{array}{c}{1}\\{1}\end{array}\right] \\ A\vec{x_{3}}&=\left[\begin{array}{c}{17}\\{39}\end{array}\right]\end{aligned}\end{align} \nonumber \]

    To find \(\vec{x_{1}}\), we form the proper augmented matrix and put it into reduced row echelon form and interpret the results.

    \[\left[\begin{array}{ccc}{1}&{2}&{3}\\{3}&{4}&{7}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{ccc}{1}&{0}&{1}\\{0}&{1}&{1}\end{array}\right] \nonumber \]

    This shows us that

    \[\vec{x_{1}}=\left[\begin{array}{c}{1}\\{1}\end{array}\right]. \nonumber \]

    To find \(\vec{x_{2}}\), we again form an augmented matrix and interpret its reduced row echelon form.

    \[\left[\begin{array}{ccc}{1}&{2}&{1}\\{3}&{4}&{1}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{ccc}{1}&{0}&{-1}\\{0}&{1}&{1}\end{array}\right] \nonumber \]

    Thus

    \[\vec{x_{2}}=\left[\begin{array}{c}{-1}\\{1}\end{array}\right] \nonumber \]

    which matches with what we already knew from above.

    Before continuing on in this manner to find \(\vec{x_{3}}\), we should stop and think. If the matrix vector equation \(A\vec{x}=\vec{b}\) is consistent, then the steps involved in putting

    \[\left[\begin{array}{cc}{A}&{\vec{b}}\end{array}\right] \nonumber \]

    into reduced row echelon form depend only on \(A\); it does not matter what \(\vec{b}\) is. So when we put the two matrices

    \[\left[\begin{array}{ccc}{1}&{2}&{3}\\{3}&{4}&{7}\end{array}\right]\quad\text{and}\quad\left[\begin{array}{ccc}{1}&{2}&{1}\\{3}&{4}&{1}\end{array}\right] \nonumber \]

    from above into reduced row echelon form, we performed exactly the same steps! (In fact, those steps are: \(-3R_1+R_2\rightarrow R_2\); \(-\frac12R_2\rightarrow R_2\); \(-2R_2+R_1\rightarrow R_1\).)

    Instead of solving for each column of \(X\) separately, performing the same steps to put the necessary matrices into reduced row echelon form three different times, why don’t we just do it all at once?\(^{1}\) Instead of individually putting

    \[\left[\begin{array}{ccc}{1}&{2}&{3}\\{3}&{4}&{7}\end{array}\right],\quad\left[\begin{array}{ccc}{1}&{2}&{1}\\{3}&{4}&{1}\end{array}\right]\quad\text{and}\quad\left[\begin{array}{ccc}{1}&{2}&{17}\\{3}&{4}&{39}\end{array}\right] \nonumber \]

    into reduced row echelon form, let's just put

    \[\left[\begin{array}{ccccc}{1}&{2}&{3}&{1}&{17}\\{3}&{4}&{7}&{1}&{39}\end{array}\right] \nonumber \]

    into reduced row echelon form.

    \[\left[\begin{array}{ccccc}{1}&{2}&{3}&{1}&{17}\\{3}&{4}&{7}&{1}&{39}\end{array}\right]\quad\vec{\text{rref}}\quad\left[\begin{array}{ccccc}{1}&{0}&{1}&{-1}&{5}\\{0}&{1}&{1}&{1}&{6}\end{array}\right] \nonumber \]

    By looking at the last three columns, we see \(X\):

    \[X=\left[\begin{array}{ccc}{1}&{-1}&{5}\\{1}&{1}&{6}\end{array}\right]. \nonumber \]

    Now that we’ve justified the technique we’ve been using in this section to solve \(AX=B\) for \(X\), we reinforce its importance by restating it as a Key Idea.

    Key Idea \(\PageIndex{1}\): Solving \(AX=B\)

    Let \(A\) be an \(n\times n\) matrix, where the reduced row echelon form of \(A\) is \(I\). To solve the matrix equation \(AX=B\) for \(X\),

    1. Form the augmented matrix \(\left[\begin{array}{cc}{A}&{B}\end{array}\right]\).
    2. Put this matrix into reduced row echelon form. It will be of the form \(\left[\begin{array}{cc}{I}&{X}\end{array}\right]\), where \(X\) appears in the columns where \(B\) once was.

    These simple steps cause us to ask certain questions. First, we specify above that \(A\) should be a square matrix. What happens if \(A\) isn’t square? Is a solution still possible? Secondly, we only considered cases where the reduced row echelon form of \(A\) was \(I\) (and stated that as a requirement in our Key Idea). What if the reduced row echelon form of \(A\) isn’t ? Would we still be able to find a solution? (Instead of having exactly one solution, could we have no solution? Infinite solutions? How would we be able to tell?)

    These questions are good to ask, and we leave it to the reader to discover their answers. Instead of tackling these questions, we instead tackle the problem of “Why do we care about solving \(AX=B\)?” The simple answer is that, for now, we only care about the special case when \(B=I\). By solving \(AX=I\) for \(X\), we find a matrix \(X\) that, when multiplied by \(A\), gives the identity \(I\). That will be very useful.

    Footnotes

    [1] One reason to do it three different times is that we enjoy doing unnecessary work. Another reason could be that we are stupid.↩︎


    This page titled 2.5: Solving Matrix Equations AX=B is shared under a CC BY-NC 3.0 license and was authored, remixed, and/or curated by Gregory Hartman et al. via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.