Linear Algebra Intro
Linear algebra is the mathematics of vectors, matrices and linear equations. It is the workhorse of modern computing: every 3D game, every neural network and every search engine runs on it. This course takes you from solving small systems of equations by hand to eigenvalues, inner products and the matrix tricks behind LLMs.
The reference book
The topic order of this course follows the chapters of Peter Selinger's open textbook Matrix Theory and Linear Algebra (Dalhousie University), which is published under the Creative Commons Attribution 4.0 (CC BY 4.0) licence. You can read the book for free at mathstat.dal.ca/~selinger/linear-algebra. Thanks to Peter Selinger for making it open.
The book is used as a map of topics only: the explanations, examples, numbers and exercises in these lessons are written from scratch, with a programmer's angle and runnable Python.
What is in the course
| Part | Topics |
|---|---|
| 1. Systems of linear equations | geometric and algebraic view, elementary row operations, Gaussian and Gauss-Jordan elimination, homogeneous systems, fields, applications |
| 2. Vectors in | points and vectors, addition, scalar multiplication, linear combinations, length, dot and cross product |
| 3. Lines and planes in | parametric and normal forms |
| 4. Matrices | arithmetic, multiplication, inverses, elementary matrices, transpose, arithmetic mod , cryptography |
| 5. Spans, independence and bases in | span, linear independence, subspaces, dimension, column/row/null space |
| 6. Linear transformations in | the matrix of a transformation, rotations, projections, perspective rendering |
| 7. Determinants | cofactors, row operations, the inverse formula, Cramer's rule |
| 8. Eigenvalues and eigenvectors | diagonalization, matrix powers, recurrences, differential equations, Cayley-Hamilton |
| 9. Vector spaces | the abstract definition, subspaces, bases, error-correcting codes |
| 10. Linear transformations of vector spaces | the algebra of transformations, matrices with respect to a basis |
| 11. Inner product spaces | orthogonality, Gram-Schmidt, least squares, symmetric matrices, PCA |
| Appendix | complex numbers |
| Linear algebra in computing | graphics pipelines, quaternions, neural layers, embeddings, attention, SVD, LoRA, PageRank, numerical methods |
Why programmers need linear algebra
| Where | What linear algebra does there |
|---|---|
| 3D graphics and games | Every vertex is a vector; moving, rotating and projecting a model is a matrix product. Lighting uses dot products, surface normals use cross products. |
| Machine learning | A dataset is a matrix (rows = samples). Linear regression is a least-squares problem; PCA is an eigenvalue problem. |
| Deep learning | A dense layer computes . Training a network is mostly multiplying big matrices on a GPU. |
| LLMs | Tokens become embedding vectors; similar meanings have a large cosine similarity. Attention is the matrix product . |
| Search and ranking | Google's PageRank is an eigenvector of the web's link matrix. |
| Error-correcting codes | QR codes, disks and network packets use linear codes over the field . |
| Simulation and engineering | Circuits, structures and fluids reduce to large linear systems . |
Here is a tiny taste of the most common task in the whole course, solving a linear system:
from sympy import Matrix
# 2x + 3y = 13
# x - y = -1
A = Matrix([[2, 3], [1, -1]])
b = Matrix([13, -1])
print("solution:", list(A.solve(b)))solution: [2, 3]
And the same object, a matrix, doing graphics work: rotating the point by 90° about the origin.
import numpy as np
theta = np.pi / 2
R = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
p = np.array([1.0, 0.0])
print("rotated point:", np.round(R @ p, 6))rotated point: [0. 1.]
How lessons work
Every lesson explains the idea in plain words, typesets formulas in math notation (, , ), and then computes it. We use two Python libraries:
- SymPy
Matrixfor exact arithmetic with fractions, so row reduction gives1/3instead of0.333333. - NumPy for fast floating-point work on big arrays, the way ML and graphics code does it.
The next lesson, Linear Algebra with SymPy and NumPy, shows both side by side. If NumPy is new to you, see the NumPy course first.
Tip: Linear algebra rewards doing small examples by hand. Each lesson ends with exercises that have answers and full solutions: try them on paper before opening the solution.
Learning paths
| Your goal | Suggested route |
|---|---|
| General university math | Basic Math → Algebra → Calculus → this course → Differential Equations |
| Game developer | Calculus (vectors, motion) → this course (parts 1–3, 4, 6) → Game Math → Game Physics |
| AI / ML engineer | Calculus → this course (all parts, especially 8, 11 and computing) → Probability → Machine Learning → the Machine Learning track |
| Deep learning and LLMs | this course → Math for Deep Learning → Generative AI & LLMs |
Exercises
Exercise 1: Spot the linear equation
Which of these equations are linear in and ? (a) , (b) , (c) , (d) .
Answer
(a) and (d) are linear; (b) and (c) are not.
Solution
A linear equation only adds constant multiples of the variables: no products of variables, no powers, no functions of them.
Exercise 2: Check a solution
Does solve both and ?
Answer
Yes.
Solution
Exercise 3: Your first solve (code)
Use SymPy to solve , , .
Answer
, , .
Solution
Write the coefficients row by row (a missing variable has coefficient 0) and call solve.
from sympy import Matrix
A = Matrix([[1, 1, 1], [1, -1, 0], [0, 1, 2]])
b = Matrix([6, -1, 8])
print(list(A.solve(b)))[1, 2, 3]
Test yourself
In a dense neural-network layer , what is ?
- A single number
- A matrix of weights
- An activation function
- A list of training examples
Why does this course use SymPy Matrix for row reduction?
- It is faster than NumPy
- It computes exactly with fractions, so no rounding errors appear
- NumPy cannot store matrices
- It runs on the GPU
Which of these is computed as an eigenvector?
- A cross product
- PageRank scores
- A cosine similarity
- A rotation by 90°