Matrix Multiplication and Dot Products

⚡ Key Takeaways

Matrix multiplication combines two matrices by taking dot products of rows with columns. For matrices AA (size m×nm\times n) and BB (size n×pn\times p), the product ABAB is an m×pm\times p matrix whose (i,j)(i,j) entry is the dot product of row ii of AA with column jj of BB. Where it applies: linear systems, geometric transformations, computer graphics, statistics, machine learning. Who/when: formalized by Arthur Cayley (1858), building on work by Jacques Binet and Gotthold Eisenstein.

💡 The Core Insight

A matrix is a machine that transforms vectors. Multiplying matrices means chaining machines together. Each entry of the product is a dot product — a measure of how much one row "agrees" with one column. The dot product is the atom; matrix multiplication is the molecule built from many such atoms arranged in rows and columns.

Formal Statement

DefinitionDot Product

Given two vectors of the same length nn,

1
a=(a1,a2,…,an),b=(b1,b2,…,bn),\quad \mathbf{a}=(a_1,a_2,\dots,a_n),\qquad \mathbf{b}=(b_1,b_2,\dots,b_n),

Derivation hint: A vector is just an ordered list of numbers; both must have the same number of components for the dot product to be defined. their dot product (or scalar product) is the single number

2
a⋅b=∑k=1nakbk=a1b1+a2b2+⋯+anbn.\quad \mathbf{a}\cdot\mathbf{b}=\sum_{k=1}^{n} a_k b_k = a_1b_1 + a_2b_2 + \cdots + a_nb_n.

Derivation hint: Multiply each pair of matching entries, then add all the products together — the result is a scalar, not a vector. A second, geometric formula relates the dot product to lengths and the angle θ\theta between the vectors:

3
a⋅b=∥a∥ ∥b∥cos⁡θ,\quad \mathbf{a}\cdot\mathbf{b}=\|\mathbf{a}\|\,\|\mathbf{b}\|\cos\theta,

Derivation hint: Apply the Law of Cosines to the triangle formed by a\mathbf{a}, b\mathbf{b}, and a−b\mathbf{a}-\mathbf{b}, then expand using equation [2]. where ∥a∥=a⋅a\|\mathbf{a}\|=\sqrt{\mathbf{a}\cdot\mathbf{a}} is the length (magnitude) of a\mathbf{a}.

DefinitionMatrix Multiplication

Let AA be an m×nm\times n matrix with entries aika_{ik} and BB an n×pn\times p matrix with entries bkjb_{kj}. The product C=ABC=AB is the m×pm\times p matrix whose entries are

4
cij=∑k=1naik bkj,1≤i≤m, 1≤j≤p.\quad c_{ij}=\sum_{k=1}^{n} a_{ik}\,b_{kj},\qquad 1\le i\le m,\ 1\le j\le p.

Derivation hint: The entry in row ii, column jj of the product is the dot product of row ii of AA with column jj of BB — sum over the shared index kk.

Symbols:

  • mm = number of rows of AA (and of CC).
  • nn = number of columns of AA = number of rows of BB (the inner dimension, which must match).
  • pp = number of columns of BB (and of CC).
  • aika_{ik} = entry of AA in row ii, column kk.
  • bkjb_{kj} = entry of BB in row kk, column jj.
  • cijc_{ij} = entry of the product in row ii, column jj.
TheoremCompatibility and Size Rule

The product ABAB is defined if and only if the number of columns of AA equals the number of rows of BB. In that case:

5
(m×n)⋅(n×p)  ⟶  (m×p).\quad (m\times n)\cdot(n\times p) \;\longrightarrow\; (m\times p).

Derivation hint: The inner dimensions (nn and nn) must cancel; the outer dimensions (mm and pp) survive as the result's size.

Figure
Computing one entry of a matrix product as a row–column dot product
Row 2 of A [ 3 1 2 ] Col 1 of B 4 0 5 c = (3)(4) + (1)(0) + (2)(5) = 12 + 0 + 10 = 22 Pair up, multiply, then sum — one dot product gives one entry.

Why It Holds / Derivation

ProofWhy Matrix Multiplication Composes Transformations

Matrix multiplication is defined the way it is so that applying transformation BB, then transformation AA, equals applying the single matrix ABAB.

Step 1. Treat a matrix BB (n×pn\times p) as a function that sends a vector x\mathbf{x} (length pp) to a new vector y=Bx\mathbf{y}=B\mathbf{x} (length nn), where each component is a dot product:

6
yk=∑j=1pbkj xj.\quad y_k=\sum_{j=1}^{p} b_{kj}\,x_j.

Derivation hint: This is just equation [4] specialized to the case where the second factor is a single column (p→1p\to 1).

