Finding the Product of Two Matrices

In addition to multiplying a matrix by a scalar, we can multiply two matrices. Finding the product of two matrices is only possible when the inner dimensions are the same, meaning that the number of columns of the first matrix is equal to the number of rows of the second matrix. If

AA
is an
 m × r \text{ }m\text{ }\times \text{ }r\text{ }
matrix and
BB
is an
 r × n \text{ }r\text{ }\times \text{ }n\text{ }
matrix, then the product matrix
ABAB
is an
 m × n \text{ }m\text{ }\times \text{ }n\text{ }
matrix. For example, the product
ABAB
is possible because the number of columns in
AA
is the same as the number of rows in
BB
. If the inner dimensions do not match, the product is not defined.

A has two rows and three columns and B has three rows and three columns. Because the number of columns in A matches the number of rows in B, the product of A and B is defined.Figure 1


We multiply entries of
AA
with entries of
BB
according to a specific pattern as outlined below. The process of matrix multiplication becomes clearer when working a problem with real numbers.

To obtain the entries in row
ii
of
AB,AB,\text{}
we multiply the entries in row
ii
of
AA
by column
jj
in
BB
and add. For example, given matrices
AA
and
B,B,\text{}
where the dimensions of
AA
are
2 × 32\text{ }\times \text{ }3
and the dimensions of
BB
are
3 × 3,3\text{ }\times \text{ }3,\text{}
the product of
ABAB
will be a
2 × 32\text{ }\times \text{ }3
matrix.

A=[a11a12a13a21a22a23] and B=[b11b12b13b21b22b23b31b32b33]A=\left[\begin{array}{rrr}\qquad {a}_{11}& \qquad {a}_{12}& \qquad {a}_{13}\\ \qquad {a}_{21}& \qquad {a}_{22}& \qquad {a}_{23}\end{array}\right]\text{ and }B=\left[\begin{array}{rrr}\qquad {b}_{11}& \qquad {b}_{12}& \qquad {b}_{13}\\ \qquad {b}_{21}& \qquad {b}_{22}& \qquad {b}_{23}\\ \qquad {b}_{31}& \qquad {b}_{32}& \qquad {b}_{33}\end{array}\right]
Multiply and add as follows to obtain the first entry of the product matrix
ABAB
.

  1. To obtain the entry in row 1, column 1 of
    AB,AB,\text{}
    multiply the first row in
    AA
    by the first column in
    BB
    , and add.

    [a11a12a13][b11b21b31]=a11b11+a12b21+a13b31\left[\begin{array}{ccc}{a}_{11}& {a}_{12}& {a}_{13}\end{array}\right]\cdot \left[\begin{array}{c}{b}_{11}\\ {b}_{21}\\ {b}_{31}\end{array}\right]={a}_{11}\cdot {b}_{11}+{a}_{12}\cdot {b}_{21}+{a}_{13}\cdot {b}_{31}
  2. To obtain the entry in row 1, column 2 of
    AB,AB,\text{}
    multiply the first row of
    AA
    by the second column in
    BB
    , and add.

    [a11a12a13][b12b22b32]=a11b12+a12b22+a13b32\left[\begin{array}{ccc}{a}_{11}& {a}_{12}& {a}_{13}\end{array}\right]\cdot \left[\begin{array}{c}{b}_{12}\\ {b}_{22}\\ {b}_{32}\end{array}\right]={a}_{11}\cdot {b}_{12}+{a}_{12}\cdot {b}_{22}+{a}_{13}\cdot {b}_{32}
  3. To obtain the entry in row 1, column 3 of
    AB,AB,\text{}
    multiply the first row of
    AA
    by the third column in
    BB
    , and add.

    [a11a12a13][b13b23b33]=a11b13+a12b23+a13b33\left[\begin{array}{ccc}{a}_{11}& {a}_{12}& {a}_{13}\end{array}\right]\cdot \left[\begin{array}{c}{b}_{13}\\ {b}_{23}\\ {b}_{33}\end{array}\right]={a}_{11}\cdot {b}_{13}+{a}_{12}\cdot {b}_{23}+{a}_{13}\cdot {b}_{33}


