Linear Algebra

§2 Matrices and Matrix Operations

1. The Big Idea

A matrix is a rectangular array of numbers.

That sounds simple, but matrices are powerful because they let us organize many numbers at once. In linear algebra, matrices can represent systems of equations, transformations, data tables, or rules for combining vectors.

Example:

A=[123456]A= \begin{bmatrix} 1&2&3\\ 4&5&6 \end{bmatrix}

This matrix has 2 rows and 3 columns, so its size is

2×32\times 3

Always read matrix size as

rows×columns\text{rows}\times\text{columns}

Rows go across. Columns go down.


2. Matrix Anatomy

Before doing operations with matrices, it helps to know the vocabulary.

WordMeaning
rowa horizontal line of entries
columna vertical line of entries
entryone number inside the matrix
sizenumber of rows by number of columns
square matrixsame number of rows and columns
main diagonalentries from top-left to bottom-right
tracesum of the main diagonal entries

Entries

The entry in row ii, column jj is written as

aija_{ij}

For example, in

A=[123456]A= \begin{bmatrix} 1&2&3\\ 4&5&6 \end{bmatrix}

we have

a21=4a_{21}=4

because row 2, column 1 contains 4.

The order of the subscripts matters: a21a_{21} means row 2, column 1, not row 1, column 2.

Square Matrices

A square matrix has the same number of rows and columns.

Example of a 2×22\times 2 square matrix:

[1234]\begin{bmatrix} 1&2\\ 3&4 \end{bmatrix}

Example of a 3×33\times 3 square matrix:

[123456789]\begin{bmatrix} 1&2&3\\ 4&5&6\\ 7&8&9 \end{bmatrix}

Square matrices are special because ideas like determinants, inverses, and trace only make sense for square matrices.

Main Diagonal and Trace

In a square matrix, the main diagonal goes from top left to bottom right.

For

A=[123456789]A= \begin{bmatrix} 1&2&3\\ 4&5&6\\ 7&8&9 \end{bmatrix}

the main diagonal entries are

1, 5, 91,\ 5,\ 9

The trace is the sum of those entries:

tr(A)=1+5+9=15\operatorname{tr}(A)=1+5+9=15

For an n×nn\times n matrix,

tr(A)=a11+a22++ann\operatorname{tr}(A)=a_{11}+a_{22}+\cdots+a_{nn}

Trace is only defined for square matrices because non-square matrices do not have a complete main diagonal from corner to corner.


3. Entrywise Operations

Some matrix operations happen entry by entry. Nothing fancy happens with rows and columns yet: matching positions are combined with matching positions.

Addition and Subtraction

Matrices can be added or subtracted only if they have the same size.

If

A=[1234],B=[5678]A= \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix}, \qquad B= \begin{bmatrix} 5&6\\ 7&8 \end{bmatrix}

then

A+B=[1+52+63+74+8]=[681012]A+B= \begin{bmatrix} 1+5&2+6\\ 3+7&4+8 \end{bmatrix} = \begin{bmatrix} 6&8\\ 10&12 \end{bmatrix}

You can subtract the same way:

AB=[15263748]=[4444]A-B= \begin{bmatrix} 1-5&2-6\\ 3-7&4-8 \end{bmatrix} = \begin{bmatrix} -4&-4\\ -4&-4 \end{bmatrix}

If the sizes do not match, addition and subtraction are not defined.

Scalar Multiplication

A scalar is just a number.

To multiply a matrix by a scalar, multiply every entry by that scalar:

3[1234]=[36912]3 \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix} = \begin{bmatrix} 3&6\\ 9&12 \end{bmatrix}

Scalar multiplication stretches every entry by the same factor.


4. Matrix Multiplication

Matrix multiplication is the first operation that is not entry-by-entry.

Instead, it combines rows of the first matrix with columns of the second matrix.

Size Rule

If AA is m×nm\times n and BB is n×pn\times p, then ABAB is defined and has size m×pm\times p.

The inside dimensions must match:

(m×n)(n×p)(m\times n)(n\times p)

The outside dimensions give the size of the answer:

m×pm\times p

So the quick rule is:

(m×n)(n×p)=m×p(m\times n)(n\times p)=m\times p

Example:

ProductDefined?Result size
(2×3)(3×4)(2\times 3)(3\times 4)yes2×42\times 4
(3×2)(3×4)(3\times 2)(3\times 4)noinside dimensions do not match
(5×1)(1×6)(5\times 1)(1\times 6)yes5×65\times 6

How to Multiply

To get entry cijc_{ij} of ABAB:

  1. Take row ii of AA.
  2. Take column jj of BB.
  3. Multiply matching entries.
  4. Add the results.

This is a dot product between a row and a column.

Example:

A=[1234],B=[5678]A= \begin{bmatrix} 1&2\\ 3&4 \end{bmatrix}, \qquad B= \begin{bmatrix} 5&6\\ 7&8 \end{bmatrix}

Then

AB=[1(5)+2(7)1(6)+2(8)3(5)+4(7)3(6)+4(8)]AB= \begin{bmatrix} 1(5)+2(7)&1(6)+2(8)\\ 3(5)+4(7)&3(6)+4(8) \end{bmatrix}

So

AB=[19224350]AB= \begin{bmatrix} 19&22\\ 43&50 \end{bmatrix}

Order Matters

Usually,

ABBAAB\neq BA

Matrix multiplication is not commutative.

This is not just a technical detail. Matrix multiplication often represents doing one action after another. If you change the order, you change the process.

For ordinary numbers, 23=322\cdot 3=3\cdot 2. For matrices, that kind of swapping usually fails.


5. The Identity Matrix

The identity matrix is the matrix version of the number 11.

For 2×22\times 2:

I2=[1001]I_2= \begin{bmatrix} 1&0\\ 0&1 \end{bmatrix}

For 3×33\times 3:

I3=[100010001]I_3= \begin{bmatrix} 1&0&0\\ 0&1&0\\ 0&0&1 \end{bmatrix}

The identity matrix satisfies

AI=AAI=A

and

IA=AIA=A

when the multiplication is defined.

The phrase "when the multiplication is defined" matters. The identity matrix has to have the correct size. For example, if AA is 2×32\times 3, then AI3=AAI_3=A and I2A=AI_2A=A.


6. Transpose

The transpose of AA, written ATA^T, is found by switching rows and columns.

If

A=[123456]A= \begin{bmatrix} 1&2&3\\ 4&5&6 \end{bmatrix}

then

AT=[142536]A^T= \begin{bmatrix} 1&4\\ 2&5\\ 3&6 \end{bmatrix}

The first row of AA becomes the first column of ATA^T.

Transpose Rules

(A+B)T=AT+BT(A+B)^T=A^T+B^T (AB)T=ATBT(A-B)^T=A^T-B^T (AT)T=A(A^T)^T=A (cA)T=cAT(cA)^T=cA^T

The important product rule is

(AB)T=BTAT(AB)^T=B^TA^T

Notice that the order reverses. Transpose flips how rows and columns interact, so a product has to be reversed when transposed.


7. Inverse Matrices

An inverse is something that undoes another thing.

For ordinary numbers, multiplying by a1a^{-1} undoes multiplying by aa. For matrices, multiplying by A1A^{-1} undoes multiplying by AA.

A square matrix AA is invertible if there exists a matrix BB such that

AB=BA=IAB=BA=I

Then BB is called the inverse of AA, written

A1A^{-1}

So an invertible matrix satisfies

AA1=A1A=IAA^{-1}=A^{-1}A=I

Only square matrices can be invertible, but not every square matrix is invertible.

Why Inverses Matter

For ordinary equations, to solve

ax=bax=b

we divide by aa:

x=a1bx=a^{-1}b

For matrices, division is replaced by multiplying by an inverse.

If

AX=BAX=B

then multiply on the left by A1A^{-1}:

X=A1BX=A^{-1}B

But if

XA=BXA=B

then multiply on the right by A1A^{-1}:

X=BA1X=BA^{-1}

The side matters because matrix multiplication is not commutative.


8. Inverse of a 2×22\times 2 Matrix

For a 2×22\times 2 matrix,

A=[abcd]A= \begin{bmatrix} a&b\\ c&d \end{bmatrix}

the inverse is

A1=1adbc[dbca]A^{-1} = \frac{1}{ad-bc} \begin{bmatrix} d&-b\\ -c&a \end{bmatrix}

provided

adbc0ad-bc\neq 0

The number

adbcad-bc

is the determinant of AA.

If

adbc=0ad-bc=0

then AA is not invertible.

You will study determinants more deeply in the next section. For now, remember this practical test: for a 2×22\times 2 matrix, the inverse formula only works if adbcad-bc is not zero.


9. Algebraic Properties of Inverses

If AA and BB are invertible matrices of compatible sizes, then:

RuleMeaning
(A1)1=A(A^{-1})^{-1}=Aundoing the inverse gets back to AA
(AB)1=B1A1(AB)^{-1}=B^{-1}A^{-1}undo a product in reverse order
(cA)1=1cA1(cA)^{-1}=\frac{1}{c}A^{-1}scalar factors invert too, if c0c\neq 0
(AT)1=(A1)T(A^T)^{-1}=(A^{-1})^Ttranspose and inverse work nicely together

The product rule is the one to remember carefully:

(AB)1=B1A1(AB)^{-1}=B^{-1}A^{-1}

The order reverses for the same reason you undo steps backward. If you put on socks and then shoes, you remove shoes first and socks second.


10. Elementary Matrices

An elementary matrix is created by performing one elementary row operation on an identity matrix.

Start with

I3=[100010001]I_3= \begin{bmatrix} 1&0&0\\ 0&1&0\\ 0&0&1 \end{bmatrix}

If you swap two rows, multiply a row by a nonzero constant, or add a multiple of one row to another, the result is an elementary matrix.

Elementary matrices matter because row operations can be represented as matrix multiplication.

Row operationWhat the elementary matrix does
swap rowsswaps rows of another matrix
scale a rowscales a row of another matrix
add a multiple of one row to anotherperforms elimination

Row Operations as Multiplication

Suppose a row operation is represented by an elementary matrix EE. Then applying that row operation to AA is the same as multiplying:

EAEA

So if a sequence of elementary matrices reduces AA to the identity matrix, we can write something like

EkE2E1A=IE_k\cdots E_2E_1A=I

That means

A1=EkE2E1A^{-1}=E_k\cdots E_2E_1

The original matrix AA is built by undoing those row operations in the opposite direction:

A=E11E21Ek1A=E_1^{-1}E_2^{-1}\cdots E_k^{-1}

For example, if three elementary matrices reduce AA to II,

E3E2E1A=IE_3E_2E_1A=I

then

A1=E3E2E1A^{-1}=E_3E_2E_1

and

A=E11E21E31A=E_1^{-1}E_2^{-1}E_3^{-1}

This is the theoretical reason row-reduction can find inverses.

Small Example

Let

A=[1237]A= \begin{bmatrix} 1&2\\ 3&7 \end{bmatrix}

Eliminate the 33 below the first pivot:

R2R23R1R_2\to R_2-3R_1

This row operation is represented by

E1=[1031]E_1= \begin{bmatrix} 1&0\\ -3&1 \end{bmatrix}

Then eliminate the 22 above the second pivot:

R1R12R2R_1\to R_1-2R_2

This is represented by

E2=[1201]E_2= \begin{bmatrix} 1&-2\\ 0&1 \end{bmatrix}

Since applying E1E_1 and then E2E_2 reduces AA to II, we have

E2E1A=IE_2E_1A=I

Therefore

A1=E2E1A^{-1}=E_2E_1

and the original matrix can be recovered by undoing those elementary matrices in reverse:

