Matrix Multiplication

Subtopic: Matricies

Matrix multiplication is the workhorse of linear algebra—it computes the composition of linear transformations, solves systems of equations, and powers everything from graphics to neural networks. The rule is simple once you see it: row times column, summed up.

Introduction

Why is matrix multiplication defined the way it is? It's not component-wise (that would be too simple and less useful). Instead, it's designed so that if matrix A A represents one transformation and B B represents another, then A⁢B A B represents doing B B first, then A A.

This connection to function composition is why matrix multiplication is so powerful—and why it's not commutative. The order of transformations matters.

Definition

For A⁢(m⨉n) A times open paren m the n ary times of n close parenand B⁢(n⨉p) B times open paren n the n ary times of p close paren, the product C=A⁢B C equals A B is an m⨉p m the n ary times of p matrix where:

Ci⁢j=∑k=1n(Ai⁢k)⁢Bk⁢j=Ai⁢1⁢B1⁢j+Ai⁢2⁢B2⁢j+⋯+Ai⁢n⁢Bn⁢j C sub i j equals the sum from k equals 1 to n of open paren A sub i k close paren B sub k j equals A sub i 1 B sub 1 j plus A sub i 2 B sub 2 j plus dot dot dot plus A sub i n B sub n j

Entry (i,j) open paren i comma j close paren of C C is the dot product of row i of A A with column j of B B.

Critical requirement: the number of columns of A A must equal the number of rows of B B.

Geometric Interpretation

If A A represents transformation T1 T sub 1 and B B represents T2 T sub 2, then A⁢B A B AB represents the composition T1∘T2 T sub 1 composed with T sub 2: first apply T2 T sub 2, then T1 T sub 1.

For a vector x x: (A⁢B)⁢x=A⁢(B⁢x) A B times x equals A times B x. The vector is first transformed by B B, then the result is transformed by A A.

This explains why A⁢B≠B⁢A A B is not equal to B A in general: rotating then scaling is different from scaling then rotating.

Step-by-Step Example

Multiply:

A=(1234),B=(5678) A equals the 2 by 2 matrix Row 1: 1 2 Row 2: 3 4 comma B equals the 2 by 2 matrix Row 1: 5 6 Row 2: 7 8

C11= C sub 11 equals (row 1 1 of A A) ⋅ times (column 1 1 of B B)=1⁢(5)+2⁢(7)=5+14=19 equals 1 times 5 plus 2 times 7 equals 5 plus 14 equals 19

C12= C sub 12 equals (row 1 1 of A A) ⋅ times (column 2 2 of B B)=1⁢(6)+2⁢(8)=6+16=22 equals 1 times 6 plus 2 times 8 equals 6 plus 16 equals 22

C21= C sub 21 equals (row 2 2 of A A) ⋅ times (column 1 1 of B B)=3⁢(5)+4⁢(7)=15+28=43 equals 3 times 5 plus 4 times 7 equals 15 plus 28 equals 43

C22= C sub 22 equals (row 2 2 of A A) ⋅ times (column 2 2 of B B)=3⁢(6)+4⁢(8)=18+32=50 equals 3 times 6 plus 4 times 8 equals 18 plus 32 equals 50

A⁢B=(19224350) A B equals the 2 by 2 matrix Row 1: 19 22 Row 2: 43 50

Key Properties

  • NOT commutative: A⁢B≠B⁢A A B is not equal to B A in general (even when both products exist)

  • Associative: (A⁢B)⁢C=A⁢(B⁢C) A B times C equals A times B C

  • Distributive: A⁢(B+C)=A⁢B+A⁢C A times open paren B plus C close paren equals A B plus A C and (A+B)⁢C=A⁢C+B⁢C open paren A plus B close paren times C equals A C plus B C

  • Identity: A⁢I=I⁢A=A A I equals I A equals A, where I I is the identity matrix

  • Transpose: (A⁢B)T=BT⁢AT open paren A B close paren to the T power equals B to the T power A to the T power (note the reversal)

  • Inverse: (A⁢B)−1=B−1⁢A−1 open paren A B close paren to the negative 1 power equals B to the negative 1 power A to the negative 1 power (note the reversal)

Matrix-Vector Multiplication

A special case: A⁢(m⨉n) A times open paren m the n ary times of n close paren times x x (n n ⨉ n ary times 1 column vector) gives an m m ⨉ n ary times 1 1 vector.

A⁢x=x1⁢a1+x2⁢a2+⋯+xn⁢an A x equals x sub 1 a sub 1 plus x sub 2 a sub 2 plus dot dot dot plus x sub n a sub n

where ai a sub i is column i i of A A. So A⁢x A x is a linear combination of A A's columns!

This column view is often more insightful than the row-dot-column computation.

Dimension Rules

(m×n) open paren m times n close paren times (n×p)=(m×p) open paren n times p close paren equals open paren m times p close paren

The inner dimensions must match; the outer dimensions give the result size.

Memory aid: (a×b)⁢(b×c)=(a×c) open paren a times b close paren times open paren b times c close paren equals open paren a times c close paren — the b b's cancel.

Computational Cost

Multiplying an (m×n) open paren m times n close paren matrix by an (n×p) open paren n times p close paren matrix takes O⁢(m⁢n⁢p) O times open paren m n p close paren operations using the standard algorithm.

For square n×n n times n matrices, this is O⁡(n3) O of open paren n cubed close paren.

Faster algorithms exist (Strassen: O⁡(n2.81) O of open paren n raised to the 2.81 power close paren), but standard multiplication is usually used in practice due to better constants and numerical stability.

Block Multiplication

Matrices can be partitioned into blocks, and multiplication works block-wise as if blocks were entries:

(A11A12A21A22)⁢(B11B12B21B22)=(A11⁢B11+A12⁢B21⋯⋮⋱) the 2 by 2 matrix Row 1: A sub 11 A sub 12 Row 2: A sub 21 A sub 22 times the 2 by 2 matrix Row 1: B sub 11 B sub 12 Row 2: B sub 21 B sub 22 equals the 2 by 2 matrix Row 1: Column 1, A sub 11 B sub 11 plus A sub 12 B sub 21 Column 2, dot dot dot Row 2: Column 1, vertical ellipsis Column 2, down right diagonal ellipsis

This is useful for large matrices and parallel computation.

Applications

In graphics, transformations (rotation, scaling, translation) are matrices. Combining transformations = multiplying matrices.

In neural networks, each layer performs y=W⁢x+b y equals W x plus b, where W W is a weight matrix. Deep networks are chains of matrix multiplications.

In solving linear systems A⁢x=b A x equals b, understanding matrix-vector multiplication reveals the column space and solution structure.

In Markov chains, powers of the transition matrix An A to the n-th power give the n n-step transition probabilities.

Summary

Matrix multiplication combines row–column dot products to produce a new matrix. It represents composition of linear transformations, explaining its non-commutativity. Key properties: associative, distributive, and transpose and inverse reverse order. The column view (A⁢x A x as a linear combination of columns) provides geometric insight. Matrix multiplication is O⁡(n3) O of open paren n cubed close paren for square matrices and underlies applications from graphics to machine learning.