Evanalysis
3.2Estimated reading time: 26 min

3.2 Matrix multiplication, identity matrices, and linear systems

Learn when matrix products are defined, how the row-by-column rule and identity matrices work, and how multiplication encodes linear systems.

Course contents

Matrix multiplication is the first matrix operation that genuinely mixes rows with columns. It is also the operation that lets matrices encode composition, systems of equations, and later inverse matrices. Because of that, you should not memorize the rule as a pattern of symbols only. You should know what the dimensions are doing at each step.

Motivation

Addition and scalar multiplication act entry by entry. Matrix multiplication is different. To compute one output entry, you compare one row of the left matrix with one column of the right matrix.

That is why dimensions matter so strictly.

There is also a structural reason for this dimension rule. An n×pn \times p matrix sends a vector with pp entries to one with nn entries, and an m×nm \times n matrix can then accept that output and send it to a vector with mm entries. Thus BB followed by AA has the size m×pm \times p, exactly the size of ABAB. The matching inner dimension is the space through which the two actions connect; the outer dimensions record the input and output of the combined action.

Definition

When a matrix product is defined

If AA is an m×nm \times n matrix and BB is an n×pn \times p matrix, then the product ABAB is defined and is an m×pm \times p matrix.

If the number of columns of AA does not equal the number of rows of BB, then the product ABAB is undefined.

The inner dimensions must match. The outer dimensions tell you the size of the result.

The row-by-column rule

Definition

Matrix multiplication

Suppose A=[aij]A = [a_{ij}] is an m×nm \times n matrix and B=[bjk]B = [b_{jk}] is an n×pn \times p matrix.

Then the (i,k)(i,k) entry of ABAB is

(AB)ik=ai1b1k+ai2b2k+⋯+ainbnk.(AB)_{ik} = a_{i1}b_{1k} + a_{i2}b_{2k} + \cdots + a_{in}b_{nk}.

So each output entry is the dot-product-style combination of row ii of AA with column kk of BB.

This rule explains three important facts at once:

  • multiplication is not entrywise;
  • the inner dimensions must match;
  • the output entry uses every matched position in the row and column.

Worked example

Compute a product carefully

Let

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

Then ABAB is defined because both matrices are 2×22 \times 2. Its entries are:

(AB)11=1⋅4+2⋅5=14,(AB)_{11} = 1 \cdot 4 + 2 \cdot 5 = 14,(AB)12=1⋅0+2⋅1=2,(AB)_{12} = 1 \cdot 0 + 2 \cdot 1 = 2,(AB)21=3⋅4+(−1)⋅5=7,(AB)_{21} = 3 \cdot 4 + (-1) \cdot 5 = 7,(AB)22=3⋅0+(−1)⋅1=−1.(AB)_{22} = 3 \cdot 0 + (-1) \cdot 1 = -1.

So

AB=[1427−1].AB = \begin{bmatrix} 14 & 2 \\ 7 & -1 \end{bmatrix}.

Matrix-vector multiplication is a system statement

If xx is a column vector, then AxAx is a special case of matrix multiplication. It packages the left-hand sides of a linear system into one object.

For

A=[12−13−15],x=[x1x2x3],A = \begin{bmatrix} 1 & 2 & -1 \\ 3 & -1 & 5 \end{bmatrix}, \qquad x = \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix},

we have

Ax=[x1+2x2−x33x1−x2+5x3].Ax = \begin{bmatrix} x_1 + 2x_2 - x_3 \\ 3x_1 - x_2 + 5x_3 \end{bmatrix}.

So the system Ax=bAx = b is not merely shorthand. It is a matrix product whose entries reproduce the equations of the system.

Read Ax one equation at a time

The sequence below keeps the same symbolic 2×32 \times 3 by 3×13 \times 1 product visible as the rows of AA become the equations inside Ax=bAx = b. Use it as a bridge between the formula above and the editable multiplication visualizer later in the note.

Matrix products as equations

Follow how row-by-column multiplication turns Ax = b into a complete system, one row equation at a time.

  1. Match the sizes

    A 2 x 3 matrix can multiply a 3 x 1 vector because each row of A has exactly three entries to pair with x.

  2. Read row 1

    The first output entry is the first row of A paired with x: a11*x1 + a12*x2 + a13*x3.

  3. Set it equal to b1

    When Ax = b, that first output entry becomes the first equation of the system.

  4. Read row 2

    The second row gives the second equation: a21*x1 + a22*x2 + a23*x3 = b2.

  5. Stack the equations

    Ax = b is the vertical stack of all row equations, written as one matrix equation.

  6. Extend to AB

    If B = [u v], then AB = [Au Av]. A general product is several Ax-style products side by side.