We proceed the same way to obtain the second row of
ABAB
. In other words, row 2 of
AA
times column 1 of
BB
; row 2 of
AA
times column 2 of
BB
; row 2 of
AA
times column 3 of
BB
. When complete, the product matrix will be

AB=[a11b11+a12b21+a13b31a21b11+a22b21+a23b31a11b12+a12b22+a13b32a21b12+a22b22+a23b32a11b13+a12b23+a13b33a21b13+a22b23+a23b33]AB=\left[\begin{array}{c}\begin{array}{l}{a}_{11}\cdot {b}_{11}+{a}_{12}\cdot {b}_{21}+{a}_{13}\cdot {b}_{31}\\ \end{array}\\ {a}_{21}\cdot {b}_{11}+{a}_{22}\cdot {b}_{21}+{a}_{23}\cdot {b}_{31}\end{array}\begin{array}{c}\begin{array}{l}{a}_{11}\cdot {b}_{12}+{a}_{12}\cdot {b}_{22}+{a}_{13}\cdot {b}_{32}\\ \end{array}\\ {a}_{21}\cdot {b}_{12}+{a}_{22}\cdot {b}_{22}+{a}_{23}\cdot {b}_{32}\end{array}\begin{array}{c}\begin{array}{l}{a}_{11}\cdot {b}_{13}+{a}_{12}\cdot {b}_{23}+{a}_{13}\cdot {b}_{33}\\ \end{array}\\ {a}_{21}\cdot {b}_{13}+{a}_{22}\cdot {b}_{23}+{a}_{23}\cdot {b}_{33}\end{array}\right]

A General Note: Properties of Matrix Multiplication

For the matrices
A,B,A,B,\text{}
and
CC
the following properties hold.

  • Matrix multiplication is associative:
    (AB)C=A(BC)\left(AB\right)C=A\left(BC\right)
    .
  • Matrix multiplication is distributive:
    C(A+B)=CA+CB,(A+B)C=AC+BC.\begin{array}{l}\begin{array}{l}\\ C\left(A+B\right)=CA+CB,\end{array}\qquad \\ \left(A+B\right)C=AC+BC.\qquad \end{array}


Note that matrix multiplication is not commutative.

Example 8: Multiplying Two Matrices

Multiply matrix
AA
and matrix
BB
.

A=[1234] and B=[5678]A=\left[\begin{array}{cc}1& 2\\ 3& 4\end{array}\right]\text{ and }B=\left[\begin{array}{cc}5& 6\\ 7& 8\end{array}\right]

Solution

First, we check the dimensions of the matrices. Matrix
AA
has dimensions
2×22\times 2
and matrix
BB
has dimensions
2×22\times 2
. The inner dimensions are the same so we can perform the multiplication. The product will have the dimensions
2×22\times 2
.

We perform the operations outlined previously.

The first column of the product of A and B is defined as the result of matrix -vector multiplication of A and the first column of B. Column two of the product of A and B is defined as the result of the matrix-vector multiplication of A and the second column of B.Figure 2


Example 9: Multiplying Two Matrices

Given
AA
and
B:B:


  1. Find
    ABAB
    .
  2. Find
    BABA
    .
A=[123405] and B=[542103]A=\left[\begin{array}{l}\begin{array}{ccc}-1& 2& 3\end{array}\qquad \\ \begin{array}{ccc}4& 0& 5\end{array}\qquad \end{array}\right]\text{ and }B=\left[\begin{array}{c}5\\ -4\\ 2\end{array}\begin{array}{c}-1\\ 0\\ 3\end{array}\right]

