Search for probability and statistics terms on Statlect
StatLect

Matrix multiplication

by , PhD

This lecture introduces matrix multiplication, one of the basic algebraic operations that can be performed on matrices.

Table of Contents

Dot product

Before defining matrix multiplication, we need to introduce the concept of dot product of two vectors.

Definition Let A be a $1	imes K$ row vector and $B$ a Kx1 column vector. Denote their entries by [eq1] and by [eq2], respectively. Then, their dot product $AB$ is[eq3]

Note that in the above definition the order of the product matters, that is $AB$ is not the same as $BA$, because the first vector (A) needs to be a row vector, and the second one ($B$) needs to be a column vector. Furthermore, the dot product is defined only if A and $B$ have the same number of entries (K).

Example Let A be a $1	imes 3$ vector defined by[eq4]and $B$ a $3	imes 1$ vector defined by[eq5]Their dot product $AB$ is[eq6]

Matrix product

We are now ready to define matrix product.

Definition Let A be a $K	imes L$ matrix and $B$ a $L	imes M$ matrix. Then, their product $AB$ is a $K	imes M$ matrix whose $left( k,m
ight) $-th entry is equal to the dot product between the k-th row of A and the $m$-th column of $B$, for $1leq kleq K$ and $1leq mleq M$.

In other words, the $left( k,m
ight) $-th entry of $AB$ is[eq7]

Note that the order of the product matters, that is $AB$ is not the same as $BA$. Furthermore, the number of columns of A needs to be equal to the number of rows of $B$ (in which case the two matrices are said to be conformable for the multiplication $AB$).

The next diagram summarizes the dimensions involved in matrix multiplication:[eq8]

Example Define the $2	imes 3$ matrix[eq9]and the $3	imes 2$ matrix [eq10]They are conformable for the multiplication $AB$ because the number of columns of A is equal to the number of rows of $B$. The dimension of the matrix $AB$ is $2	imes 2$. The product is[eq11]where, for example, the $left( 2,1
ight) $-th entry of $AB$ has been obtained from the dot product of the second row of A with the first column of $B$:[eq12]

Motivation

Why is matrix multiplication defined in this way? There are many possible answers to this question, but the simplest one has to do with the need of obtaining a simple matrix representation for systems of linear equations. The next example shows how.

Example Consider the following system of two equations in two unknowns:[eq13]This can be represented in matrix form as[eq14]where the matrix of coefficients is[eq15]the vector of unknowns is[eq16]and the vector of constants is[eq17]You can easily check that the two ways of writing the system of equations are equivalent by performing the matrix multiplication[eq18]

Another reason why matrix multiplication is defined in the manner shown above is that it allows us to easily deal with input-output systems in which given outputs can be obtained from fixed combinations of inputs.

Example A factory can produce two goods, denoted by $O_{1}$ and $O_{2}$, using different combinations of two inputs, $I_{1}$ and $I_{2}$. In particular, $2$ units of $I_{1}$ and 1 unit of $I_{2}$ are needed to produce a unit of $O_{1}$, and 1 unit of $I_{1}$ and $3$ units of $I_{2}$ are needed to produce a unit of $O_{2}$. This information can be summarized by the input-output matrix[eq19]where the two rows correspond to the two outputs and the two columns correspond to the two inputs. Each unit of $I_{1}$ costs $2$ dollars, and each unit of $I_{2}$ costs 1 dollar. This information can be summarized by the vector of prices[eq20]In order to find the costs of producing the two outputs, it suffices to perform the following matrix multiplication[eq21]So, both outputs have a production cost of $5$ dollars.

Properties of matrix multiplication

As we have already said, unlike multiplication of real numbers, matrix multiplication does not enjoy the commutative property, that is, $AB$ is not the same as $BA$. However, some of the properties enjoyed by multiplication of real numbers are also enjoyed by matrix multiplication.

Proposition (distributive property) Matrix multiplication is distributive with respect to matrix addition, that is,[eq22]for any matrices A, $B$ and $C$ such that the above multiplications and additions are meaningfully defined.