The row-by-column rule is why one compact equation, Ax = b, can store an entire linear system. Each row of A supplies one equation; a full product AB repeats the same idea once for every column of B.

Identity matrices do nothing, on purpose

Definition

Identity matrix

For each positive integer nn, the identity matrix InI_n is the n×nn \times n square matrix with 11 on the main diagonal and 00 everywhere else.

For example,

I2=[1001],I3=[100010001].I_2 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}, \qquad I_3 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}.

The identity matrix matters because it preserves any compatible matrix:

AIn=A,ImA=AAI_n = A, \qquad I_m A = A

whenever the sizes match.

Worked example

Why multiplying by the identity changes nothing

Let

A=[2−143].A = \begin{bmatrix} 2 & -1 \\ 4 & 3 \end{bmatrix}.

Then

AI2=[2−143][1001]=[2−143].AI_2 = \begin{bmatrix} 2 & -1 \\ 4 & 3 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} 2 & -1 \\ 4 & 3 \end{bmatrix}.

The first column of AI2AI_2 reproduces the first column of AA, and the second column reproduces the second column of AA.

That is exactly why inverse matrices are defined through the identity later: if A−1A^{-1} exists, then AA−1=IAA^{-1} = I.

Compare a general product with identity multiplication

The next sequence separates the two mechanics that matter most here: a single entry of ABAB is built from one row and one column, while multiplying by an identity matrix preserves the compatible rows or columns. After comparing the cases, use the interactive visualizer below to choose individual output entries yourself.

Matrix products and identity matrices

Follow one matrix product entry form from a row-column sum, then see why multiplying by an identity matrix preserves rows and columns.

  1. Size gate

    A 2 x 3 matrix can multiply a 3 x 2 matrix because the inner sizes match. The outer sizes make AB a 2 x 2 matrix.

  2. One entry

    The top-left output entry uses row 1 of A and column 1 of B: c11 = 1*4 + 2*5 + (-1)*6 = 8.

  3. Whole product

    Repeat the row-column rule for every output cell. The product is not built by multiplying corresponding positions.

  4. Right identity

    In A I_n = A, the columns of I_n select the columns of A, so right multiplication by the identity preserves A.

  5. Left identity

    In I_m A = A, the rows of I_m select the rows of A, so left multiplication by the identity also preserves A.

  6. Order warning

    Identity matrices are special. In general AB and BA ask different row-column questions and need not be equal.

A matrix product is defined by compatible inner sizes. Each output entry is a row-column sum, and identity matrices preserve compatible matrices because their rows and columns select the original rows and columns.

Multiplication is usually not commutative

One of the first conceptual shocks in linear algebra is that

AB≠BAAB \ne BA

in general.

Sometimes both products are defined and differ. Sometimes one product is defined and the other is not. So order matters twice: it matters for meaning, and it matters for the final answer.

Counterexample mode

Matching dimensions do not guarantee commutativity

The claim “two square matrices of the same size always satisfy AB=BAAB=BA” is false even though both products exist and have the same size. Take

A=[1234],B=[0001].A=\begin{bmatrix}1&2\\3&4\end{bmatrix},\qquad B=\begin{bmatrix}0&0\\0&1\end{bmatrix}.

Both are real 2×22\times2 matrices, so the hypothesis is satisfied. Direct row-by-column multiplication gives

AB=[0204],BA=[0034].AB=\begin{bmatrix}0&2\\0&4\end{bmatrix},\qquad BA=\begin{bmatrix}0&0\\3&4\end{bmatrix}.

For example, (AB)12=1⋅0+2⋅1=2(AB)_{12}=1\cdot0+2\cdot1=2, whereas (BA)12=0⋅2+0⋅4=0(BA)_{12}=0\cdot2+0\cdot4=0. One unequal corresponding entry is enough to prove AB≠BAAB\ne BA. The failure has a structural explanation: multiplying this BB on the right keeps the second column and zeros the first, while multiplying it on the left keeps the second row and zeros the first.

A valid replacement is: a square matrix commutes with every scalar multiple of the identity of the same size. Indeed, if B=cIB=cI, then AB=A(cI)=cA=(cI)A=BAAB=A(cI)=cA=(cI)A=BA. For arbitrary square matrices, commutativity needs its own justification; matching dimensions guarantees that multiplication is defined, not that factors can be interchanged.

Use the figure below to watch one output entry being built from a selected row and a selected column.

Read and try

Follow one matrix product entry

The live widget updates each entry of AB as you change the entries of A and B.

Result

89
34