Solution

  1. As the dimensions of
    AA
    are
    2×32\text{}\times \text{}3
    and the dimensions of
    BB
    are
    3×2,3\text{}\times \text{}2,\text{}
    these matrices can be multiplied together because the number of columns in
    AA
    matches the number of rows in
    BB
    . The resulting product will be a
    2×22\text{}\times \text{}2
    matrix, the number of rows in
    AA
    by the number of columns in
    BB
    .

    AB=[123405] [514023] =[1(5)+2(4)+3(2)1(1)+2(0)+3(3)4(5)+0(4)+5(2)4(1)+0(0)+5(3)] =[7103011]\begin{array}{l}\qquad \\ AB=\left[\begin{array}{rrr}\qquad -1& \qquad 2& \qquad 3\\ \qquad 4& \qquad 0& \qquad 5\end{array}\right]\text{ }\left[\begin{array}{rr}\qquad 5& \qquad -1\\ \qquad -4& \qquad 0\\ \qquad 2& \qquad 3\end{array}\right]\qquad \\ \text{ }=\left[\begin{array}{rr}\qquad -1\left(5\right)+2\left(-4\right)+3\left(2\right)& \qquad -1\left(-1\right)+2\left(0\right)+3\left(3\right)\\ \qquad 4\left(5\right)+0\left(-4\right)+5\left(2\right)& \qquad 4\left(-1\right)+0\left(0\right)+5\left(3\right)\end{array}\right]\qquad \\ \text{ }=\left[\begin{array}{rr}\qquad -7& \qquad 10\\ \qquad 30& \qquad 11\end{array}\right]\qquad \end{array}
  2. The dimensions of
    BB
    are
    3×23\times 2
    and the dimensions of
    AA
    are
    2×32\times 3
    . The inner dimensions match so the product is defined and will be a
    3×33\times 3
    matrix.

    BA=[514023] [123405] =[5(1)+1(4)5(2)+1(0)5(3)+1(5)4(1)+0(4)4(2)+0(0)4(3)+0(5)2(1)+3(4)2(2)+3(0)2(3)+3(5)] =[91010481210421]\begin{array}{l}\qquad \\ BA=\left[\begin{array}{rr}\qquad 5& \qquad -1\\ \qquad -4& \qquad 0\\ \qquad 2& \qquad 3\end{array}\right]\text{ }\left[\begin{array}{rrr}\qquad -1& \qquad 2& \qquad 3\\ \qquad 4& \qquad 0& \qquad 5\end{array}\right]\qquad \\ \text{ }=\left[\begin{array}{rrr}\qquad 5\left(-1\right)+-1\left(4\right)& \qquad 5\left(2\right)+-1\left(0\right)& \qquad 5\left(3\right)+-1\left(5\right)\\ \qquad -4\left(-1\right)+0\left(4\right)& \qquad -4\left(2\right)+0\left(0\right)& \qquad -4\left(3\right)+0\left(5\right)\\ \qquad 2\left(-1\right)+3\left(4\right)& \qquad 2\left(2\right)+3\left(0\right)& \qquad 2\left(3\right)+3\left(5\right)\end{array}\right]\qquad \\ \text{ }=\left[\begin{array}{rrr}\qquad -9& \qquad 10& \qquad 10\\ \qquad 4& \qquad -8& \qquad -12\\ \qquad 10& \qquad 4& \qquad 21\end{array}\right]\qquad \end{array}

Analysis of the Solution

Notice that the products
ABAB
and
BABA
are not equal.

AB=[7103011][91010481210421]=BAAB=\left[\begin{array}{cc}-7& 10\\ 30& 11\end{array}\right]\ne \left[\begin{array}{ccc}-9& 10& 10\\ 4& -8& -12\\ 10& 4& 21\end{array}\right]=BA
This illustrates the fact that matrix multiplication is not commutative.

Q & A

Is it possible for AB to be defined but not BA?

Yes, consider a matrix A with dimension
3×43\times 4
and matrix B with dimension
4×24\times 2
. For the product AB the inner dimensions are 4 and the product is defined, but for the product BA the inner dimensions are 2 and 3 so the product is undefined.