Proof

Let us start with the product[eq23]Let A and $B$ be $K	imes L$ matrices, and $C$ an $L	imes M$ matrix. Denote a generic $left( k,l
ight) $-th element of the matrix $A+B$ by [eq24], and a generic $left( k,m
ight) $-th element of the product between $left( A+B
ight) $ and $C$ by [eq25]. By the definitions of matrix addition and matrix multiplication, we have that[eq26]where: in steps $rame{A}$ and $rame{C}$ we have used the definition of matrix multiplication; in step $rame{B}$ we have used the definition of matrix addition. This holds for any $left( k,m
ight) $-th element of the matrix. Therefore, we have that[eq27]

With an almost identical argument it is possible to prove that[eq28]

Proposition (associative property) Matrix multiplication is associative, that is,[eq29]for any matrices A, $B$ and $C$ such that the above multiplications are meaningfully defined.

Proof

Suppose A has dimension $K	imes L$, $B$ has dimension $L	imes M$, and $C$ has dimension $M	imes N$. Associativity holds because a generic $left( k,n
ight) $-th element of the matrix $Aleft( BC
ight) $ is[eq30]where we have used the definition of product between A and $BC$ (step $rame{A}$), between $B$ and $C$ (step $rame{B}$), between A and $B$ (step $rame{C}$), between $AB$ and $C$ (step $rame{D}$).

Other properties

Other properties of matrix products are listed here.

Transpose of a product

Proposition Let A be a $K	imes L$ matrix and $B$ a $L	imes M$ matrix. Let $A^{	op }$ and $B^{	op }$ be their transposes. Then,[eq31]

Proof

The $left( k,m
ight) $-th entry of $AB$ is the dot product of the k-th row of A and the $m$-th column of $B$:[eq32]By the definition of matrix transpose, the latter is equal to the $left( m,k
ight) $-th entry of [eq33]:[eq34]The $left( m,k
ight) $-th entry $B^{	op }A^{	op }$ is the dot product of the $m$-th row of $B^{	op }$ and the k-th column of $A^{	op }$: [eq35]Since the $m$-th row of $B^{	op }$ is equal to the $m$-th column of $B$, and the k-th column of $A^{	op }$ is equal to the k-th row of A, we have[eq36]Thus,[eq37]for any $m$ and k. Therefore,[eq38]

Solved exercises

Below you can find some exercises with explained solutions.

Exercise 1

Define a $3	imes 3$ matrix[eq39]and a $3	imes 2$ matrix[eq40]Compute the product $AB$.

Solution

The dimensions involved in this multiplication are summarized in the following diagram:[eq41]Thus, $AB$ is a $3	imes 2$ matrix such that for each $1leq kleq 3$ and $1leq mleq 2$, the $left( k,m
ight) $-th element of $AB$ is equal to the dot product between the k-th row of A and the $m$-th row of $B$: [eq42]

Exercise 2

Given the matrices A and $B$ defined above, compute the product $BA$.

Solution

The matrices A and $B$ are not conformable for the multiplication $BA$ because the number of columns of $B$ is not equal to the number of rows of $A $. Therefore, multiplication cannot be carried out.

Exercise 3

Define a $2	imes 1$ column vector[eq43]and a $1	imes 3$ row vector[eq44]Compute the product $AB$.

Solution

The dimensions involved in this multiplication are summarized in the following diagram:[eq45]Thus, $AB$ is a $2	imes 3$ matrix. It is computed as follows: [eq46]Note that each element of $AB$ is the product of a row of A with a column of $B$. But the rows of A are scalars, because A is a column vector, and the columns of $B$ are also scalars, because $B$ is a row vector. As a consequence, each entry of $AB$ is obtained as the product of two scalars.

How to cite

Please cite as:

Taboga, Marco (2021). "Matrix multiplication", Lectures on matrix algebra. https://www.statlect.com/matrix-algebra/matrix-multiplication.

The books

Most of the learning materials found on this website are now available in a traditional textbook format.