8 = 1×2 + 2×3

Read the product by columns as well as by entries

The row-by-column rule is the standard local computation rule, but it is not the only useful interpretation.

Write the columns of BB as

B=[b1 b2 ⋯ bp].B = [b_1\ b_2\ \cdots\ b_p].

Then the product can be read as

AB=[Ab1 Ab2 ⋯ Abp].AB = [Ab_1\ Ab_2\ \cdots\ Ab_p].

So each column of ABAB is obtained by applying AA to the corresponding column of BB.

Worked example

One product read column by column

Let

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

If

b1=[45],b2=[01],b_1 = \begin{bmatrix} 4 \\ 5 \end{bmatrix}, \qquad b_2 = \begin{bmatrix} 0 \\ 1 \end{bmatrix},

then

Ab1=[147],Ab2=[2−1].Ab_1 = \begin{bmatrix} 14 \\ 7 \end{bmatrix}, \qquad Ab_2 = \begin{bmatrix} 2 \\ -1 \end{bmatrix}.

Therefore

AB=[1427−1].AB = \begin{bmatrix} 14 & 2 \\ 7 & -1 \end{bmatrix}.

This is the same answer as the entrywise row-by-column computation. The point is that matrix multiplication packages several matrix-vector products together.

Matrix multiplication represents composition

The multiplication rule is not arbitrary. It is the rule that makes matrices encode linear transformations in sequence.

If a vector xx is first sent to BxBx, and then that result is sent to A(Bx)A(Bx), the combined effect is

(AB)x.(AB)x.

That is why the inner dimensions must match. The output of the first map must be a valid input for the second one.

Theorem

Associativity matches repeated composition

Whenever the products are defined,

A(BC)=(AB)C.A(BC) = (AB)C.

So we may regroup a chain of matrix products without changing the final linear transformation.

This does not mean that order may be changed. Associativity lets us change parentheses, not the order of the factors themselves.

Worked example

Grouping may change, but order may not

Suppose AA is 2×32 \times 3, BB is 3×43 \times 4, and CC is 4×24 \times 2.

Then both ABAB and BCBC are defined, so both (AB)C(AB)C and A(BC)A(BC) make sense, and associativity says they are equal. More explicitly, ABAB is 2×42 \times 4, so (AB)C(AB)C is 2×22 \times 2; meanwhile, BCBC is 3×23 \times 2, so A(BC)A(BC) is also 2×22 \times 2.

But BABA is not defined at all, because the inner dimensions 44 and 22 do not match. So matrix multiplication is associative, but not commutative.

Standard basis vectors explain why columns behave so cleanly

The standard basis vectors make the column interpretation precise. In Rn\mathbb{R}^n, the vector eke_k has a 11 in position kk and 00 everywhere else. If AA is an m×nm \times n matrix, then AekAe_k is exactly the kkth column of AA.

This is why the identity matrix behaves so naturally. The columns of InI_n are e1,e2,…,ene_1, e_2, \ldots, e_n, so right-multiplying by InI_n simply reproduces the columns of AA one by one.

This also explains why a compatible zero matrix on the right forces the product to be zero: every column of the zero matrix is the zero vector, so every column of the product is A0=0A0 = 0.

Theorem

A matrix is determined by its action on vectors

Let AA and BB be m×nm \times n matrices. If

Ax=Bxfor every x∈Rn,Ax=Bx \qquad \text{for every } x\in\mathbb{R}^n,

then A=BA=B.

Proof

Proof using the standard basis

For each k=1,…,nk=1,\ldots,n, substitute the standard basis vector eke_k into the hypothesis. This gives Aek=BekAe_k=Be_k. But AekAe_k is the kkth column of AA, and BekBe_k is the kkth column of BB. Hence the two matrices have the same kkth column for every kk. All their columns, and therefore all their entries, are equal, so A=BA=B.

The words "for every xx" are essential. Two different matrices can agree on one particular vector—for example, both send the zero vector to zero. The proof also shows something sharper: it is enough to check the nn standard basis vectors, because their images reveal the columns one at a time.

The first algebra laws worth remembering

Once multiplication is defined, the next issue is how it interacts with the other matrix operations you already know.

Whenever the sizes are compatible, matrix multiplication satisfies:

A(B+C)=AB+AC,(A+B)C=AC+BC,A(B + C) = AB + AC, \qquad (A + B)C = AC + BC,

and scalar multiplication may be moved in or out:

(cA)B=c(AB)=A(cB).(cA)B = c(AB) = A(cB).

The zero matrix is the simplest sanity check for these rules. If 00 is a compatible zero matrix, then

