Evanalysis
3.1Embedded interactionEstimated reading time: 13 min

3.1 Matrix multiplication and identity matrices

Learn when matrix products are defined, how the row-by-column rule works, and why identity matrices matter for systems and inverses.

Course contents

MATH1030: Linear algebra I

Rigorous linear algebra notes on systems, matrices, structure, and proof, with interaction used only where it clarifies the mathematics.

Chapter 1Systems of equations1 sections
Chapter 4Solution structure1 sections
Chapter 5Invertibility1 sections

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.

Why multiplication is more subtle than addition

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.

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 AB 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 AB 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) entry of AB 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 i of AA with column k 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=[1231],B=[4051].A = \begin{bmatrix} 1 & 2 \\ 3 & -1 \end{bmatrix}, \qquad B = \begin{bmatrix} 4 & 0 \\ 5 & 1 \end{bmatrix}.

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

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

So

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

Matrix-vector multiplication is a system statement

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

For

A=[121315],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+2x2x33x1x2+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.

Identity matrices do nothing, on purpose

Definition

Identity matrix

For each positive integer n, the identity matrix InI_n is the n×nn \times n square matrix with 1 on the main diagonal and 0 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=[2143].A = \begin{bmatrix} 2 & -1 \\ 4 & 3 \end{bmatrix}.

Then

AI2=[2143][1001]=[2143].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 A1A^{-1} exists, then AA1=IAA^{-1} = I.

Multiplication is usually not commutative

One of the first conceptual shocks in linear algebra is that

ABBAAB \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.

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 AB is obtained by applying AA to the corresponding column of BB.

Worked example

One product read column by column

Let

A=[1231],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=[21].Ab_1 = \begin{bmatrix} 14 \\ 7 \end{bmatrix}, \qquad Ab_2 = \begin{bmatrix} 2 \\ -1 \end{bmatrix}.

Therefore

AB=[14271].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 x is first sent to Bx, and then that result is sent to 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 AB and BC are defined, so both (AB)C and A(BC) make sense, and associativity says they are equal.

But BA is not defined at all, because the inner dimensions 4 and 2 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 RnR^n, the vector eke_k has a 1 in position k and 0 everywhere else. If AA is an m×nm \times n matrix, then AekAe_k is exactly the kth 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.

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 0 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.

Worked example

A zero product does not force a zero factor

Let

A=[11],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=[11+(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

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 ith row of AA and the whole kth 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 AB is defined but BA is not. Never assume the reverse order makes sense automatically.

Quick checks

Quick check

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

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

Solution

Answer

Quick check

What does multiplying by InI_n do to a compatible matrix?

Answer in one sentence.

Solution

Answer

Quick check

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

Use the column interpretation of matrix multiplication.

Solution

Answer

Exercise

Quick check

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

Think of x as a column vector.

Solution

Guided solution

Quick check

Explain why BA may be undefined even when AB is defined.

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

Solution

Guided solution

This note depends on 2.1 Matrix basics. Continue to 3.2 Transpose and special matrices or jump ahead to 5.1 Invertible matrices.

Section mastery checkpoint

Answer each question correctly to complete this section checkpoint. Correct progress: 0%.

Skills: matrix-multiplication, dimensions

If A is 2×3 and B is 3×4, what is the size of AB?

Attempts used: 0

Attempts remaining: Unlimited attempts

Preview does not consume an attempt.

Submit records a graded attempt.

Skills: matrix-multiplication, row-by-column

Let A = [[1,2],[3,4]] and B = [[0,5],[1,-1]]. Fill in the blank: the (1,2)-entry of AB is ____.

Attempts used: 0

Attempts remaining: Unlimited attempts

Preview does not consume an attempt.

Submit records a graded attempt.

Syntax guidance: Enter a single scalar.

Skills: identity-matrix, matrix-multiplication

Which statement best describes the role of the identity matrix?

Attempts used: 0

Attempts remaining: Unlimited attempts

Preview does not consume an attempt.

Submit records a graded attempt.

Key terms in this unit