A=E11E21A=E_1^{-1}E_2^{-1}

The main takeaway is not that you should always write inverses this way. The takeaway is that row operations and matrix multiplication are deeply connected.


11. Row Equivalence

Two matrices AA and BB are row equivalent if one can be changed into the other using elementary row operations.

This means they have the same row-reduction structure.

For augmented matrices, row equivalence is especially important because row operations preserve the solution set of a system. So row-equivalent augmented matrices represent systems with the same solutions.


12. Finding an Inverse by Row Reduction

To find A1A^{-1}, place AA beside the identity matrix:

[AI][A\mid I]

Then row-reduce until the left side becomes II.

If the row-reduction succeeds,

[AI][IA1][A\mid I]\to[I\mid A^{-1}]

The right side is the inverse.

For a 2×22\times 2 matrix, the setup looks like

[ab10cd01]\left[ \begin{array}{cc|cc} a&b&1&0\\ c&d&0&1 \end{array} \right]

Row-reduce the left side to the identity matrix. Whatever appears on the right side is A1A^{-1}.

When the Method Fails

If the left side cannot become II, then AA is not invertible.

So this method is both a way to find inverses and a way to test whether an inverse exists.


13. Equivalent Conditions for Invertibility

For a square matrix AA, the following statements all mean the same thing:

A is invertibleA \text{ is invertible} A row-reduces to IA \text{ row-reduces to } I Ax=0 has only the trivial solutionA\vec{x}=\vec{0} \text{ has only the trivial solution} A can be written as a product of elementary matricesA \text{ can be written as a product of elementary matrices} det(A)0\det(A)\neq 0

These are different languages for the same idea: AA does not collapse information, so it can be undone.


14. Problem-Solving Routine

When working with matrices, check the structure before doing calculations.

  1. Check sizes first. Many mistakes happen before any arithmetic begins.
  2. For addition or subtraction, sizes must match. Add or subtract corresponding entries.
  3. For scalar multiplication, multiply every entry. No size restriction beyond having a matrix.
  4. For matrix multiplication, check inside dimensions. If they match, the outside dimensions give the answer size.
  5. For inverses, check that the matrix is square. Non-square matrices do not have ordinary inverses.
  6. When solving with inverses, multiply on the correct side. AX=BAX=B and XA=BXA=B are different situations.
  7. To find an inverse, row-reduce [AI][A\mid I]. If the left side becomes II, the right side is A1A^{-1}.

15. Key Takeaways

  • Matrix size is always rows by columns.
  • Addition, subtraction, and scalar multiplication happen entry-by-entry.
  • Matrix multiplication uses row-dot-column products.
  • For ABAB, the inside dimensions must match.
  • Matrix multiplication usually depends on order: ABBAAB\neq BA.
  • The identity matrix acts like 11 for matrix multiplication.
  • The inverse matrix undoes multiplication by a matrix.
  • Inverse and transpose product rules reverse the order.
  • Row-reduction can find inverses using [AI][IA1][A\mid I]\to[I\mid A^{-1}].

Mini-Self-Check

  1. If AA is 2×32\times 3 and BB is 3×43\times 4, what size is ABAB?

The inside dimensions match: (2×3)(3×4)(2\times 3)(3\times 4). The answer has the outside dimensions, so ABAB is 2×42\times 4.

Click to reveal
  1. Can a 2×32\times 3 matrix have an ordinary inverse?

No. Ordinary inverses are only defined for square matrices.

Click to reveal
  1. Why is (AB)1=B1A1(AB)^{-1}=B^{-1}A^{-1} instead of A1B1A^{-1}B^{-1}?

Because undoing a sequence happens in reverse order. If ABAB means one combined product, the inverse must undo the BB part first, then the AA part.

Click to reveal
  1. What does [AI][IA1][A\mid I]\to[I\mid A^{-1}] mean?

It means that if row-reduction turns the left side AA into the identity matrix, then the right side has become the inverse of AA.

Click to reveal
Back to Linear Algebra