Matrix Operations
00 · Symbol Glossary
An uppercase letter denoting a matrix. Matrices extend vectors: a vector is a single column of numbers; a matrix is a rectangular grid. Bold uppercase is sometimes written , but plain uppercase is equally standard — context makes it clear.
The entry of matrix in row , column . Read aloud as "a-i-j." The first subscript is always the row, the second is always the column — row then column, always. is in row 2, column 3.
The dimensions of a matrix: rows and columns. An matrix has entries total. Read aloud as "m by n." When dimensions appear in a product, the inner dimensions must match.
The set of all matrices with real entries. Extends from Chapter 1: a vector in is an element of . Addition and scalar multiplication on satisfy the same 8 vector space axioms.
The matrix formed by flipping across its main diagonal: rows become columns, columns become rows. . Chapter 1 defined transpose for vectors; this is the same operation extended to full matrices.
The product of matrices and , computed via row-by-column dot products. Not component-wise multiplication. The entry equals the dot product of row of with column of . Order matters — in general.
The identity matrix: ones on the main diagonal, zeros everywhere else. and for any matrix — multiplication by leaves the matrix unchanged, just as multiplication by 1 leaves a scalar unchanged.
The sum of the diagonal entries of a square matrix: . Only defined for square matrices. In Chapter 6 it will reappear as the sum of the eigenvalues — a fundamental connection between entries and structure.
01 · What is a Matrix
A vector organises a list of numbers into one column. A matrix organises numbers into a rectangular grid — rows and columns. Every quant operation on multi-dimensional data eventually becomes a matrix operation: a portfolio of assets observed over days is an matrix, each row a snapshot and each column an asset's history.
An matrix over is a rectangular array of real numbers with rows and columns:
— the entry in row , column . First index is row, second is column.
— diagonal dots meaning the pattern continues in both directions.
— read "m by n." The number of rows comes first, always.
A fund tracks 3 assets over 4 trading days. Returns (in percent) are stored as a matrix — 4 days (rows), 3 assets (columns):
— day 1, asset 3 returned . — day 4, asset 2 returned . The row index names the day, the column index names the asset.
Reading as row 2, column 3 is wrong. The subscript order is row-then-column without exception. For the matrix : (row 3, column 2), not (row 2, column 3). Swapping the indices retrieves a completely different entry.
02 · Matrix Addition and Scalar Multiplication
Matrix addition and scalar multiplication work entry-by-entry — the same pattern as vector operations from Chapter 1, now applied to every slot in the grid.
For , their sum is defined entry-by-entry:
Both matrices must have identical dimensions. Adding an matrix to a matrix is undefined unless and .
For and scalar :
Every entry is multiplied by . This preserves dimensions: .
Confirm dimensions match: and . Both . ✓ Addition is defined.
Scale by 2: multiply every entry of by 2. . Each of the four entries of is doubled individually.
Add entry : . Adding a negative is subtraction.
Add entry : .
Add entry : .
Add entry : .
Assemble the result:
and . Adding them fails at slot : has no entry in column 3. The dimensions differ ( vs ). This is undefined — full stop. The number of columns (2 vs 3) must match, not just the number of rows.
03 · Matrix Multiplication
Matrix multiplication is the most important — and the most misunderstood — operation in linear algebra. It is not entry-by-entry. It is row-by-column dot products.
For and , the product has entries:
— the dot product of row of with column of .
— the shared index, stepping through .
The inner dimensions must match: must have columns and must have rows. The result has the outer dimensions: rows (from ) and columns (from ).
Write the dimensions side by side: . The inner two numbers must match — both must equal . The result takes the outer two: . Example: ✓. Example: — inner pair is — mismatch. ✗ Undefined.
Check dimensions: , . Inner dimensions both . ✓ Result will be .
Compute entry : dot product of row 1 of with column 1 of .
Row 1 of : . Column 1 of : .
. The comes from , the from , the from .
Compute entry : dot product of row 1 of with column 2 of .
Column 2 of : .
. The from , the from , the from .
Compute entry : dot product of row 2 of with column 1 of .
Row 2 of : . Column 1 of : .
. The from , the from , the from .
Compute entry : dot product of row 2 of with column 2 of .
. The from , the from , the from .
Assemble the result:
For and :
.
.
. Swapping the order gives a different matrix. This is not a quirk of this specific pair — matrix multiplication is non-commutative in general. Never assume .
A matrix holds daily returns for 3 assets (columns) over 2 days (rows). A weight vector holds the portfolio allocation for each asset. The product gives the portfolio return on each day:
Day 1 portfolio return: . Day 2: . Each row of is dotted with — exactly the row-by-column pattern of matrix-vector multiplication.
04 · The Transpose
The transpose of a matrix is formed by reflecting it across the main diagonal: row of becomes column of , and column of becomes row of .
For , the transpose is defined by:
The row and column indices swap. An matrix transposes to an matrix — dimensions flip too.
Identify dimensions: . The transpose will be — dimensions flip.
Write row 1 of as column 1 of : row 1 is , so column 1 of is .
Write row 2 of as column 2 of : row 2 is , so column 2 of is .
Assemble:
Two transpose properties are critical — one is obvious, one trips people up:
— transposing twice returns the original matrix.
— the order reverses when transposing a product. The reversed order is not optional; it is forced by the dimension math.
. For and : , so .
and . The product would need the inner dimensions to match: times — inner pair is . Mismatch. is not even defined here.
: times — inner pair is ✓ — gives . Correct.
A symmetric matrix satisfies — it is unchanged by transpose. Covariance matrices in finance are always symmetric, which makes them tractable for eigenvalue analysis in Chapter 6.
05 · Special Matrices
Four matrices appear so often they have names. Recognising them on sight saves work.
The identity matrix has ones on the main diagonal and zeros elsewhere:
For any : and . Multiplying by is the matrix analogue of multiplying a number by 1.
A square matrix is diagonal if whenever — all entries off the main diagonal are zero:
Products of diagonal matrices are easy: — just multiply the diagonal entries. No row-by-column calculation needed.
A square matrix is symmetric if , i.e., for all .
Symmetric matrices are their own transpose. Every covariance matrix is symmetric because .
For two assets with variances , , and covariance :
✓ — the off-diagonal entries are equal. This symmetry is not accidental; it holds for every covariance matrix by definition of covariance.
06 · The Trace
The trace of a square matrix is the sum of its diagonal entries. It is the first of several invariants — numbers that capture something essential about the matrix regardless of how it is written.
For :
Only defined for square matrices. The trace is a single real number.
Identify the main diagonal entries: , , . The main diagonal runs from top-left to bottom-right.
Sum the diagonal entries: . The is from position , the from , the from .
Two trace properties are useful:
— trace is cyclic under products. Note: this does not mean . The matrices may be completely different while their traces of products coincide.
For a covariance matrix , the total variance across all assets equals the trace:
The is the variance of asset 1, the is the variance of asset 2. In PCA, the trace of the covariance matrix equals the total variance to be explained across all principal components.
07 · Practice Exercises
Add entry by entry in the same position. Confirm both matrices have the same dimensions before starting.
: add each entry at the same position.
: . : . : . : . : . : .
.
: multiply every entry of by 3. : . : . : . : . : . : . Therefore .
Let and , both in . Compute and , showing every entry.
Check inner dimensions first: gives a result. Each entry is the dot product of row of with column of .
, . Inner dimensions both 3. Result is .
: row 1 of = , col 1 of = . .
: row 1 of = , col 2 of = . .
: row 2 of = , col 1 of = . .
: row 2 of = , col 2 of = . .
Therefore .
Compute where and . Show every entry computation in full.
Transpose by writing each row of as the corresponding column of . Then check by computing both sides.
, so : row 1 of becomes col 1 of , row 2 becomes col 2, row 3 becomes col 3. .
. .
: dimensions — inner pair is . Mismatch. is not defined. The product is defined: .
. . . . .
For and : (a) Write down and . (b) Determine whether is defined. (c) Compute , showing all four entries.
Compute both and explicitly. If they differ in even one entry, that proves non-commutativity for these matrices.
, .
: : . : . : . : . .
: : . : . : . : . .
. Therefore — matrix multiplication is not commutative for these matrices.
For and , compute both and . Confirm or refute: .
The trace is the sum of diagonal entries. For a symmetric matrix, check that for every off-diagonal pair.
.
. The 3 comes from position , the 5 from , the 7 from .
Symmetry check: ✓. ✓. ✓. All off-diagonal pairs match. Therefore is symmetric.
and is symmetric.
For : (a) Compute . (b) Determine whether is symmetric. Check every off-diagonal pair.
The portfolio variance is . Compute first (matrix-vector product), then take the dot product with .
, .
Step 1 — Compute : row 1: . Row 2: . So .
Step 2 — Compute .
Portfolio variance . Portfolio standard deviation . The total variance of is reduced to because the assets are positively correlated () — but the weights concentrate less than in the high-variance asset.
A two-asset portfolio has covariance matrix (variances in ) and weight vector . Compute the portfolio variance . Show the matrix-vector product first, then the scalar product with .
08 · Summary
| Term | Definition |
|---|---|
| Matrix | Rectangular array with rows, columns. Entry : row , column . |
| Addition | . Requires identical dimensions. |
| Scalar mult. | . Every entry scaled. |
| Matrix product | . Row-by-column dot products. Inner dimensions must match. |
| Non-commutativity | in general. Order matters in every matrix product. |
| Transpose | . Dimensions flip. — order reverses. |
| Identity | Ones on diagonal, zeros elsewhere. . |
| Symmetric | . Off-diagonal entries satisfy . |
| Trace | . Square matrices only. Equals total variance for covariance matrices. |
Next: Systems of Linear Equations — how the equation organises multiple unknowns, and what the solution set looks like geometrically.