Intuition The big picture (WHY this definition?)
A matrix is a machine that transforms vectors (a linear map). When you multiply two matrices A B AB A B , you are composing two machines : "first do B B B , then do A A A ". Function composition is why the row-times-column rule looks the way it does — it is the only rule that makes ( A B ) x = A ( B x ) (AB)\mathbf{x} = A(B\mathbf{x}) ( A B ) x = A ( B x ) true for every vector x \mathbf{x} x .
Everything below (the dot-product formula, associativity, non-commutativity) is just consequences of "matrices are composed transformations."
Definition Matrix product
If A A A is m × n m\times n m × n and B B B is n × p n\times p n × p , then C = A B C = AB C = A B is m × p m\times p m × p with
C i j = ∑ k = 1 n A i k B k j . C_{ij} = \sum_{k=1}^{n} A_{ik}\,B_{kj}. C ij = ∑ k = 1 n A ik B k j .
The inner dimensions must match (n = n n = n n = n ); the outer dimensions (m , p m,p m , p ) give the result's size.
WHY the sum-of-products? Let's derive it. A matrix B B B acts on a vector x \mathbf{x} x by
( B x ) k = ∑ j B k j x j . (B\mathbf{x})_k = \sum_{j} B_{kj} x_j. ( B x ) k = ∑ j B k j x j .
We demand that A B AB A B be the single matrix doing "A A A after B B B ", i.e. ( A B ) x = A ( B x ) (AB)\mathbf{x} = A(B\mathbf{x}) ( A B ) x = A ( B x ) for all x \mathbf{x} x . Compute the i i i -th entry:
( A ( B x ) ) i = ∑ k A i k ( B x ) k = ∑ k A i k ( ∑ j B k j x j ) = ∑ j ( ∑ k A i k B k j ⏟ = ( A B ) i j ) x j . \big(A(B\mathbf{x})\big)_i = \sum_k A_{ik}(B\mathbf{x})_k = \sum_k A_{ik}\Big(\sum_j B_{kj}x_j\Big) = \sum_j \Big(\underbrace{\sum_k A_{ik}B_{kj}}_{=(AB)_{ij}}\Big)x_j. ( A ( B x ) ) i = ∑ k A ik ( B x ) k = ∑ k A ik ( ∑ j B k j x j ) = ∑ j ( = ( A B ) ij k ∑ A ik B k j ) x j .
So the coefficient multiplying x j x_j x j — which is ( A B ) i j (AB)_{ij} ( A B ) ij — is forced to be ∑ k A i k B k j \sum_k A_{ik}B_{kj} ∑ k A ik B k j . The definition isn't arbitrary; composition forces it.
2 × 2 2\times2 2 × 2 product
A = ( 1 2 3 4 ) , B = ( 5 6 7 8 ) . A=\begin{pmatrix}1&2\\3&4\end{pmatrix},\quad B=\begin{pmatrix}5&6\\7&8\end{pmatrix}. A = ( 1 3 2 4 ) , B = ( 5 7 6 8 ) .
( A B ) 11 = 1 ⋅ 5 + 2 ⋅ 7 = 19 (AB)_{11}=1\cdot5+2\cdot7=19 ( A B ) 11 = 1 ⋅ 5 + 2 ⋅ 7 = 19 . Why? Row 1 of A A A dotted with column 1 of B B B .
( A B ) 12 = 1 ⋅ 6 + 2 ⋅ 8 = 22 (AB)_{12}=1\cdot6+2\cdot8=22 ( A B ) 12 = 1 ⋅ 6 + 2 ⋅ 8 = 22 . Why? Row 1 with column 2.
( A B ) 21 = 3 ⋅ 5 + 4 ⋅ 7 = 43 (AB)_{21}=3\cdot5+4\cdot7=43 ( A B ) 21 = 3 ⋅ 5 + 4 ⋅ 7 = 43 , ( A B ) 22 = 3 ⋅ 6 + 4 ⋅ 8 = 50 (AB)_{22}=3\cdot6+4\cdot8=50 ( A B ) 22 = 3 ⋅ 6 + 4 ⋅ 8 = 50 .
A B = ( 19 22 43 50 ) . AB=\begin{pmatrix}19&22\\43&50\end{pmatrix}. A B = ( 19 43 22 50 ) .
Worked example Non-square: shapes must align
A A A is 2 × 3 2\times3 2 × 3 , B B B is 3 × 2 3\times2 3 × 2 :
A = ( 1 0 2 − 1 3 1 ) , B = ( 4 1 0 2 1 0 ) . A=\begin{pmatrix}1&0&2\\-1&3&1\end{pmatrix},\ B=\begin{pmatrix}4&1\\0&2\\1&0\end{pmatrix}. A = ( 1 − 1 0 3 2 1 ) , B = 4 0 1 1 2 0 .
Inner dims 3 = 3 3=3 3 = 3 ✓, result is 2 × 2 2\times2 2 × 2 .
( A B ) 11 = 1 ⋅ 4 + 0 ⋅ 0 + 2 ⋅ 1 = 6 (AB)_{11}=1\cdot4+0\cdot0+2\cdot1=6 ( A B ) 11 = 1 ⋅ 4 + 0 ⋅ 0 + 2 ⋅ 1 = 6 . Why? Three-term dot product over the shared index k = 1 , 2 , 3 k=1,2,3 k = 1 , 2 , 3 .
( A B ) 12 = 1 ⋅ 1 + 0 ⋅ 2 + 2 ⋅ 0 = 1 (AB)_{12}=1\cdot1+0\cdot2+2\cdot0=1 ( A B ) 12 = 1 ⋅ 1 + 0 ⋅ 2 + 2 ⋅ 0 = 1 ; ( A B ) 21 = − 1 ⋅ 4 + 3 ⋅ 0 + 1 ⋅ 1 = − 3 (AB)_{21}=-1\cdot4+3\cdot0+1\cdot1=-3 ( A B ) 21 = − 1 ⋅ 4 + 3 ⋅ 0 + 1 ⋅ 1 = − 3 ; ( A B ) 22 = − 1 ⋅ 1 + 3 ⋅ 2 + 1 ⋅ 0 = 5 (AB)_{22}=-1\cdot1+3\cdot2+1\cdot0=5 ( A B ) 22 = − 1 ⋅ 1 + 3 ⋅ 2 + 1 ⋅ 0 = 5 .
A B = ( 6 1 − 3 5 ) . AB=\begin{pmatrix}6&1\\-3&5\end{pmatrix}. A B = ( 6 − 3 1 5 ) .
Note B A BA B A would be 3 × 3 3\times3 3 × 3 — a different shape . Already a hint at non-commutativity!
Worked example Order matters (rotation then reflection ≠ reflection then rotation)
Let R = ( 0 − 1 1 0 ) R=\begin{pmatrix}0&-1\\1&0\end{pmatrix} R = ( 0 1 − 1 0 ) (90° rotation), F = ( 1 0 0 − 1 ) F=\begin{pmatrix}1&0\\0&-1\end{pmatrix} F = ( 1 0 0 − 1 ) (flip y y y ).
R F = ( 0 1 1 0 ) , F R = ( 0 − 1 − 1 0 ) . RF=\begin{pmatrix}0&1\\1&0\end{pmatrix},\qquad FR=\begin{pmatrix}0&-1\\-1&0\end{pmatrix}. R F = ( 0 1 1 0 ) , F R = ( 0 − 1 − 1 0 ) .
Why this step? R F RF R F means "flip first, then rotate"; F R FR F R means "rotate first, then flip". Physically these land a point in different places, so R F ≠ F R RF\neq FR R F = F R .
Algebraic proof (entrywise). With sizes compatible,
( ( A B ) C ) i ℓ = ∑ j ( A B ) i j C j ℓ = ∑ j ( ∑ k A i k B k j ) C j ℓ = ∑ k ∑ j A i k B k j C j ℓ . \big((AB)C\big)_{i\ell}=\sum_j (AB)_{ij}C_{j\ell}=\sum_j\Big(\sum_k A_{ik}B_{kj}\Big)C_{j\ell}=\sum_{k}\sum_{j}A_{ik}B_{kj}C_{j\ell}. ( ( A B ) C ) i ℓ = ∑ j ( A B ) ij C j ℓ = ∑ j ( ∑ k A ik B k j ) C j ℓ = ∑ k ∑ j A ik B k j C j ℓ .
( A ( B C ) ) i ℓ = ∑ k A i k ( B C ) k ℓ = ∑ k A i k ( ∑ j B k j C j ℓ ) = ∑ k ∑ j A i k B k j C j ℓ . \big(A(BC)\big)_{i\ell}=\sum_k A_{ik}(BC)_{k\ell}=\sum_k A_{ik}\Big(\sum_j B_{kj}C_{j\ell}\Big)=\sum_{k}\sum_{j}A_{ik}B_{kj}C_{j\ell}. ( A ( B C ) ) i ℓ = ∑ k A ik ( B C ) k ℓ = ∑ k A ik ( ∑ j B k j C j ℓ ) = ∑ k ∑ j A ik B k j C j ℓ .
Both equal the same double sum — finite sums can be reordered. Done. Associativity is why "A B C ABC A B C " is unambiguous.
Also note distributivity : A ( B + C ) = A B + A C A(B+C)=AB+AC A ( B + C ) = A B + A C and ( A + B ) C = A C + B C (A+B)C=AC+BC ( A + B ) C = A C + B C , and A I = I A = A A I = I A = A A I = I A = A (identity).
Intuition WHY order matters
Matrices = transformations. Composing transformations is order-sensitive ("put on socks then shoes" ≠ "shoes then socks"). Only special pairs commute (e.g. with I I I , with their own powers, simultaneously diagonalizable matrices).
Three reasons A B ≠ B A AB\neq BA A B = B A :
Shape: A B AB A B and B A BA B A can have different sizes (Example 2) — then they can't be equal.
Even when both square: the dot products mix rows/cols differently. See R F RF R F vs F R FR F R above.
Commutator measures failure: [ A , B ] : = A B − B A [A,B]:=AB-BA [ A , B ] := A B − B A . It is 0 0 0 iff they commute.
Worked example Concrete non-commuting square pair
A = ( 1 1 0 1 ) A=\begin{pmatrix}1&1\\0&1\end{pmatrix} A = ( 1 0 1 1 ) , B = ( 1 0 1 1 ) B=\begin{pmatrix}1&0\\1&1\end{pmatrix} B = ( 1 1 0 1 ) .
A B = ( 2 1 1 1 ) AB=\begin{pmatrix}2&1\\1&1\end{pmatrix} A B = ( 2 1 1 1 ) , B A = ( 1 1 1 2 ) BA=\begin{pmatrix}1&1\\1&2\end{pmatrix} B A = ( 1 1 1 2 ) . Why? Compute each entry as a row·column; they differ on the diagonal. So [ A , B ] = ( 1 0 0 − 1 ) ≠ 0 [A,B]=\begin{pmatrix}1&0\\0&-1\end{pmatrix}\neq 0 [ A , B ] = ( 1 0 0 − 1 ) = 0 .
Common mistake "Matrix multiplication is entrywise, like addition."
Why it feels right: addition is entrywise, so symmetry suggests multiplication is too. Fix: entrywise product (Hadamard) loses the composition meaning and breaks ( A B ) x = A ( B x ) (AB)\mathbf{x}=A(B\mathbf{x}) ( A B ) x = A ( B x ) . Real multiplication is row·column so it represents composing maps.
( A B ) − 1 = A − 1 B − 1 (AB)^{-1}=A^{-1}B^{-1} ( A B ) − 1 = A − 1 B − 1 ."
Why it feels right: mirrors numbers ( a b ) − 1 = a − 1 b − 1 (ab)^{-1}=a^{-1}b^{-1} ( ab ) − 1 = a − 1 b − 1 . Fix: order reverses! ( A B ) − 1 = B − 1 A − 1 (AB)^{-1}=B^{-1}A^{-1} ( A B ) − 1 = B − 1 A − 1 — to undo "B then A" you undo A first: ( A B ) ( B − 1 A − 1 ) = A ( B B − 1 ) A − 1 = I (AB)(B^{-1}A^{-1})=A(BB^{-1})A^{-1}=I ( A B ) ( B − 1 A − 1 ) = A ( B B − 1 ) A − 1 = I .
A B = 0 ⇒ A = 0 AB=0 \Rightarrow A=0 A B = 0 ⇒ A = 0 or B = 0 B=0 B = 0 ."
Why it feels right: true for real numbers (no zero divisors). Fix: matrices have zero divisors, e.g. ( 0 1 0 0 ) 2 = 0 \begin{pmatrix}0&1\\0&0\end{pmatrix}^2=0 ( 0 0 1 0 ) 2 = 0 but the matrix isn't 0 0 0 .
( A + B ) 2 = A 2 + 2 A B + B 2 (A+B)^2=A^2+2AB+B^2 ( A + B ) 2 = A 2 + 2 A B + B 2 ."
Why it feels right: binomial habit. Fix: ( A + B ) 2 = A 2 + A B + B A + B 2 (A+B)^2=A^2+AB+BA+B^2 ( A + B ) 2 = A 2 + A B + B A + B 2 ; you can only merge A B + B A AB+BA A B + B A into 2 A B 2AB 2 A B if they commute.
Recall Feynman: explain to a 12-year-old (hidden)
Think of each matrix as a little recipe machine for moving dots on a grid. A B AB A B means "run machine B B B , then machine A A A , back to back, as one combined machine." To build that combined machine you slide each row of A A A across each column of B B B , multiply matching numbers and add them up — that's the row-dot-column rule. Because doing B B B -then-A A A is usually different from A A A -then-B B B (like socks-then-shoes vs shoes-then-socks), swapping the order usually gives a different machine — that's non-commutativity. But grouping three machines ( A B ) C (AB)C ( A B ) C vs A ( B C ) A(BC) A ( B C ) gives the same pipeline, so that grouping is free — that's associativity.
Mnemonic Remember the rules
"Rows Cross Columns; Order Counts; Brackets Don't."
RCC = row·column for entries; Order Counts = A B ≠ B A AB\neq BA A B = B A ; Brackets Don't (matter) = associativity.
For C = A B C=AB C = A B what is C i j C_{ij} C ij ? ∑ k A i k B k j \sum_k A_{ik}B_{kj} ∑ k A ik B k j — row
i i i of
A A A dotted with column
j j j of
B B B .
Which dimensions must match to form A B AB A B ? The inner ones:
A A A is
m × n m\times n m × n ,
B B B is
n × p n\times p n × p ; result is
m × p m\times p m × p .
WHY is the product defined by row·column sums and not entrywise? So that
( A B ) x = A ( B x ) (AB)\mathbf{x}=A(B\mathbf{x}) ( A B ) x = A ( B x ) , i.e.
A B AB A B represents composition of the two linear maps.
State and justify associativity. ( A B ) C = A ( B C ) (AB)C=A(BC) ( A B ) C = A ( B C ) ; both apply maps in order
C , B , A C,B,A C , B , A to any vector, and entrywise both equal
∑ j , k A i k B k j C j ℓ \sum_{j,k}A_{ik}B_{kj}C_{j\ell} ∑ j , k A ik B k j C j ℓ .
Is matrix multiplication commutative? Give a counterexample. No. E.g.
( 1 1 0 1 ) ( 1 0 1 1 ) ≠ \begin{pmatrix}1&1\\0&1\end{pmatrix}\begin{pmatrix}1&0\\1&1\end{pmatrix}\neq ( 1 0 1 1 ) ( 1 1 0 1 ) = the reverse.
What is ( A B ) − 1 (AB)^{-1} ( A B ) − 1 ? B − 1 A − 1 B^{-1}A^{-1} B − 1 A − 1 (order reverses).
Expand ( A + B ) 2 (A+B)^2 ( A + B ) 2 for matrices. A 2 + A B + B A + B 2 A^2+AB+BA+B^2 A 2 + A B + B A + B 2 (not
A 2 + 2 A B + B 2 A^2+2AB+B^2 A 2 + 2 A B + B 2 unless
A , B A,B A , B commute).
Define the commutator and what it measures. [ A , B ] = A B − B A [A,B]=AB-BA [ A , B ] = A B − B A ; it is
0 0 0 iff
A A A and
B B B commute.
Can A B = 0 AB=0 A B = 0 with A , B A,B A , B both nonzero? Yes — matrices have zero divisors, e.g.
( 0 1 0 0 ) 2 = 0 \begin{pmatrix}0&1\\0&0\end{pmatrix}^2=0 ( 0 0 1 0 ) 2 = 0 .
Linear Transformations — matrix product = composition of maps.
Identity and Inverse Matrices — ( A B ) − 1 = B − 1 A − 1 (AB)^{-1}=B^{-1}A^{-1} ( A B ) − 1 = B − 1 A − 1 .
Dot Product — each entry of A B AB A B is a dot product.
Determinants — det ( A B ) = det A det B \det(AB)=\det A\det B det ( A B ) = det A det B (multiplicative despite non-commutativity).
Transpose — ( A B ) ⊤ = B ⊤ A ⊤ (AB)^\top=B^\top A^\top ( A B ) ⊤ = B ⊤ A ⊤ (order also reverses).
Matrix Powers and Diagonalization — commuting matrices share eigenvectors.
Definition Cij = sum Aik Bkj
Entry / Column / Row views
Associativity AB C = A BC
Non-commutativity AB != BA
Rotation then flip != flip then rotation
Intuition Hinglish mein samjho
Dekho, matrix ko ek machine samjho jo vectors ko transform karti hai (linear map). Jab tum A B AB A B multiply karte ho, tum do machines ko jod rahe ho — pehle B B B chalao, phir A A A . Isi "composition" ki wajah se row-into-column wala rule banta hai: ( A B ) i j (AB)_{ij} ( A B ) ij matlab A A A ki i i i -th row ka B B B ki j j j -th column ke saath dot product. Yeh definition koi randomly nahi hai — yeh isliye aati hai taaki ( A B ) x = A ( B x ) (AB)\mathbf{x}=A(B\mathbf{x}) ( A B ) x = A ( B x ) har vector ke liye sach ho. Inner dimensions match karne chahiye, aur outer dimensions result ka size dete hain.
Associativity (( A B ) C = A ( B C ) (AB)C=A(BC) ( A B ) C = A ( B C ) ) free milti hai kyunki functions ko compose karna hamesha associative hota hai — "C phir B phir A" ek hi pipeline hai, bracket kahin bhi lagao farak nahi padta. Isliye hum "A B C ABC A B C " likh sakte hain bina confusion ke.
Lekin commutativity nahi hoti — A B AB A B aur B A BA B A generally alag hote hain. Socho socks-then-shoes vs shoes-then-socks: order badal do, result badal jaata hai. Kabhi shape hi alag ho jaata hai, kabhi square hone par bhi entries alag aati hain. Iska measure hota hai commutator [ A , B ] = A B − B A [A,B]=AB-BA [ A , B ] = A B − B A , jo 0 0 0 tabhi hota hai jab dono commute karein.
Do common galtiyan yaad rakho: ( A B ) − 1 = B − 1 A − 1 (AB)^{-1}=B^{-1}A^{-1} ( A B ) − 1 = B − 1 A − 1 (order ulta hota hai, kyunki pehle A undo karna padta hai), aur ( A + B ) 2 = A 2 + A B + B A + B 2 (A+B)^2=A^2+AB+BA+B^2 ( A + B ) 2 = A 2 + A B + B A + B 2 — yahan 2 A B 2AB 2 A B tabhi likh sakte ho jab A , B A,B A , B commute karein. Mnemonic: Rows Cross Columns; Order Counts; Brackets Don't.