Linear Algebra
3.210 min read

Matrix-Vector Multiplication

To multiply matrix AA (size m×nm \times n) by vector x\mathbf{x} (in Rn\mathbb{R}^n), the result AxA\mathbf{x} is a vector in Rm\mathbb{R}^m. The dimensions must be compatible: the number of columns of AA must equal the length of x\mathbf{x}.

The column perspective: Ax=x1a1+x2a2++xnanA\mathbf{x} = x_1\mathbf{a}_1 + x_2\mathbf{a}_2 + \cdots + x_n\mathbf{a}_n — a linear combination of the columns of AA weighted by the entries of x\mathbf{x}. This is the geometric view.

The two-finger rule (entry-by-entry): The ii-th entry of AxA\mathbf{x} is the dot product of row ii of AA with x\mathbf{x}: (Ax)i=jaijxj(A\mathbf{x})_i = \sum_j a_{ij} x_j. This is the computational view.

Formal View

Definition 3.2 — Matrix-Vector Multiplication
For ARm×nA \in \mathbb{R}^{m \times n} and xRn\mathbf{x} \in \mathbb{R}^n,
Ax=(ja1jxjjamjxj)=x1a1++xnanA\mathbf{x} = \begin{pmatrix} \sum_j a_{1j}x_j \\ \vdots \\ \sum_j a_{mj}x_j \end{pmatrix} = x_1\mathbf{a}_1 + \cdots + x_n\mathbf{a}_n
where aj\mathbf{a}_j is the jj-th column of AA.

Interactive Visualization

Matrix-Vector Multiplication

Why This Matters

Matrix-vector multiplication is the core computational primitive of linear algebra and deep learning.

  • Neural network forward pass: each layer computes y=Ax+b\mathbf{y} = A\mathbf{x} + \mathbf{b}
  • Image filtering: applying a kernel is matrix-vector multiplication (vectorized)
  • PageRank: Google's original algorithm computes repeated matrix-vector products

Quiz

Question 1

The product AxA\mathbf{x} for AR3×2A \in \mathbb{R}^{3 \times 2} and xR2\mathbf{x} \in \mathbb{R}^2 lives in:

Common Mistakes

  • Forgetting that AxA\mathbf{x} requires nn (columns of AA) to equal the length of x\mathbf{x}.
  • Computing AxA\mathbf{x} by rows when the column perspective is more geometric and informative.