Step 2. Now apply matrix AA (m×nm\times n) to y\mathbf{y}, producing z=Ay\mathbf{z}=A\mathbf{y}:

7
zi=∑k=1naik yk.\quad z_i=\sum_{k=1}^{n} a_{ik}\,y_k.

Derivation hint: Same dot-product rule, now applied to the intermediate vector y\mathbf{y}.

Step 3. Substitute equation [6] into equation [7]:

8
zi=∑k=1naik(∑j=1pbkj xj)=∑j=1p(∑k=1naik bkj)xj.\quad z_i=\sum_{k=1}^{n} a_{ik}\left(\sum_{j=1}^{p} b_{kj}\,x_j\right)=\sum_{j=1}^{p}\left(\sum_{k=1}^{n} a_{ik}\,b_{kj}\right)x_j.

Derivation hint: Swap the order of summation (a finite sum lets you do this freely), then group the inner sum.

Step 4. The bracketed quantity is exactly cij=∑kaikbkjc_{ij}=\sum_k a_{ik}b_{kj} from equation [4]. Therefore z=(AB)x\mathbf{z}=(AB)\mathbf{x}, proving that the matrix product encodes the composition of the two transformations. ■\blacksquare

∎
mathematician · Arthur Cayley | 1821–1895

A British mathematician and trained lawyer, Cayley published A Memoir on the Theory of Matrices (1858), giving the first abstract treatment of matrices as objects in their own right. He defined matrix addition, multiplication, and the identity, and noted that matrix multiplication is non-commutative — a radical departure from ordinary arithmetic. Cayley also stated (and verified in small cases) what is now the Cayley–Hamilton theorem. Remarkably prolific, he produced nearly 1,000 papers, many while practicing law for 14 years before becoming Sadleirian Professor at Cambridge.

Building Intuition

🧠 Intuition

Think of the dot product as a similarity score: when two vectors point in the same direction, cos⁡θ=1\cos\theta=1 and the dot product is large and positive; when perpendicular, cos⁡θ=0\cos\theta=0 and the dot product is exactly zero; when opposite, it is negative. This is why orthogonality (perpendicularity) and "zero dot product" mean the same thing. For matrix multiplication, picture AA as a stack of row-detectors and BB as a set of column-inputs. Entry cijc_{ij} measures how strongly row ii responds to column jj. Another lens: each column of ABAB is a combination of the columns of AA, weighted by a column of BB. The matrix BB tells you how to mix the columns of AA.

TD
The Dot Product in Physics

Physicists meet the dot product as work: W=F⋅dW=\mathbf{F}\cdot\mathbf{d}, the force times the distance in the direction of motion. Only the component of force aligned with displacement does work, which is exactly what ∥F∥∥d∥cos⁡θ\|\mathbf{F}\|\|\mathbf{d}\|\cos\theta captures. Push perpendicular to motion and you do zero work — the dot product is zero. This single idea reappears as power (P=F⋅vP=\mathbf{F}\cdot\mathbf{v}), magnetic flux, and the projection of one quantity onto another throughout mechanics and electromagnetism.

Worked Examples

ExampleDot Product with a Geometric Check

Given: a=(3,4)\mathbf{a}=(3,4) and b=(4,−3)\mathbf{b}=(4,-3).

Step 1 — Algebraic formula (eq. [2]):

a⋅b=(3)(4)+(4)(−3)=12−12=0.\mathbf{a}\cdot\mathbf{b}=(3)(4)+(4)(-3)=12-12=0.

Step 2 — Interpret. A zero dot product means the vectors are perpendicular.

Step 3 — Verify with the geometric formula (eq. [3]). Both lengths are 32+42=5\sqrt{3^2+4^2}=5, so

0=a⋅b=5⋅5⋅cos⁡θ  ⇒  cos⁡θ=0  ⇒  θ=90∘.0=\mathbf{a}\cdot\mathbf{b}=5\cdot 5\cdot\cos\theta \;\Rightarrow\; \cos\theta=0\;\Rightarrow\;\theta=90^\circ.
a⋅b=0,θ=90∘ (perpendicular)\boxed{\mathbf{a}\cdot\mathbf{b}=0,\quad \theta=90^\circ \text{ (perpendicular)}}
ExampleA 2×2 Matrix Product

Given:

A=(1234),B=(5678).A=\begin{pmatrix} 1 & 2\\ 3 & 4\end{pmatrix},\qquad B=\begin{pmatrix} 5 & 6\\ 7 & 8\end{pmatrix}.

Step 1 — Check sizes. AA is 2×22\times 2, BB is 2×22\times 2; inner dimensions match, so ABAB is 2×22\times 2.

