maths.freeLinear Algebra › 3. Matrices › Matrix multiplication

Matrix multiplication

Rows times columns, entry by entry.

Entry (i, j) of AB is row i of A dotted with column j of B, which is why the inner dimensions must match. Every entry is computed in the open below. Matrix multiplication is composition of transformations, which is why it is not commutative.

Matrix Multiplication

We know how to add vectors and how to multiply them by scalars. Together, these operations give us the possibility of making linear combinations. Similarly, we know how to add matrices and how to multiply matrices by scalars. In this section we mix all these ideas together and produce an operation known as matrix multiplication. This will lead to some results that are both surprising and central. We begin with a definition of how to multiply a vector by a matrix.

  1. \begin{bmatrix} 2 & 3 & -1 & 0\\ 1 & -2 & 7 & 3\\ 1 & 5 & 3 & 2\\ \end{bmatrix} &&\text{with}&& \colvector{2\\-3\\0\\5}
  2. \begin{bmatrix} 2 & 3 & -1 & 0\\ 1 & -2 & 7 & 3\\ 1 & 5 & 3 & 2\\ \end{bmatrix} && \begin{bmatrix} 2 & 6\\ -3 & -4\\ 0 & 2\\ 3 & -1\\ \end{bmatrix}
  3. 2x_1 + 3x_2 - x_3 &= 0\\ x_1 + 2x_2 + x_3 &= 3\\ x_1 + 3x_2 + 3x_3 &= 7

Matrix-Vector Product

We have repeatedly seen the importance of forming linear combinations of the columns of a matrix. As one example of this, the oft-used , said that every solution to a system of linear equations gives rise to a linear combination of the column vectors of the coefficient matrix that equals the vector of constants. This theorem, and others, motivate the following central definition.

So, the matrix-vector product is yet another version of multiplication, at least in the sense that we have yet again overloaded juxtaposition of two symbols as our notation. Remember your objects, an $m\times n$ matrix times a vector of size $n$ will create a vector of size $m$. So if $A$ is rectangular, then the size of the vector changes. With all the linear combinations we have performed so far, this computation should now seem second nature.

Example: A matrix times a vector

Consider A= \begin{bmatrix} 1 & 4 & 2 & 3 & 4\\ -3 & 2 & 0 & 1 & -2\\ 1 & 6 & -3 & -1 & 5 \end{bmatrix} && \vect{u}=\colvector{2\\1\\-2\\3\\-1}

Then A\vect{u}= 2\colvector{1\\-3\\1}+ 1\colvector{4\\2\\6}+ (-2)\colvector{2\\0\\-3}+ 3\colvector{3\\1\\-1}+ (-1)\colvector{4\\-2\\5} = \colvector{7\\1\\6}.

We can now represent systems of linear equations compactly with a matrix-vector product () and column vector equality (). This finally yields a very popular alternative to our unconventional $\linearsystem{A}{\vect{b}}$ notation.

Condensed — the full section is in Beezer, A First Course in Linear Algebra.

Matrix Multiplication

We now define how to multiply two matrices together. Stop for a minute and think about how you might define this new operation.

Many books would present this definition much earlier in the course. However, we have taken great care to delay it as long as possible and to present as many ideas as practical based mostly on the notion of linear combinations. Towards the conclusion of the course, or when you perhaps take a second course in linear algebra, you may be in a position to appreciate the reasons for this. For now, understand that matrix multiplication is a central definition and perhaps you will appreciate its importance more by having saved it for later.

Example: Product of two matrices

Set A= \begin{bmatrix} 1 & 2 & -1 & 4 & 6\\ 0 & -4 & 1 & 2 & 3\\ -5 & 1 & 2 & -3 & 4 \end{bmatrix} && B= \begin{bmatrix} 1 & 6 & 2 & 1\\ -1 & 4 & 3 & 2\\ 1 & 1 & 2 & 3\\ 6 & 4 & -1 & 2\\ 1 & -2 & 3 & 0 \end{bmatrix} &

Then AB= \left[ A\colvector{1\\-1\\1\\6\\1} \left\lvert A\colvector{6\\4\\1\\4\\-2}\right. \left\lvert A\colvector{2\\3\\2\\-1\\3}\right. \left\lvert A\colvector{1\\2\\3\\2\\0}\right. \right] = \begin{bmatrix} 28 & 17 & 20 & 10\\ 20 & -13 & -3 & -1\\ -18 & -44 & 12 & -3 \end{bmatrix}.

Is this the definition of matrix multiplication you expected? Perhaps our previous operations for matrices caused you to think that we might multiply two matrices of the same size, entry-by-entry? Notice that our current definition uses matrices of different sizes (though the number of columns in the first must equal the number of rows in the second), and the result is of a third size. Notice too in the previous example that we cannot even consider the product $BA$, since the sizes of the two matrices in this order are not right.

But it gets weirder than that. Many of your old ideas about multiplication will not apply to matrix multiplication, but some still will. So make no assumptions, and do not do anything until you have a theorem that says you can. Even if the sizes are right, matrix multiplication is not commutative order matters.

Condensed — the full section is in Beezer, A First Course in Linear Algebra.

Matrix Multiplication, Entry-by-Entry

While certain natural properties of multiplication do not hold, many more do. In the next subsection, we will state and prove the relevant theorems. But first, we need a theorem that provides an alternate means of multiplying two matrices. In many texts, this would be given as the definition of matrix multiplication. We prefer to turn it around and have the following formula as a consequence of our definition. It will prove useful for proofs of matrix equality, where we need to examine products of matrices, entry-by-entry.