A0=0,0A=0.A0 = 0, \qquad 0A = 0.

The reason is that every row-by-column product uses only zero entries from the zero matrix, so every output entry is zero as well.

These identities are basic, but they matter because later arguments about inverse matrices, row operations, and block-matrix computation assume them silently. If you do not know them explicitly, longer calculations become much harder to audit.

Unknown entries and the order of factors

A product with unknown entries brings three ideas together: compatible dimensions, the row and column that determine each output entry, and the order of the factors. Use those structural facts before solving the resulting scalar equations.

Worked example

Recover unknowns from a partially known product

Let

A=[12131021],B=[ab11ba12].A = \begin{bmatrix} 1 & 2 & 1 & 3 \\ 1 & 0 & 2 & 1 \end{bmatrix}, \qquad B = \begin{bmatrix} a & b \\ 1 & 1 \\ b & a \\ 1 & 2 \end{bmatrix}.

Suppose

AB=[1c3d].AB = \begin{bmatrix} 1 & c \\ 3 & d \end{bmatrix}.

The product is defined because AA is 2×42 \times 4 and BB is 4×24 \times 2, so ABAB must be 2×22 \times 2. Computing only the entries we need gives

AB=[a+b+5a+b+8a+2b+12a+b+2].AB = \begin{bmatrix} a+b+5 & a+b+8 \\ a+2b+1 & 2a+b+2 \end{bmatrix}.

Comparing the first column with the given matrix gives

a+b+5=1,a+2b+1=3.a+b+5=1, \qquad a+2b+1=3.

Thus

a+b=−4,a+2b=2.a+b=-4, \qquad a+2b=2.

Subtracting the first equation from the second gives b=6b=6, and then a=−10a=-10. The remaining entries are

c=a+b+8=4,d=2a+b+2=−12.c=a+b+8=4, \qquad d=2a+b+2=-12.

This kind of problem is not really about multiplying every entry in sight. It is about extracting the few equations that the known product entries force.

Worked example

Expand products without pretending matrices commute

Let AA and BB be square matrices of the same size. Then

(5A−B)(2A+3B)=5A(2A+3B)−B(2A+3B).(5A-B)(2A+3B) = 5A(2A+3B)-B(2A+3B).

Now distribute on the right:

5A(2A+3B)−B(2A+3B)=10A2+15AB−2BA−3B2.5A(2A+3B)-B(2A+3B) =10A^2+15AB-2BA-3B^2.

The middle terms are 15AB15AB and −2BA-2BA. They cannot be combined into 13AB13AB unless you already know that AB=BAAB=BA.

The same warning explains a common false shortcut:

(A+B)(A−B)=A2−AB+BA−B2.(A+B)(A-B) =A^2-AB+BA-B^2.

This equals A2−B2A^2-B^2 only under the extra condition AB=BAAB=BA. Real-number algebra hides this issue because real-number multiplication is commutative. Matrix algebra does not.

Worked example

A zero product does not force a zero factor

Let

A=[1−1],B=[11].A = \begin{bmatrix} 1 & -1 \end{bmatrix}, \qquad B = \begin{bmatrix} 1 \\ 1 \end{bmatrix}.

Neither factor is the zero matrix, yet

AB=[1⋅1+(−1)⋅1]=[0].AB = \begin{bmatrix} 1 \cdot 1 + (-1) \cdot 1 \end{bmatrix} = \begin{bmatrix} 0 \end{bmatrix}.

So matrix multiplication behaves differently from real-number multiplication: AB=0AB = 0 does not imply A=0A = 0 or B=0B = 0.

Theorem

The identity matrix is unique

If EE is an n×nn \times n matrix such that

EA=AandAE=AEA = A \qquad \text{and} \qquad AE = A

for every compatible n×nn \times n matrix AA, then E=InE = I_n.

Proof

Why no second identity matrix can exist

Take A=InA = I_n. Then the defining property of EE gives EIn=InEI_n = I_n. But right-multiplying any matrix by InI_n leaves it unchanged, so EIn=EEI_n = E. Therefore E=InE = I_n.

Common mistakes

Common mistake

Matrix multiplication is not entrywise multiplication

The entry (AB)ik(AB)_{ik} is not aikbika_{ik}b_{ik}. It is built from the whole iith row of AA and the whole kkth column of BB.

Common mistake

Defined products can still appear in only one order

If AA is 2×32 \times 3 and BB is 3×43 \times 4, then ABAB is defined but BABA is not. Never assume the reverse order makes sense automatically.

Common mistake

Column language belongs to the right-hand factor