Step 2 — Compute each entry as a dot product (eq. [4]):

  • c11=(1)(5)+(2)(7)=5+14=19c_{11}=(1)(5)+(2)(7)=5+14=19
  • c12=(1)(6)+(2)(8)=6+16=22c_{12}=(1)(6)+(2)(8)=6+16=22
  • c21=(3)(5)+(4)(7)=15+28=43c_{21}=(3)(5)+(4)(7)=15+28=43
  • c22=(3)(6)+(4)(8)=18+32=50c_{22}=(3)(6)+(4)(8)=18+32=50
AB=(19224350)\boxed{AB=\begin{pmatrix} 19 & 22\\ 43 & 50\end{pmatrix}}

Step 3 — Confirm non-commutativity. Computing BABA instead gives (23343146)≠AB\begin{pmatrix}23 & 34\\ 31 & 46\end{pmatrix}\ne AB. The order genuinely matters.

Common Misconceptions

⚠️ Common mistake

Matrix multiplication is NOT element-wise. Beginners often try to multiply matching entries: (AB)ij≠aijbij(AB)_{ij}\ne a_{ij}b_{ij}. That element-wise operation (the Hadamard product) is a different, less common thing. The real product uses rows times columns and a sum, per equation [4].

Order matters. In general AB≠BAAB\ne BA. Sometimes only one of the two products even exists, because dimensions must line up. Never silently swap factors.

The identity is not "all ones." The multiplicative identity is the matrix II with 1's on the diagonal and 0's elsewhere, satisfying AI=IA=AAI=IA=A. A matrix of all ones does something entirely different.

Counterexample

Claim (false): "If AB=0AB=0 (the zero matrix), then A=0A=0 or B=0B=0." With ordinary numbers this is true, but matrices break it. Take

A=(1000),B=(0001).A=\begin{pmatrix} 1 & 0\\ 0 & 0\end{pmatrix},\qquad B=\begin{pmatrix} 0 & 0\\ 0 & 1\end{pmatrix}.

Then

AB=(0000),AB=\begin{pmatrix} 0 & 0\\ 0 & 0\end{pmatrix},

yet neither AA nor BB is the zero matrix. Matrices can have zero divisors, so you cannot "cancel" factors the way you do with real numbers.

Connections

connection

The dot product is the seed of Vector Spaces: lengths, angles, and orthogonality are all defined through it, generalizing to the abstract inner product. Matrix multiplication realizes Linear Transformations concretely — every linear map between finite spaces is "a matrix," and composing maps is multiplying matrices. Solving Systems of Linear Equations is written compactly as Ax=bA\mathbf{x}=\mathbf{b}, and the search for x\mathbf{x} leads to the Matrix Inverse and the Determinant. The geometric side connects to Trigonometry through the cos⁡θ\cos\theta formula in equation [3].

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- 1748 — Gabriel Cramer publishes Cramer's Rule using determinant-like arrays to solve linear systems.
- 1812 — Jacques Binet and Augustin-Louis Cauchy independently study products of rectangular arrays (the Binet–Cauchy identity).
- 1844 — Hermann Grassmann develops a general theory of "extensive quantities," anticipating vectors and bilinear products.
- 1850 — James Joseph Sylvester coins the word "matrix" (Latin for womb) for a rectangular array from which determinants are born.
- 1858 — Arthur Cayley's Memoir on the Theory of Matrices gives the first systematic algebra of matrices, defining multiplication and noting non-commutativity.
- 1881 — J. Willard Gibbs and Oliver Heaviside formalize vector notation, popularizing the dot product in physics and engineering.
- 1888 — Giuseppe Peano gives an axiomatic definition of a vector space, setting the abstract stage for these operations.
- 1969 — Volker Strassen shocks the field by showing matrix multiplication can be done faster than the obvious n3n^3 operations, opening the study of its true complexity.

Subtleties & Limits

open-problem

How fast can two matrices be multiplied? The schoolbook method for n×nn\times n matrices costs about n3n^3 multiplications. Strassen (1969) lowered the exponent to ≈2.807\approx 2.807, and successive breakthroughs have pushed it down — the current record exponent ω\omega sits around 2.3712.371 (as of the early 2020s). The deep open question is whether ω=2\omega=2, meaning matrices could be multiplied in essentially the time it takes just to read them. No one knows; the best lower bound is only slightly above 22, leaving a wide, famous gap that drives ongoing research in theoretical computer science.

See Also

Vectors and Scalars · Linear Transformations · Determinant · Matrix Inverse · Systems of Linear Equations · Eigenvalues and Eigenvectors · Cross Product