






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







How to use this guide. Linear algebra is the mathematics of vectors and matrices, and it sits under a large part of computing: 3D graphics and games move every vertex with a matrix, search engines and recommendation systems rank items with eigenvectors, machine learning fits models by solving linear systems, and image processing treats pictures as large matrices. This guide covers the topics in a typical first course for computing, IT and engineering students. Each section gives the definitions and rules, then worked examples set out the way exam answers are expected. Every vector, matrix product, determinant, inverse, eigenvalue and fitted line in this guide was checked with a Python script (exact fractions) written for it.
Notation used. Vectors are bold lower case ( u , v ) or written as columns or tuples, e.g. (2, −1, 3). Matrices are capital letters (A, B). Aᵀ is the transpose, A⁻¹ the inverse, det(A) or |A| the determinant, I the identity matrix, 0 the zero vector, ‖ v ‖ the length (norm) of v , and λ (lambda) an eigenvalue. An m × n matrix has m rows and n columns; aᵢⱼ is the entry in row i, column j.
Contents
Vectors Matrices and matrix operations Systems of linear equations and Gaussian elimination Determinants The inverse of a matrix and Cramer's rule Linear independence, span, basis and rank Linear transformations and computer graphics Eigenvalues and eigenvectors Applications: Markov chains, least squares and orthogonalisation Summary table Practice questions and answers
A vector has magnitude and direction. In computing it is simply an ordered list of numbers: a point or direction in 2D (x, y) or 3D (x, y, z), a pixel colour (R, G, B), or a row of features describing a customer. The set of all vectors with n real entries is called ℝⁿ.
1.1 Basic operations
Take u = (2, −1, 3) and v = (1, 4, 2).
Operation Rule Result Addition u + v Add matching entries (3, 3, 5) Scalar multiple 2 u − v Multiply each entry, then subtract (4, −2, 6) − (1, 4, 2) = (3, −6, 4) Dot product u · v u₁v₁ + u₂v₂ + u₃v₃ 2 − 4 + 6 = 4 Length ‖ u ‖ √(u₁² + u₂² + u₃²) √(4 + 1 + 9) = √14 ≈ 3. Length ‖ v ‖ √(1 + 16 + 4) = √21 ≈ 4. Unit vector u / ‖ u ‖ Divide by the length (2, −1, 3)/√
A unit vector has length 1; dividing a non-zero vector by its length is called normalising it. In graphics, surface normals and light directions are normalised before lighting is calculated.
1.2 The angle between two vectors
The dot product links algebra and geometry: u · v = ‖ u ‖ ‖ v ‖ cos θ, so
cos θ = ( u · v ) / (‖ u ‖ ‖ v ‖) = 4 / (√14 × √21) = 4 / √294 ≈ 0.2333, so θ ≈ 76.5°.
If u · v = 0 the vectors are orthogonal (perpendicular). If u · v > 0 the angle is acute; if it is negative the angle is obtuse. Cosine similarity, used to compare documents in search engines and recommender systems, is exactly this cos θ applied to word-count or feature vectors.
1.3 Projection
The projection of u onto v is the "shadow" of u along v :
proj vu = (( u · v ) / ( v · v )) v = (4/21)(1, 4, 2) = (4/21, 16/21, 8/21).
The scalar 4/21 tells you how many copies of v the shadow contains. The leftover part u − proj vu is
orthogonal to v ; this idea is the basis of the Gram–Schmidt process in section 9.3 and of least squares fitting.
1.4 The cross product (3D only)
u × v = (u₂v₃ − u₃v₂, u₃v₁ − u₁v₃, u₁v₂ − u₂v₁)
For u = (2, −1, 3), v = (1, 4, 2):
first entry: (−1)(2) − (3)(4) = −2 − 12 = − second entry: (3)(1) − (2)(2) = 3 − 4 = − third entry: (2)(4) − (−1)(1) = 8 + 1 = 9
So u × v = (−14, −1, 9). Check: (−14, −1, 9) · (2, −1, 3) = −28 + 1 + 27 = 0 and (−14, −1, 9) · (1, 4, 2) = −14 − 4 + 18 = 0, so the result is perpendicular to both. Its length √278 ≈ 16.67 equals the area of the parallelogram formed by u and v ; half of it is the area of the triangle. Note v × u = −( u × v ): the cross product is not commutative. Graphics programs use it to find the normal of a triangle from two of its edges.
2. Matrices and matrix operations
A matrix is a rectangular array of numbers. A greyscale image of 1080 × 1920 pixels is a 1080 × 1920 matrix; a spreadsheet of 500 students and 6 marks is a 500 × 6 matrix.
Special matrix Description Example Square Same number of rows and columns 3 × 3 Identity I 1s on the main diagonal, 0 elsewhere; AI = IA = A [[1, 0], [0, 1]] Zero All entries 0 [[0, 0], [0, 0]] Diagonal Non-zero entries only on the main diagonal [[5, 0], [0, 2]] Upper triangular All entries below the diagonal are 0 [[2, 5, 1], [0, 3, 7], [0, 0, 4]] Symmetric A = Aᵀ [[3, 1], [1, 3]]
(Matrices are written row by row in square brackets: [[1, 2], [3, 4]] has first row 1, 2 and second row 3, 4.)
[ 1 2 1 | 9 ] [ 2 -1 3 | 12 ] [ 3 1 -1 | 1 ]
R2 → R2 − 2R1, R3 → R3 − 3R1: [ 1 2 1 | 9 ] [ 0 -5 1 | -6 ] [ 0 -5 -4 | -26 ]
R3 → R3 − R2: [ 1 2 1 | 9 ] [ 0 -5 1 | -6 ] [ 0 0 -5 | -20 ]
Back substitution: −5z = −20 → z = 4 ; −5y + 4 = −6 → y = 2 ; x + 4 + 4 = 9 → x = 1. Check in equation 2: 2 − 2 + 12 = 12. ✓ The RREF is [[1, 0, 0 | 1], [0, 1, 0 | 2], [0, 0, 1 | 4]].
3.3 How many solutions?
Compare the rank (number of non-zero rows in echelon form) of A with the rank of [A | b ], with n unknowns:
Situation Meaning Number of solutions rank A = rank [A | b ] = n Consistent, no free variables Exactly one rank A = rank [A | b ] < n Consistent, n − rank free variables Infinitely many rank A < rank [A | b ] A row reads 0 = non-zero None (inconsistent)
Inconsistent example. x + y + z = 2 and 2x + 2y + 2z = 5. R2 → R2 − 2R1 gives 0 = 1, so there is no solution (the planes are parallel).
Infinitely many example. x + y + z = 6, x − y + 2z = 5, 2x + 3z = 11. The third equation is the sum of the first two, so the RREF is [[1, 0, 1.5 | 5.5], [0, 1, −0.5 | 0.5], [0, 0, 0 | 0]] with rank 2 < 3. Let z = t (a free parameter): x = 5.5 − 1.5t, y = 0.5 + 0.5t, z = t. With t = 1 this gives (4, 1, 1), which satisfies all three equations.
A system with b = 0 is homogeneous. It always has the trivial solution x = 0 , and it has non-trivial solutions exactly when rank A < n (for a square A, when det A = 0).
4. Determinants
The determinant is a single number computed from a square matrix. It tells you whether the matrix is invertible (det ≠ 0) and how the matrix scales area or volume.
2 × 2: det [[a, b], [c, d]] = ad − bc. Example: det [[3, 5], [1, 2]] = 6 − 5 = 1. 3 × 3 by cofactor expansion along row 1: det A = a₁₁(a₂₂a₃₃ − a₂₃a₃₂) − a₁₂(a₂₁a₃₃ − a₂₃a₃₁) + a₁₃(a₂₁a₃₂ − a₂₂a₃₁). The signs follow the checkerboard pattern + − + / − + − / + − +.
Worked example. T = [[2, 1, 3], [0, −1, 4], [1, 2, 0]].
det T = 2[(−1)(0) − (4)(2)] − 1[(0)(0) − (4)(1)] + 3[(0)(2) − (−1)(1)] = 2(−8) − 1(−4) + 3(1) = −16 + 4
Tip: expand along the row or column with the most zeros to save work. For a triangular matrix the determinant is the product of the diagonal: det [[2, 5, 1], [0, 3, 7], [0, 0, 4]] = 2 × 3 × 4 = 24.
4.1 Properties (for n × n matrices)
Property Rule Transpose det(Aᵀ) = det(A) Product det(AB) = det(A) det(B) Inverse det(A⁻¹) = 1 / det(A) Scalar multiple det(kA) = kⁿ det(A) Swap two rows Changes the sign Multiply one row by k Multiplies det by k Add a multiple of one row to another No change Two equal rows, or a row of zeros det = 0
Geometric meaning. |det A| is the factor by which A scales areas (2D) or volumes (3D). A negative determinant means the transformation flips orientation (a mirror image). det A = 0 means space is squashed into a line or plane, so the transformation cannot be undone.
5. The inverse of a matrix and Cramer's rule
A square matrix A is invertible (non-singular) if there is a matrix A⁻¹ with AA⁻¹ = A⁻¹A = I. This happens exactly when det A ≠ 0. Then A x = b has the unique solution x = A⁻¹ b.
5.1 The 2 × 2 formula
[[a, b], [c, d]]⁻¹ = (1 / (ad − bc)) [[d, −b], [−c, a]]: swap the diagonal, negate the off-diagonal, divide by the determinant.
Example. K = [[4, 7], [2, 6]]: det K = 24 − 14 = 10, so K⁻¹ = (1/10)[[6, −7], [−2, 4]] = [[0.6, −0.7], [−0.2, 0.4]]. Check: the top-left entry of KK⁻¹ is 4(0.6) + 7(−0.2) = 2.4 − 1.4 = 1. ✓
5.2 Gauss–Jordan method for larger matrices
Write [A | I] and row-reduce until the left side is I; the right side is then A⁻¹. If a row of zeros appears on the left, A is not invertible.
Example. G = [[1, 2, 0], [0, 1, 3], [2, 5, 4]] (det G = 1).
[ 1 2 0 | 1 0 0 ] [ 0 1 3 | 0 1 0 ] [ 2 5 4 | 0 0 1 ] R3 → R3 − 2R1: [ 0 1 4 | -2 0 1 ] R3 → R3 − R2: [ 0 0 1 | -2 -1 1 ] R2 → R2 − 3R3: [ 0 1 0 | 6 4 -3 ] R1 → R1 − 2R2: [ 1 0 0 | -11 -8 6 ]
G⁻¹ = [[-11, -8, 6], [6, 4, -3], [-2, -1, 1]]
Check: row 1 of G times column 1 of G⁻¹ = 1(−11) + 2(6) + 0(−2) = 1 ✓; row 3 of G times column 1 = 2(−11) + 5(6) + 4(−2) = −22 + 30 − 8 = 0 ✓.
Useful facts: (AB)⁻¹ = B⁻¹A⁻¹ (reversed order); (Aᵀ)⁻¹ = (A⁻¹)ᵀ; (kA)⁻¹ = (1/k)A⁻¹. In practice, programs solve A x = b by elimination (for example numpy.linalg.solve ) rather than computing A⁻¹, because it is faster and more accurate.
5.3 Cramer's rule
For a square system with det A ≠ 0, xᵢ = det(Aᵢ) / det(A), where Aᵢ is A with column i replaced by b.
Example. 3x + 2y = 16, x − y = 2. det A = (3)(−1) − (2)(1) = −5. Dₓ = det [[16, 2], [2, −1]] = −16 − 4 = −20; Dy = det [[3, 16], [1, 2]] = 6 − 16 = −10. So x = −20 / −5 = 4 and y = −10 / −5 = 2. Check:
7.2 Composition: order matters
Doing transformation A first and then B is the single matrix BA (the first transformation is written on the right). Rotating (2, 1) by 90° and then reflecting in the x-axis uses [[1, 0], [0, −1]][[0, −1], [1, 0]] = [[0, −1], [−1, 0]] and sends (2, 1) to (−1, −2). Reflecting first and then rotating gives [[0, 1], [1, 0]] and sends (2, 1) to (1, 2), a different result.
7.3 Homogeneous coordinates and translation
Moving a point by (3, 4) is not linear (it moves the origin), so it cannot be a 2 × 2 matrix. Graphics systems therefore write the point (x, y) as (x, y, 1) and use 3 × 3 matrices; 3D graphics uses 4 × 4 matrices in the same way.
Translate by (tx, ty): [[1, 0, tx], [0, 1, ty], [0, 0, 1]] Rotate 90°: [[0, -1, 0], [1, 0, 0], [0, 0, 1]]
Rotate (2, 1) by 90°, then translate by (3, 4): T·R = [[0, -1, 3], [1, 0, 4], [0, 0, 1]] T·R·(2, 1, 1) = (-1 + 3, 2 + 4, 1) = (2, 6, 1) → point (2, 6)
Translate first, then rotate: R·T·(2, 1, 1) = (-5, 5, 1) → point (-5, 5)
A game engine multiplies the model, view and projection matrices once and then applies the single combined matrix to thousands of vertices, which is far cheaper than applying each transformation separately.
8. Eigenvalues and eigenvectors
A non-zero vector v is an eigenvector of a square matrix A with eigenvalue λ if A v = λ v : the matrix only stretches v (by λ) without turning it off its line.
Method.
Solve the characteristic equation det(A − λI) = 0 for λ. For each λ, solve (A − λI) v = 0 for the non-zero vectors v (a null space).
Worked example. E = [[4, 1], [2, 3]].
det(E − λI) = (4 − λ)(3 − λ) − (1)(2) = λ² − 7λ + 10 = (λ − 5)(λ − 2), so λ = 5 and λ = 2. λ = 5: E − 5I = [[−1, 1], [2, −2]] gives −x + y = 0, so v₁ = (1, 1). Check: E(1, 1) = (5, 5) = 5(1, 1). ✓ λ = 2: E − 2I = [[2, 1], [2, 1]] gives 2x + y = 0, so v₂ = (1, −2). Check: E(1, −2) = (2, −4) = 2(1, −2). ✓
Quick checks for any 2 × 2 matrix: the sum of the eigenvalues equals the trace (sum of the diagonal, 4 + 3 = 7 = 5 + 2) and their product equals the determinant (12 − 2 = 10 = 5 × 2). For a triangular matrix the eigenvalues are the diagonal entries: [[2, 1, 0], [0, 3, 4], [0, 0, −1]] has eigenvalues 2, 3 and −1. A symmetric matrix always has real eigenvalues and orthogonal eigenvectors: [[3, 1], [1, 3]] has λ = 4 with (1, 1) and λ = 2 with (1, −1), and (1, 1) · (1, −1) = 0.
8.1 Diagonalisation and matrix powers
If an n × n matrix has n independent eigenvectors, then A = PDP⁻¹, where the columns of P are the eigenvectors and D is the diagonal matrix of the matching eigenvalues. Then Aᵏ = PDᵏP⁻¹, and Dᵏ just raises each diagonal entry to the power k.
For E: P = [[1, 1], [1, −2]], D = [[5, 0], [0, 2]], P⁻¹ = (1/3)[[2, 1], [1, −1]].
E⁵ = P [[3125, 0], [0, 32]] P⁻¹ = [[2094, 1031], [2062, 1063]] , the same as multiplying E by itself five times.
Where eigenvectors are used. Google's original PageRank is the eigenvector with eigenvalue 1 of a huge link matrix; principal component analysis (PCA) in machine learning uses the eigenvectors of a
covariance matrix to find the directions of greatest variation; vibration and stability analysis in engineering looks at eigenvalues; and Markov chains (next section) settle at an eigenvector.
9. Applications
9.1 Markov chains
A transition matrix describes the probability of moving between states; here each column adds up to
M = [[0.9, 0.5], [0.1, 0.5]] (columns: from Subscribed, from Not subscribed).
Starting from x₀ = (0.5, 0.5): x₁ = M x₀ = (0.7, 0.3) and x₂ = M x₁ = (0.78, 0.22). The long-run steady state solves M x = x , i.e. (M − I) x = 0 , which is an eigenvector with eigenvalue 1: −0.1x + 0.5y = 0 gives x = 5y, so normalising to total 1 gives x = (5/6, 1/6) ≈ (0.833, 0.167). In the long run about 83.3% of people are subscribed.
9.2 Least squares: fitting a line
When a system A x = b has more equations than unknowns it usually has no exact solution. The least squares solution minimises the sum of squared errors and solves the normal equations AᵀA x = Aᵀ b.
Example. Fit y = a + bx to the points (1, 2), (2, 3), (3, 5), (4, 6). Each row of X is (1, xᵢ):
XᵀX = [[4, 10], [10, 30]], Xᵀ y = (16, 47). Solving 4a + 10b = 16 and 10a + 30b = 47 gives b = 1.4 and a = 0.5 , so the line is y = 0.5 + 1.4x. Residuals (actual − fitted): 0.1, −0.3, 0.3, −0.1; sum of squared errors = 0.2.
This is exactly what a linear regression routine in Excel, Python or R computes.
9.3 Orthogonal vectors and Gram–Schmidt
An orthonormal set is a set of mutually perpendicular unit vectors. The Gram–Schmidt process turns any independent set into one: keep the first vector, then subtract from each next vector its projections onto the ones already chosen, and finally normalise.
For a₁ = (1, 1, 0) and a₂ = (1, 0, 1): w₂ = a₂ − (( a₂ · a₁ )/( a₁ · a₁ )) a₁ = (1, 0, 1) − (1/2)(1, 1, 0) = (0.5, −0.5, 1). Check: w₂ · a₁ = 0.5 − 0.5 + 0 = 0 ✓. Normalising gives e₁ = (1, 1, 0)/√2 and e₂ = (1, −1, 2)/ √6. Orthonormal bases make projections easy and lie behind the QR factorisation used by numerical software.
20.Find the least squares line y = a + bx through (0, 1), (1, 3), (2, 4), (3, 4).
Answers
1. a · b = 3 − 8 − 2 = −7 ; ‖ a ‖ = √(9 + 4 + 1) = √14 ≈ 3.742. The dot product is not zero, so they are not orthogonal (the angle is obtuse because it is negative). 2. Dot product = 0 + 0 + 1 = 1; each length is √2, so cos θ = 1/2 and θ = 60°. 3. (2·6 − 3·5, 3·4 − 1·6, 1·5 − 2·4) = (−3, 6, −3). Its length is √54 ≈ 7.348, so the triangle's area is half of that, ≈ 3.. 4. (4, 2) · (3, 1) = 14 and (3, 1) · (3, 1) = 10, so the projection is 1.4(3, 1) = (4.2, 1.4). 5. AB is 2 × 2: row 1: (3 + 0 + 2, 1 + 0 + 0) = (5, 1); row 2: (−3 + 6 + 1, −1 + 3 + 0) = (4, 2). AB = [[5, 1], [4, 2]]. BA is 3 × 3. 6. AB = [[2, 1], [1, 1]] and BA = [[1, 1], [1, 2]]. They differ, so matrix multiplication is not commutative. 7. R2 − 2R1 gives −3y − z = −6; R3 − R1 gives y − 2z = −5. From the second, y = 2z − 5; substituting: −3(2z − 5) − z = −6 → −7z = −21 → z = 3 , y = 1 , x = 6 − 1 − 3 = 2. Check: 4 − 1 + 3 = 6 ✓, 2 + 2 − 3 = 1 ✓. 8. The coefficient determinant is k − 4. (a) k ≠ 4 : exactly one solution. (b) k = 4 : R2 − 2R1 gives 0 = 5 − 6 = −1, a contradiction, so no solution. (With these right-hand sides there is no value giving infinitely many solutions.) 9. 3 × 4 − 1 × (−2) = 12 + 2 = 14. 10. 1(4·6 − 5·0) − 2(0·6 − 5·1) + 3(0·0 − 4·1) = 24 + 10 − 12 = 22. 11. det(2A) = 2³ × 5 = 40 ; det(Aᵀ) = 5 ; det(A⁻¹) = 1/5 ; swapping two rows gives −. 12. det = 6 − 5 = 1, so the inverse is [[3, −5], [−1, 2]]. Check: [[2, 5], [1, 3]][[3, −5], [−1, 2]] = [[1, 0], [0, 1]] ✓. 13. det A = (2)(−1) − (3)(5) = −17; Dₓ = (13)(−1) − (3)(7) = −34; Dy = (2)(7) − (13)(5) = −51. x =
−34/−17 = 2 , y = −51/−17 = 3.
14. No, they are dependent. The determinant of the matrix with these columns is 1(5 − 1) − 0 + 2( − 2) = 0. Indeed (2, 1, 5) = 2(1, 0, 2) + 1(0, 1, 1). 15. RREF = [[1, 2, 0], [0, 0, 1], [0, 0, 0]], so rank = 2 and nullity = 3 − 2 = 1. From x + 2y = 0 and z = 0, with y = t: x = −2t, so a null-space basis is (−2, 1, 0). 16. Rotation: (3, 1) → (−1, 3). Reflection in the x-axis: (−1, 3) → (−1, −3). Combined matrix (reflection × rotation) = [[1, 0], [0, −1]][[0, −1], [1, 0]] = [[0, −1], [−1, 0]]. 17. S·T = [[2, 0, 0], [0, 2, 0], [0, 0, 1]][[1, 0, 5], [0, 1, −2], [0, 0, 1]] = [[2, 0, 10], [0, 2, −4], [0, 0, 1]]. Applied to (1, 1, 1): (2 + 10, 2 − 4, 1), so the image is (12, −2). (Translating gives (6, −1); doubling gives (12, −2).) 18. (2 − λ)² − 1 = 0 → λ² − 4λ + 3 = 0 → λ = 3 with eigenvector (1, 1) , and λ = 1 with eigenvector (1, −1). Trace 4 = 3 + 1 and det 3 = 3 × 1 ✓. 19. A is triangular, so λ = 1 and 3. λ = 1: (A − I) = [[0, 2], [0, 2]] gives y = 0, v = (1, 0). λ = 3: (A − 3I) = [[−2, 2], [0, 0]] gives x = y, v = (1, 1). P = [[1, 1], [0, 1]], D = [[1, 0], [0, 3]], P⁻¹ = [[1, −1], [0, 1]]. A⁴ = P[[1, 0], [0, 81]]P⁻¹ = [[1, 80], [0, 81]]. 20. XᵀX = [[4, 6], [6, 14]] and Xᵀ y = (12, 23). Solving 4a + 6b = 12 and 6a + 14b = 23 gives b = 1 and a = 1.5 , so y = 1.5 + x. (Equivalently: x̄ = 1.5, ȳ = 3, Sxy = 5, Sxx = 5, b = 1, a = 3 − 1.5 = 1.5.)