is the way many people compute matrix products by hand. It will also be very useful for the theorems we are going to prove shortly. However, the definition () is frequently the most useful for its connections with deeper ideas like the null space and the upcoming column space.

Condensed — the full section is in Beezer, A First Course in Linear Algebra.

Properties of Matrix Multiplication

In this subsection, we collect properties of matrix multiplication and its interaction with the zero matrix (), the identity matrix (), matrix addition (), scalar matrix multiplication (), the inner product (), conjugation (), and the transpose (). Whew! Here we go. These are great proofs to practice with, so try to concoct the proofs before reading them, they will get progressively more complicated as we go.

It is this theorem that gives the identity matrix its name. It is a matrix that behaves with matrix multiplication like the scalar 1 does with scalar multiplication. To multiply by the identity matrix is to have no effect on the other matrix.

Since says matrix multipication is associative, it means we do not have to be careful about the order in which we perform matrix multiplication, nor how we parenthesize an expression with just several matrices multiplied togther. So this is where we draw the line on explaining every last detail in a proof. We will frequently add, remove, or rearrange parentheses with no comment. Indeed, I only see about a dozen places where is cited in a proof. You could try to count how many times we avoid making a reference to this theorem.

Condensed — the full section is in Beezer, A First Course in Linear Algebra.

Hermitian Matrices

The adjoint of a matrix has a basic property when employed in a matrix-vector product as part of an inner product. At this point, you could even use the following result as a motivation for the definition of an adjoint.

Sometimes a matrix is equal to its adjoint (), and these matrices have interesting properties. One of the most common situations where this occurs is when a matrix has only real number entries. Then we are simply talking about symmetric matrices (), so you can view this as a generalization of a symmetric matrix.

Again, the set of real matrices that are Hermitian is exactly the set of symmetric matrices. In we will uncover some amazing properties of Hermitian matrices, so when you get there, run back here to remind yourself of this definition. Further properties will also appear in . Right now we prove a fundamental result about Hermitian matrices, matrix vector products and inner products. As a characterization, this could be employed as a definition of a Hermitian matrix and some authors take this approach.

So, informally, Hermitian matrices are those that can be tossed around from one side of an inner product to the other with reckless abandon. We will see later what this buys us.

Condensed — the full section is in Beezer, A First Course in Linear Algebra.

Kugwira ntchito chitsanzo: [[1,2],[3,4]] * [[5,6],[7,8]]

[[1,2],[3,4]] * [[5,6],[7,8]]

\left[\begin{matrix}1 & 2\\3 & 4\end{matrix}\right] \left[\begin{matrix}5 & 6\\7 & 8\end{matrix}\right]

Gawo ndi Gawo

  1. \left[\begin{matrix}1 & 2\\3 & 4\end{matrix}\right] \left[\begin{matrix}5 & 6\\7 & 8\end{matrix}\right]

    A 2×2 times a 2×2 gives a 2×2 matrix. Entry (i, j) is row i of A dotted with column j of B.

  2. c_{11} = (1)(5) + (2)(7) = 19

  3. c_{12} = (1)(6) + (2)(8) = 22

  4. c_{21} = (3)(5) + (4)(7) = 43

  5. c_{22} = (3)(6) + (4)(8) = 50

  6. AB = \left[\begin{matrix}19 & 22\\43 & 50\end{matrix}\right]

Kusonyeza yankho
AB = \left[\begin{matrix}19 & 22\\43 & 50\end{matrix}\right]

Symbols used here

\sum_{k=1}^{n} a_k
summation
Add a_k for k = 1 up to n.
A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}
matrix
A rectangular array of numbers; a linear map.
i
imaginary unit
i² = −1.
\leq,\ \geq
less/greater than or equal
Inequalities that allow equality; < and > exclude it.
\neq
not equal
The two sides are different.
\mathbf{v},\ \vec{v}
vector
A quantity with magnitude and direction; a column of numbers.
\det A,\ |A|
determinant
Scaling factor of area/volume under A; zero means singular.
A^{-1},\ A^{T}
inverse, transpose
The matrix that undoes A; A with rows and columns swapped.
\lambda
lambda (eigenvalue)
The factor by which an eigenvector is stretched: Av = λv.
\mathbf{u} \cdot \mathbf{v},\ \|\mathbf{v}\|
dot product, norm
Σ u_i v_i; the length of v, √(v·v).

How to: Matrix multiplication

  1. A 2×2 times a 2×2 gives a 2×2 matrix. Entry (i, j) is row i of A dotted with column j of B.

Questions people ask

What does a determinant mean geometrically?

It is the factor by which the matrix scales area (2×2) or volume (3×3), with a negative sign if orientation flips. Zero means the matrix flattens space and cannot be undone.

What is an eigenvector?

A direction the matrix does not turn — it only stretches it by the eigenvalue. Along eigenvectors a complicated matrix acts like multiplication by a number.

Why is matrix multiplication not commutative?

Because a matrix is a transformation and AB means "do B, then A". Rotating then reflecting is not the same as reflecting then rotating.

Sankhani wanu

Parts of this page are adapted from Beezer, A First Course in Linear Algebra (GFDL 1.2). Condensed and re-explained here; errors are ours.

Zambiri pa Linear Algebra