Ma · Mathematics

What Are the Practical Uses of Matrix Multiplication?

Published By the 9to5Science editorial team

At a glance

  1. 1. Interpret the dimensions

    Check that the first matrix’s columns equal the second matrix’s rows.

  2. 2. Multiply rows by columns

    Each output entry is a row–column dot product.

  3. 3. Interpret the result

    Read the product as a combined transformation, data calculation, or network operation.

  4. 4. Apply the model

    Use the resulting matrix for graphics, systems, probabilities, or data analysis.

Try it: Matrix calculator

Matrix multiplication is more than a rule for filling in a larger table of numbers. It is a compact way to combine linear operations and to calculate many weighted sums simultaneously. That is why it appears in computer graphics, engineering, probability, economics, data analysis, and machine learning.

The key interpretation is this: if matrix BB performs one operation and matrix AA performs another, then ABAB represents doing BB first and AA second.

How matrix multiplication works

If AA has dimensions m×nm \times n and BB has dimensions n×pn \times p, then the product ABAB exists and has dimensions m×pm \times p. Its entries are

(AB)ij=∑k=1naikbkj.(AB)_{ij}=\sum_{k=1}^{n} a_{ik}b_{kj}.

In plain language, each entry of ABAB is the dot product of one row of AA with one column of BB.

For example, let

A=[21−13],B=[4052].A=\begin{bmatrix}2&1\\-1&3\end{bmatrix},\qquad B=\begin{bmatrix}4&0\\5&2\end{bmatrix}.

Then

AB=[2⋅4+1⋅52⋅0+1⋅2(−1)⋅4+3⋅5(−1)⋅0+3⋅2]=[132116].AB=\begin{bmatrix} 2\cdot4+1\cdot5 & 2\cdot0+1\cdot2\\ (-1)\cdot4+3\cdot5 & (-1)\cdot0+3\cdot2 \end{bmatrix} =\begin{bmatrix}13&2\\11&6\end{bmatrix}.

The order matters. In general, AB≠BAAB\ne BA, and sometimes BABA is not even defined.

Combining geometric transformations

A point in the plane can be represented as a column vector:

x=[xy].\mathbf{x}=\begin{bmatrix}x\\y\end{bmatrix}.

A matrix can rotate, reflect, stretch, or shear that point. For example, the matrix

R=[0−110]R=\begin{bmatrix}0&-1\\1&0\end{bmatrix}

rotates vectors 90∘90^\circ counterclockwise, because

R[10]=[01].R\begin{bmatrix}1\\0\end{bmatrix} =\begin{bmatrix}0\\1\end{bmatrix}.

The matrix

S=[2003]S=\begin{bmatrix}2&0\\0&3\end{bmatrix}

stretches horizontal coordinates by 22 and vertical coordinates by 33.

To stretch first and then rotate, use RSRS, not SRSR:

RS=[0−320].RS=\begin{bmatrix}0&-3\\2&0\end{bmatrix}.

Applied to (1,1)(1,1), this gives

RS[11]=[−32].RS\begin{bmatrix}1\\1\end{bmatrix} =\begin{bmatrix}-3\\2\end{bmatrix}.

This idea is used constantly in computer graphics, animation, robotics, computer vision, and geographic coordinate systems. A three-dimensional graphics program may multiply a model matrix, a rotation matrix, a camera matrix, and a projection matrix to determine where an object appears on the screen.

Solving many linear equations

A system of linear equations can be written as

Ax=b.A\mathbf{x}=\mathbf{b}.

For example, the system

2x+y=7,x−y=1\begin{aligned} 2x+y&=7,\\ x-y&=1 \end{aligned}

becomes

[211−1][xy]=[71].\begin{bmatrix}2&1\\1&-1\end{bmatrix} \begin{bmatrix}x\\y\end{bmatrix} =\begin{bmatrix}7\\1\end{bmatrix}.

Matrix multiplication packages both left-hand sides into one expression. This makes it possible to use systematic methods such as Gaussian elimination, matrix factorizations, or numerical software.

The same structure models currents in electrical circuits, forces in mechanical systems, chemical reaction balances, supply and demand equations, and constraints in engineering designs.

Weighted sums in data analysis

Suppose three products have prices \2,, $5,and, and $8,andashopsells, and a shop sells 10,, 4,and, and 3$ units. Put the prices in a row vector and the quantities in a column vector:

[258][1043]=2(10)+5(4)+8(3)=64.\begin{bmatrix}2&5&8\end{bmatrix} \begin{bmatrix}10\\4\\3\end{bmatrix} =2(10)+5(4)+8(3)=64.

The product gives the total revenue, \64$.

With many shops or many products, matrices perform all these calculations together. A matrix of observations can be multiplied by a vector of weights to produce scores, predictions, totals, or averages. This is the basic operation behind linear regression and many other statistical models.

For instance, if a prediction uses income, years of experience, and an intercept, the model can be written as

y^=Xβ,\hat{\mathbf{y}}=X\boldsymbol{\beta},

where each row of XX describes one case and β\boldsymbol{\beta} contains the fitted coefficients.

Networks and repeated processes

A matrix can describe connections in a network. In an adjacency matrix, the entry aija_{ij} may be 11 when node ii connects to node jj and 00 otherwise. The entries of A2=AAA^2=AA count the number of two-step paths between nodes. More generally, AkA^k describes walks of length kk.

Matrix multiplication also models repeated transitions. In a Markov chain, using the column-vector convention, let PijP_{ij} be the probability of moving from state jj to state ii, so each column of PP sums to 11. If p0\mathbf{p}_0 is the initial probability vector, then

p1=Pp0,p2=P2p0.\mathbf{p}_1=P\mathbf{p}_0,\qquad \mathbf{p}_2=P^2\mathbf{p}_0.

Thus P2P^2 gives two-step transition probabilities, and P10P^{10} gives probabilities after ten steps. Applications include inventory systems, web-page ranking, population models, queues, and board-game simulations.

Images and machine learning

An image can be stored as a matrix of pixel intensities. Matrix operations can blur, sharpen, resize, or transform the image. A simple operation may replace each pixel by a weighted combination of nearby pixels; this is closely related to matrix-based filtering and convolution.

In a neural network layer, the main calculation is typically

z=Wx+b,\mathbf{z}=W\mathbf{x}+\mathbf{b},

followed by a nonlinear activation function. Here WW contains learned weights, x\mathbf{x} contains input features, and b\mathbf{b} contains biases. Multiplying WW by many input vectors is what allows the network to process large datasets efficiently.

Common mistakes

  • Ignoring dimensions: An m×nm\times n matrix can multiply an n×pn\times p matrix, not an arbitrary pair of matrices.
  • Multiplying corresponding entries: Ordinary matrix multiplication uses row–column dot products. Entrywise multiplication is a different operation.
  • Reversing the order: ABAB means apply BB first and then AA when matrices represent transformations.
  • Assuming commutativity: Usually AB≠BAAB\ne BA.
  • Confusing row and column vectors: The convention affects whether a transformation is written as AxA\mathbf{x} or xA\mathbf{x}A.
  • Forgetting units: In physical models, matrix entries must have compatible units for each sum to make sense.

A useful test is to ask what each matrix represents. If the matrices describe successive transformations, transitions, or weighted calculations, their product usually has a direct practical interpretation rather than being merely an arithmetic result.

References

  1. Introduction to Linear Algebra, Gilbert Strang
  2. Linear Algebra and Its Applications, David C. Lay

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.