Example 10: Using Matrices in Real-World Problems

Let’s return to the problem presented at the opening of this section. We have the table below, representing the equipment needs of two soccer teams.

Wildcats Mud Cats
Goals 6 10
Balls 30 24
Jerseys 14 20
We are also given the prices of the equipment, as shown in the table below.

Goal $300
Ball $10
Jersey $30
We will convert the data to matrices. Thus, the equipment need matrix is written as

E=[63014102420]E=\left[\begin{array}{c}6\\ 30\\ 14\end{array}\begin{array}{c}10\\ 24\\ 20\end{array}\right]
The cost matrix is written as

C=[3001030]C=\left[\begin{array}{ccc}300& 10& 30\end{array}\right]
We perform matrix multiplication to obtain costs for the equipment.

CE=[3001030][61030241420] =[300(6)+10(30)+30(14)300(10)+10(24)+30(20)] =[2,5203,840]\begin{array}{l}\qquad \\ \qquad \\ CE=\left[\begin{array}{rrr}\qquad 300& \qquad 10& \qquad 30\end{array}\right]\cdot \left[\begin{array}{rr}\qquad 6& \qquad 10\\ \qquad 30& \qquad 24\\ \qquad 14& \qquad 20\end{array}\right]\qquad \\ \text{ }=\left[\begin{array}{rr}\qquad 300\left(6\right)+10\left(30\right)+30\left(14\right)& \qquad 300\left(10\right)+10\left(24\right)+30\left(20\right)\end{array}\right]\qquad \\ \text{ }=\left[\begin{array}{rr}\qquad 2,520& \qquad 3,840\end{array}\right]\qquad \end{array}
The total cost for equipment for the Wildcats is $2,520, and the total cost for equipment for the Mud Cats is $3,840.

How To: Given a matrix operation, evaluate using a calculator.

  1. Save each matrix as a matrix variable
    [A],[B],[C],..\left[A\right],\left[B\right],\left[C\right],..
    .
  2. Enter the operation into the calculator, calling up each matrix variable as needed.
  3. If the operation is defined, the calculator will present the solution matrix; if the operation is undefined, it will display an error message.

Example 11: Using a Calculator to Perform Matrix Operations

Find
ABCAB-C
 given

A=[1525324172810342],B=[45213724521964831],and C=[1008998255674674275]A=\left[\begin{array}{rrr}\qquad -15& \qquad 25& \qquad 32\\ \qquad 41& \qquad -7& \qquad -28\\ \qquad 10& \qquad 34& \qquad -2\end{array}\right],B=\left[\begin{array}{rrr}\qquad 45& \qquad 21& \qquad -37\\ \qquad -24& \qquad 52& \qquad 19\\ \qquad 6& \qquad -48& \qquad -31\end{array}\right],\text{and }C=\left[\begin{array}{rrr}\qquad -100& \qquad -89& \qquad -98\\ \qquad 25& \qquad -56& \qquad 74\\ \qquad -67& \qquad 42& \qquad -75\end{array}\right]
.

Solution

On the matrix page of the calculator, we enter matrix
AA
above as the matrix variable
[A]\left[A\right]
, matrix
BB
above as the matrix variable
[B]\left[B\right]
, and matrix
CC
above as the matrix variable
[C]\left[C\right]
.

On the home screen of the calculator, we type in the problem and call up each matrix variable as needed.

[A]×[B][C]\left[A\right]\times \left[B\right]-\left[C\right]
The calculator gives us the following matrix.

[9834621361,8201,8978563112,032413]\left[\begin{array}{rrr}\qquad -983& \qquad -462& \qquad 136\\ \qquad 1,820& \qquad 1,897& \qquad -856\\ \qquad -311& \qquad 2,032& \qquad 413\end{array}\right]

Licenses and Attributions

More Study Resources for You

Show More