If B=[b1 b2]B=[b_1\ b_2], then AB=[Ab1 Ab2]AB=[Ab_1\ Ab_2]. The columns of the product are linear combinations of the columns of AA, using weights from the corresponding columns of BB. Do not write AB=[a1b1 a2b2]AB=[a_1b_1\ a_2b_2]; that expression does not match the definition of matrix multiplication.

Common mistake

Binomial formulas need commutation hypotheses

The formula (A+B)2=A2+2AB+B2(A+B)^2=A^2+2AB+B^2 is not automatic for matrices. The actual expansion is

(A+B)2=A2+AB+BA+B2.(A+B)^2=A^2+AB+BA+B^2.

You may combine the middle terms only when AB=BAAB=BA.

Summary

For AA of size m×nm \times n and BB of size n×pn \times p, the product ABAB has size m×pm \times p; incompatible inner dimensions make the product undefined. Each entry comes from one row of AA and one column of BB, while the column formula AB=[Ab1 ⋯ Abp]AB=[Ab_1\ \cdots\ Ab_p] reads the same operation as several matrix-vector products. In particular, Ax=bAx=b packages a linear system.

Identity matrices preserve compatible matrices. Matrix multiplication is associative and distributive, but associativity only changes parentheses: it does not justify changing the order of factors, and in general AB≠BAAB\ne BA. Finally, the identities Aek=col⁡k(A)Ae_k=\operatorname{col}_k(A) show that the action of a matrix on the standard basis determines every column. Consequently, if Ax=BxAx=Bx for every vector in Rn\mathbb{R}^n, then A=BA=B.

Quick checks

Checkpoint

If AA is 2×32 \times 3 and BB is 3×53 \times 5, what is the size of ABAB?

Use the inner dimensions to test whether the product is defined, then read the outer dimensions.

Solution · Answer

ABAB is defined and has size 2×52 \times 5.

Checkpoint

What does multiplying by InI_n do to a compatible matrix?

Answer in one sentence.

Solution · Answer

It leaves the matrix unchanged.

Checkpoint

If the columns of BB are b1b_1 and b2b_2, how should you read the columns of ABAB?

Use the column interpretation of matrix multiplication.

Solution · Answer

The columns of ABAB are Ab1Ab_1 and Ab2Ab_2.

Checkpoint

In (5A−B)(2A+3B)(5A-B)(2A+3B), what is the coefficient of BABA after expansion?

Keep ABAB and BABA as different terms.

Solution · Answer

The coefficient of BABA is −2-2, because the term comes from −B(2A)-B(2A).

Exercises

Checkpoint

Why does Ax=bAx = b represent several equations at once?

Use the word "rows" in your answer.

Solution · Answer

Each row of AA produces one equation when it is paired with the column vector xx, so the product AxAx packages all those row equations together.

Checkpoint

Why does Ax=0Ax = 0 always have at least one solution, no matter what AA is?

Think of xx as a column vector.

Solution · Guided solution

Take the zero vector x=0x = 0. Every entry of A0A0 is a linear combination of the entries of 00, so every entry is 00. Hence A0=0A0 = 0, and the homogeneous system always has the trivial solution.

Checkpoint

Explain why BABA may be undefined even when ABAB is defined.

Answer in terms of the inner dimensions, not just by giving one example.

Solution · Guided solution

For ABAB to be defined, the number of columns of AA must equal the number of rows of BB. For BABA to be defined, the number of columns of BB must equal the number of rows of AA. These are different conditions, so one order may be legal while the reverse order is not.

Checkpoint

Let AA and BB be the matrices from the worked example with unknowns. If the first column of ABAB is [1,3]T[1,3]^T, find aa and bb.

Use only the equations coming from the first column.

Solution · Guided solution

The first column of ABAB gives

a+b+5=1,a+2b+1=3.a+b+5=1, \qquad a+2b+1=3.

So

a+b=−4,a+2b=2.a+b=-4, \qquad a+2b=2.

Subtracting gives b=6b=6, and substituting into a+b=−4a+b=-4 gives a=−10a=-10.

Checkpoint

Write the first entry of AxAx when the first row of AA is (4,−1,2)(4, -1, 2) and x=(x1,x2,x3)Tx = (x_1, x_2, x_3)^T.

Use the row-by-column rule.

Solution · Guided solution

The first entry is 4x1−x2+2x34x_1 - x_2 + 2x_3.

This note depends on 2.1 Matrix basics. Continue to 3.3 Transpose, symmetric, and skew-symmetric matrices or jump ahead to 5.1 Invertible matrices.

Practice

Work out your answer, then check it. You can revise and try again.

Loading…

Key terms in this unit