TactivergeOffline

Level 5 Independent Engineering Research · Term 1: Advanced Engineering Mathematics

The linear algebra and differential equations behind modern engineering models, and the numerical methods that make them computable: linear systems and rank, transformations and determinants, eigenvalues and stability, conditioning and least squares, state-space ODEs and modal analysis, and the integrators (Euler, semi-implicit Euler, RK4) whose error order you measure yourself.

In this file: 27 lessons across weeks 1–9, with 142 practice questions (questions only, no answers).

Conduct an independent, reproducible engineering investigation using advanced mathematics, estimation and computing, and communicate it to the standard of an early research publication. Levels describe what you can do, not your age. About About 3–4 hours a week: 1.5 hours of study, 1.5–2 hours of computation or research work and 30 minutes of writing. Research weeks are self-paced within that budget..

Week 1: Applied linear algebra

This week you will

Vectors, combinations and span

Two cables hold up one load. Which loads can they balance, and which can they never balance however hard they pull?

About 40 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Every state an engineer tracks (forces, currents, joint angles, sensor readings) is a list of numbers that can be added and scaled. Linear algebra is the grammar of those lists. Before solving anything, it pays to ask what a set of 'ingredient' vectors can possibly build.

Goals

Predict

Column 2 of a 2×2 matrix is exactly twice column 1. How many targets b in the plane can A·x reach?

  1. Every point in the plane
  2. Only the points on one line through the origin
  3. Only the origin

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Start with 'Two cables' and use the sliders to make the orange arrow land on b. Then switch to 'Parallel columns': can you still reach b? Watch the shaded line: it is everything those columns can build.

What the interactive shows, in words

The diagram plots two column vectors of A scaled by sliders x₁ and x₂, laid tip to tail, and a target point b. A text readout gives A·x, b and the miss distance. For parallel columns, a shaded line marks the span; points off it cannot be reached.

Understand

Linear combinations

Given vectors a₁, …, aₙ and numbers x₁, …, xₙ, the vector x₁a₁ + … + xₙaₙ is a linear combination. Matrix–vector multiplication is exactly this: A·x = x₁·(column 1) + x₂·(column 2) + …. So the question 'does Ax = b have a solution?' means 'is b some combination of the columns of A?'

Span and dependence

The span of a set of vectors is every combination of them. Two non-parallel vectors in the plane span the whole plane; two parallel ones span only a line. Vectors are linearly dependent if one is a combination of the others, which means it adds nothing new to the span. A basis is a set that spans the space with no redundancy; its size is the dimension.

Vector spaces, informally

A vector space is any collection you can add and scale without leaving it: arrows in the plane, lists of three currents, even polynomials or solutions of a linear ODE. Closure is what lets us superpose: if two motions satisfy a linear equation, so does their sum. That single fact powers modal analysis later in the term.

Explain it another way: intuitive

Think of columns as ingredients and x as a recipe. Ax = b asks for a recipe that makes dish b. Parallel columns are two bottles of the same sauce: twice as many bottles, no new flavours.

Explain it another way: technical

span{a₁, …, aₙ} = {Σ xᵢaᵢ : xᵢ ∈ ℝ}. Ax = b is solvable if and only if b ∈ col(A), the column space. Columns are independent if and only if Ax = 0 has only x = 0.

Explain it another way: mathematical

For two vectors in ℝ², a₁ and a₂ are dependent exactly when det[a₁ a₂] = 0, because the parallelogram they span then has zero area.

Explain it another way: applied

In a pin-jointed frame, each member's tension pushes the joint along the member's direction. If two members are collinear, they can only resist loads along that line: the joint is a mechanism for sideways loads.

Try these examples

Example 1

Is b = (1, 5) a combination of a₁ = (2, 1) and a₂ = (−1, 1)?

The worked solution is in the online lesson.

Example 2

Are (1, 2, 3), (2, 3, 4) and (3, 5, 7) independent?

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. a₁ = (1, 0.5) and a₂ = (2, 1). What is their span?

  • The whole plane
  • The line through the origin in direction (2, 1)
  • Just the two points

2. Which statement about A·x is always true?

  • A·x is a combination of the rows of A
  • A·x is a combination of the columns of A with weights x
  • A·x has as many entries as x

3. Find x₂ so that x₁(1, 1) + x₂(1, −1) = (5, 1).

Answer:

4. Which set is linearly dependent?

  • (1, 0), (0, 1)
  • (1, 2), (3, 6)
  • (1, 1), (1, −1)

5. u(t) and w(t) both solve the linear ODE x″ + 4x = 0. Which also solves it?

  • u + w only if u = w
  • 3u − 2w
  • u·w

Apply it

Pick a three-member pin-jointed joint (sketch it). Write each member's unit direction as a column of A, the applied load as b, and decide whether the joint can resist every load direction. What happens if two members are collinear?

Reflect

Where in a project of yours would superposition (adding two solutions) save you work?

Writing engineering problems as Ax = b

A resistor network, a loaded frame and a cross-talking sensor pair look nothing alike. Why does one line of code solve all three?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Modelling is usually harder than solving. Once a problem is written as Ax = b, decades of reliable numerical software can take over. The skill is choosing unknowns, writing one equation per physical law, and checking the answer makes physical sense.

Goals

Predict

Two resistor loops share a 1 Ω resistor. Will the matrix A for the mesh currents be symmetric?

  1. Yes: the shared resistor appears equally in both off-diagonal entries
  2. No: circuit matrices are never symmetric
  3. Only if all resistors are equal

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Open the Code Lab. Write a function solve2(A, b) using elimination, then use it on the circuit below. Print the residual b − A·x: it should be (almost exactly) zero.

What the interactive shows, in words

This lesson's activity is code-based: write a small elimination solver, apply it to the two-loop circuit A = [[3, −1], [−1, 2]], b = (2, 3), and print the solution (1.4, 2.2) and the residual, which should be near zero.

Understand

A recipe for modelling
  1. Choose unknowns (loop currents, member tensions, true quantities). 2. Write one equation per physical law: Kirchhoff's voltage law per loop, ΣF = 0 per direction per joint, one sensor model per reading. 3. Collect coefficients into A, knowns into b. 4. Count: as many independent equations as unknowns for a unique answer.
Example: two-loop circuit

A 2 V source drives loop 1 through 2 Ω, and loop 2 contains a 3 V source and 1 Ω. A 1 Ω resistor is shared. KVL in loop 1: 2I₁ + 1(I₁ − I₂) = 2, so 3I₁ − I₂ = 2. Loop 2: 1(I₂ − I₁) + 1·I₂ = 3, so −I₁ + 2I₂ = 3. So A = [[3, −1], [−1, 2]], b = (2, 3), and I = (1.4, 2.2) A.

Always check the residual

Compute r = b − A·x. A tiny residual says you solved the equations you wrote; it does not say they were the right equations. So also sanity-check physics: are currents in a sensible direction, do tensions in a hanging cable come out positive, does the answer change sensibly when you double a source?

Explain it another way: intuitive

Each equation is one rule the world obeys. Stack all the rules, and the solution is the one set of unknowns that obeys every rule at once.

Explain it another way: technical

Nodal and mesh analysis produce A = G or R matrices that are symmetric and, for connected passive networks, positive definite, which guarantees a unique solution.

Explain it another way: applied

SPICE-style circuit simulators assemble exactly such a matrix from component 'stamps' and solve it at every operating point; structural finite-element codes do the same with stiffness matrices.

Try these examples

Example 1

Two sensors read r₁ = q₁ + 0.5q₂ and r₂ = 0.25q₁ + q₂. Readings are r = (3, 2.5). Find the true quantities q.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. For the circuit in the lesson (3I₁ − I₂ = 2, −I₁ + 2I₂ = 3), what is I₂ in amperes?

Answer: A

2. A frame has 3 unknown member forces at a planar joint. How many independent force-balance equations does that joint give?

  • 1
  • 2
  • 3

3. Solve −x₁ + x₂ = -3 and 2x₁ + x₂ = -6. What is x1?

Answer:

4. Solve A·x = b with A = [[0, 2, 3], [4, 0, 1], [1, -3, 1]] and b = (-8, 4, 13). What is x1?

Answer:

5. Your solver returns x with residual ‖b − Ax‖ ≈ 10⁻¹⁴. What have you shown?

  • That the physical model is correct
  • That x solves the equations you wrote, to rounding error
  • That the answer has 14 correct digits

Apply it

Model a three-loop resistor ladder of your own design as a 3×3 system. Solve it in the Code Lab, report the residual, and check one current by hand with KVL.

Reflect

Which step of the modelling recipe do you find hardest, and how could you check it?

Rank: one, none or infinitely many

Three equations, three unknowns, and yet no answer at all. How can counting fail?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Engineers meet singular systems all the time: a mechanism that can move without resistance, a sensor set that cannot tell two quantities apart, redundant constraints. Rank tells you which, before you trust a number.

Goals

Predict

Rows of A: (1, 1, 1), (1, 2, 3), (2, 3, 4). Notice row 3 = row 1 + row 2. With b = (6, 14, 21), how many solutions?

  1. Exactly one
  2. None
  3. Infinitely many

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Step through '3×3, unique', then '3×3, rank 2' and '3×3, inconsistent'. For each, count the pivots and look at the last row when elimination finishes.

What the interactive shows, in words

The row-reduction stepper shows the augmented matrix as a table after each row operation, with the pivot highlighted and the operation described in text. When finished, the readout states the rank and whether the system has one, none or infinitely many solutions.

Understand

Rank

Eliminate to row echelon form. Each non-zero row starts with a pivot; the number of pivots is the rank r. It equals the number of independent columns (and of independent rows). For an m×n matrix, r ≤ min(m, n).

The decision rule

Compare rank A with rank of the augmented matrix [A | b] and the number of unknowns n.

Free variables and the null space

A column without a pivot is free: choose its unknown freely, and back-substitute for the rest. The general solution is x = x_particular + (any vector with Ax = 0). Those homogeneous solutions form the null space, of dimension n − r. Physically, null-space directions are motions or combinations the system cannot 'see', such as a mechanism mode of a frame.

Explain it another way: intuitive

Each equation is a plane. Three planes usually meet at a point. If they meet along a line, there are infinitely many solutions; if they are arranged like a toblerone box with no common point, there are none.

Explain it another way: technical

Rank–nullity: rank A + dim null(A) = n. For square A, rank n ⇔ det A ≠ 0 ⇔ A invertible.

Explain it another way: mathematical

Solvability: b ∈ col(A) ⇔ rank[A | b] = rank A (Rouché–Capelli).

Explain it another way: applied

In a calibration with two sensors that respond identically to two quantities, the matrix has rank 1: no amount of data separates those quantities. The fix is a different sensor, not a better solver.

Try these examples

Example 1

Solve x₁ + x₂ + x₃ = 6, x₁ + 2x₂ + 3x₃ = 14, 2x₁ + 3x₂ + 4x₃ = 20.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. After elimination a 3×3 system ends with the row (0 0 0 | 0). Rank A = 2. What can you say?

  • No solution
  • Exactly one solution
  • Infinitely many solutions (one free variable)

2. Elimination ends with the row (0 0 0 | 4). What does this mean?

  • No solution
  • x₃ = 4
  • Infinitely many solutions

3. A 4×6 matrix has rank 3. What is the dimension of its null space?

Answer:

4. Find det A for A = [[3, 4], [6, 0]].

Answer:

5. A square matrix has det A = 0. Which is true?

  • Ax = b has a unique solution for every b
  • Ax = b has either no solution or infinitely many
  • A has rank n

6. Solve A·x = b with A = [[3, 2, 2], [-1, 1, -2], [1, 0, -1]] and b = (6, 4, 4). What is x1?

Answer:

Apply it

Design a 3×3 sensor-mixing matrix that has rank 2. Explain physically which combination of quantities the sensors cannot distinguish (find a null-space vector).

Reflect

Have you met a project problem that was really a rank problem in disguise?

Week 2: Matrix operations

This week you will

Gaussian elimination, back substitution and LU

Elimination throws away its multipliers. Keep them, and you can re-solve for a new right-hand side almost for free. How?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Every serious linear solver is elimination underneath. Factorising A = LU once and then solving many right-hand sides is how simulators handle a fixed circuit with changing sources, or a structure under many load cases.

Goals

Predict

Solve 0.0001x₁ + x₂ = 1, x₁ + x₂ = 2 rounding every result to 3 significant figures, using the first row as pivot. What does x₁ come out as?

  1. About 1
  2. 0
  3. About 10,000

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Choose '2×2, tiny pivot' with 3-significant-figure rounding, step to the end and read x. Now turn on partial pivoting and repeat. Then step through '3×3, unique' and write down every multiplier ℓᵢⱼ.

What the interactive shows, in words

The stepper lists each row operation in text, such as 'R2 ← R2 − (−1.5)·R1 (multiplier ℓ21 = −1.5)', and shows the matrix as a table. Options toggle partial pivoting and rounding to 3 significant figures; the readout reports the final solution.

Understand

Forward elimination and back substitution

Use the pivot in row 1 to make zeros below it in column 1, then the pivot in row 2 for column 2, and so on, until the matrix is upper triangular U. Then the last equation has one unknown; solve it and substitute upwards. Apply every row operation to b as well (that is why we work with [A | b]).

Keep the multipliers

The multiplier ℓᵢⱼ = (entry being cleared)/(pivot). Store it in L at position (i, j), with 1s on L's diagonal. For A = [[2, 1, −1], [−3, −1, 2], [−2, 1, 2]] the multipliers are ℓ₂₁ = −1.5, ℓ₃₁ = −1, ℓ₃₂ = 4, giving U = [[2, 1, −1], [0, 0.5, 0.5], [0, 0, −1]].

Why pivot?

Dividing by a tiny pivot creates huge multipliers, and huge numbers swamp small ones when rounded. Partial pivoting swaps up the row with the largest entry in the current column, keeping every |ℓᵢⱼ| ≤ 1. It costs almost nothing and is used by essentially every dense solver.

Explain it another way: intuitive

Elimination tidies equations into a staircase you can walk down from the bottom. LU is writing down the tidying moves so you can repeat them on new data without thinking again.

Explain it another way: technical

Gaussian elimination with partial pivoting computes PA = LU. It is backward stable in practice: the computed solution solves a nearby problem (A + δA)x = b with small δA.

Explain it another way: mathematical

LU without pivoting exists if and only if every leading principal minor of A is non-zero.

Explain it another way: applied

A structural code factorises the stiffness matrix K = LU once, then solves for displacements under dozens of load cases (wind, snow, traffic) with cheap triangular solves.

Derivation: Elimination is A = LU
  1. Subtracting ℓ₂₁ × row 1 from row 2 is left-multiplication by E₂₁ = I − ℓ₂₁e₂e₁ᵀ (the identity with −ℓ₂₁ in position (2, 1)).

  2. Forward elimination is a product of such matrices: E₃₂E₃₁E₂₁·A = U, upper triangular.

  3. Each Eᵢⱼ is undone by flipping the sign of its multiplier, and the inverses multiply in reverse order without interfering: L = E₂₁⁻¹E₃₁⁻¹E₃₂⁻¹ has 1s on the diagonal and ℓᵢⱼ in position (i, j).

  4. Therefore A = LU. To solve Ax = b, solve Ly = b by forward substitution, then Ux = y by back substitution.

  5. Cost: factorising is about (2/3)n³ operations; each extra right-hand side is only about 2n². With row swaps, PA = LU for a permutation matrix P.

Try these examples

Example 1

Solve 2x₁ + x₂ − x₃ = 8, −3x₁ − x₂ + 2x₃ = −11, −2x₁ + x₂ + 2x₃ = −3.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. In A = [[2, 1, −1], [−3, −1, 2], [−2, 1, 2]], what multiplier ℓ₂₁ clears the (2, 1) entry?

Answer:

2. Solve A·x = b with A = [[-2, 3, -2], [-2, 3, 4], [-3, 4, -3]] and b = (-11, 7, -15). What is x3?

Answer:

3. Why does partial pivoting help?

  • It makes the matrix symmetric
  • It keeps multipliers at most 1 in size, limiting round-off growth
  • It reduces the operation count from n³ to n²

4. You have A = LU. A new right-hand side b′ arrives. What do you do?

  • Factorise again
  • Forward-substitute Ly = b′, then back-substitute Ux = y
  • Compute A⁻¹ first

5. Factorising costs about (2/3)n³ operations. Roughly how many times longer does n = 2000 take than n = 1000?

Answer:

Apply it

In the Code Lab, implement lu(A) without pivoting, test that L·U reproduces A on three matrices, then show it failing on [[0, 1], [1, 0]] and explain why pivoting fixes it.

Reflect

Which rounding surprise in the tiny-pivot example would you have missed if you had used exact arithmetic?

Matrix multiplication as composition

Rotate then shear, or shear then rotate: the same two moves, different results. Why does order matter for matrices?

About 40 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Chaining coordinate frames along a robot arm, cascading filters, combining a sensor model with a calibration: all are matrix products. Getting the order wrong is one of the most common bugs in robotics code.

Goals

Predict

R rotates by 90°, S is the shear [[1, 1], [0, 1]]. Is SR (rotate first, then shear) equal to RS?

  1. Yes, always
  2. No, they differ
  3. Only for 90° rotations

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Load 'Shear' into A and choose 'Then apply B: Rotate 30°'. Note where î and ĵ land. Now load 'Rotate 30°' into A and apply B = 'Shear'. Same two maps, different picture. Check that det(BA) = det(B)·det(A) both times.

What the interactive shows, in words

The transformation grid shows a grid and unit square mapped by the combined matrix B·A, with î and ĵ drawn as labelled arrows. Text gives the combined matrix entries and det A, det B and det(BA).

Understand

The rule

If A is m×n and B is n×p, then AB is m×p with (AB)ᵢⱼ = Σₖ aᵢₖbₖⱼ: row i of A dotted with column j of B. Inner dimensions must match. Equivalently, column j of AB is A times column j of B.

Composition

(BA)x = B(Ax): first A acts, then B. So BA means 'A then B', read right to left, just like function composition f(g(x)). Associativity, (CB)A = C(BA), lets you pre-multiply a chain of frames into one matrix once.

Order and transposes

In general AB ≠ BA; commuting is the exception (for example two rotations about the same axis, or diagonal matrices). The transpose swaps rows and columns, and reverses products: (AB)ᵀ = BᵀAᵀ. Similarly (AB)⁻¹ = B⁻¹A⁻¹: to undo 'put on socks, then shoes', take off shoes first.

Explain it another way: intuitive

A matrix is a move. Multiplying matrices is doing moves in sequence. Turning left then walking forward is not the same as walking forward then turning left.

Explain it another way: technical

Matrices represent linear maps relative to a basis; the product represents the composite map. Cost of an n×n product by the definition is n³ multiply–adds.

Explain it another way: applied

A camera pose in world coordinates is T_world←robot · T_robot←camera. Swap the order and the camera ends up somewhere physically meaningless.

Try these examples

Example 1

Compute AB for A = [[1, 2], [3, 4]], B = [[0, 1], [1, 0]], and BA.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. A = [[-4, 1], [5, 5]] and B = [[-2, 2], [3, 0]]. What is the entry in row 2, column 1 of the product AB?

Answer:

2. To apply A first and then B to a vector x, you compute…

  • ABx
  • BAx
  • Either: they are equal

3. A is 3×2 and B is 2×4. What size is AB?

  • 2×2
  • 3×4
  • It is undefined

4. Which equals (AB)ᵀ?

  • AᵀBᵀ
  • BᵀAᵀ
  • BA

5. A = [[0, -4, 2], [1, 0, 0], [-3, -3, -3]] and B = [[0, -4, -2], [3, 4, 1], [5, -4, 0]]. What is the entry in row 3, column 1 of the product AB?

Answer:

Apply it

Build a two-link planar arm transform in the Code Lab: T = Rot(θ₁)·Trans(L₁)·Rot(θ₂)·Trans(L₂) with 3×3 homogeneous matrices. Swap two factors and show the hand position changes.

Reflect

Where in code you have written could a reversed product hide?

Inverses: undoing a linear map

A sensor matrix turns true forces into readings. Can you always run it backwards to turn readings into forces?

About 40 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Inverting a calibration, a coordinate change or a mixing matrix is a daily engineering task. Knowing when it is impossible (and when it is merely dangerous) prevents confident nonsense.

Goals

Predict

A = [[2, 4], [1, 2]]. Does A⁻¹ exist?

  1. Yes
  2. No, because det A = 0
  3. Only if we allow complex numbers

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Open the Code Lab. Write inv2(A) using the formula below and test it on five random matrices by checking A·inv2(A) ≈ I. Then try a matrix with determinant 10⁻⁹ and look at the entries.

What the interactive shows, in words

This activity is code-based: implement the 2×2 inverse formula, verify A times its inverse equals the identity on random matrices, and observe the very large entries that appear when the determinant is tiny.

Understand

What an inverse is

A⁻¹ is the matrix with A⁻¹A = AA⁻¹ = I. It exists exactly when A is square with det A ≠ 0 (rank n). Then Ax = b has the unique solution x = A⁻¹b. Geometrically, the map must not squash any direction to zero, or it cannot be undone.

Gauss–Jordan for bigger matrices

Write [A | I] and row-reduce all the way to [I | X]: eliminate below and above each pivot and scale pivots to 1. Then X = A⁻¹. If a zero pivot cannot be fixed by swapping, A is singular.

Solve, don't invert

In computation, forming A⁻¹ costs about three times more than an LU solve and is typically less accurate. Libraries offer solve(A, b) for this reason. Inverses remain useful on paper, for small fixed matrices, and when you genuinely need the entries (for example a covariance matrix).

Explain it another way: intuitive

If a map is a recipe for scrambling, the inverse is the unscrambling recipe. Scrambling that throws ingredients away (det 0) cannot be unscrambled.

Explain it another way: technical

Invertibility is equivalent to: det A ≠ 0, rank n, columns independent, Ax = 0 only for x = 0, and no zero eigenvalue.

Explain it another way: mathematical

Cofactor formula: (A⁻¹)ᵢⱼ = (−1)ⁱ⁺ʲ Mⱼᵢ / det A, where Mⱼᵢ is the minor deleting row j and column i. Note the transposed indices.

Explain it another way: applied

A six-axis force sensor uses a 6×6 calibration matrix to turn strain-gauge voltages into forces and torques; a poorly designed sensor gives a nearly singular matrix.

Derivation: The 2×2 inverse formula
  1. Let A = [[a, b], [c, d]]. We want X with AX = I.

  2. Try X = k·[[d, −b], [−c, a]] (swap the diagonal, negate the off-diagonal).

  3. Then AX = k·[[ad − bc, −ab + ba], [cd − dc, −cb + da]] = k·(ad − bc)·I.

  4. Choosing k = 1/(ad − bc) gives AX = I, so A⁻¹ = (1/det A)·[[d, −b], [−c, a]].

  5. This only works if det A = ad − bc ≠ 0; when it is zero there is no inverse.

Try these examples

Example 1

Invert A = [[3, 1], [2, 5]] and check.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. A = [[2, -5], [1, 6]]. What is the entry in row 2, column 1 of A⁻¹? (Give a decimal.)

Answer:

2. Which matrix has no inverse?

  • [[1, 2], [3, 4]]
  • [[2, 6], [1, 3]]
  • [[0, 1], [1, 0]]

3. What is (AB)⁻¹?

  • A⁻¹B⁻¹
  • B⁻¹A⁻¹
  • (BA)⁻¹

4. A = [[-1, 3], [4, 6]]. What is the entry in row 1, column 2 of A⁻¹? (Give a decimal.)

Answer:

5. A colleague computes x = inv(A) * b for a 5000×5000 system. Best advice?

  • Fine: that is the standard method
  • Use solve(A, b) (LU): cheaper and more accurate
  • Use Cramer's rule

Apply it

Find the inverse of the sensor-mixing matrix [[1, 0.5], [0.25, 1]] and use it to recover the true quantities for three different readings. Then make the cross-talk 0.99 and 0.99: what happens to the inverse's entries?

Reflect

Why might an inverse that 'exists' still be useless in practice?

Week 3: Linear transformations

This week you will

Rotation, shear, stretch and projection

Every 2×2 matrix is a picture. Can you guess what [[1, 1], [0, 1]] does to a square before you calculate anything?

About 40 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Robots rotate frames, cameras project 3D onto 2D, materials shear under load. Recognising these maps by their matrices lets you debug a transform at a glance.

Goals

Predict

Where does [[1, 1], [0, 1]] send the point (0, 1)?

  1. (0, 1)
  2. (1, 1)
  3. (1, 0)

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Load each preset in turn (rotate, shear, stretch, reflect, project). Before you look, predict where î and ĵ land from the matrix columns. Then drag a₂₂ towards 0 and watch the grid collapse.

What the interactive shows, in words

The grid diagram draws the image of a square grid and the unit square under the chosen matrix, with î and ĵ as labelled arrows. Sliders set each entry; presets load rotation, shear, stretch, reflection and projection. Text reports the determinant and whether orientation flips or the plane collapses.

Understand

Columns are images of the basis

A·(x, y) = x·A(î) + y·A(ĵ). So column 1 is A(î) and column 2 is A(ĵ). Linear maps keep the origin fixed, keep lines straight and keep evenly spaced grid lines evenly spaced.

A catalogue

Rotation by θ: [[cos θ, −sin θ], [sin θ, cos θ]], det 1. Shear: [[1, k], [0, 1]], det 1. Stretch: [[s₁, 0], [0, s₂]], det s₁s₂. Reflection in the x-axis: [[1, 0], [0, −1]], det −1. Projection onto the x-axis: [[1, 0], [0, 0]], det 0.

Projections

A projection P drops each vector onto a subspace. Doing it twice changes nothing more, so P² = P. It squashes a direction to zero, so det P = 0 and there is no inverse: from the shadow you cannot recover the object. Projection onto a unit vector u is P = uuᵀ, which reappears in least squares.

Explain it another way: intuitive

Draw the unit square. Move its two edges from the origin to the matrix columns. The square becomes a parallelogram, and every other shape follows the grid.

Explain it another way: technical

A rotation matrix is orthogonal: RᵀR = I, so R⁻¹ = Rᵀ and lengths and angles are preserved.

Explain it another way: applied

A camera's projection from 3D points to the image plane (after dividing by depth) is the reason one photo cannot give you depth: a whole line of points maps to one pixel.

Try these examples

Example 1

Write the matrix that rotates by 90° anticlockwise and check it sends (1, 0) to (0, 1).

The worked solution is in the online lesson.

Example 2

Find the matrix projecting onto the line through u = (1, 1)/√2.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. A sends î to (2, 0) and ĵ to (0, 3). What is A?

  • [[2, 0], [0, 3]]
  • [[2, 3], [0, 0]]
  • [[0, 2], [3, 0]]

2. [[1, 0], [0, −1]] is a…

  • Rotation by 180°
  • Reflection in the x-axis
  • Projection

3. For the rotation by 60°, what is the (2, 1) entry (sin 60°)?

Answer:

4. P projects onto a line. What is P³?

  • 0
  • P
  • I

5. A = [[0, -4, 2], [1, 0, 0], [-3, -3, -3]] and B = [[0, -4, -2], [3, 4, 1], [5, -4, 0]]. What is the entry in row 3, column 1 of the product AB?

Answer:

Apply it

Find a matrix that rotates by 45° and then stretches by 2 along x. Predict its columns by reasoning, then check with the transformation grid.

Reflect

Which of the five maps would you find hardest to recognise from its numbers alone?

The determinant as area scaling

Why does a single number, ad − bc, tell you whether a whole system of equations can be solved?

About 40 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Determinants detect singularities: frames that become mechanisms, robot arms that lose a direction of motion, coordinate changes that break down. As an area factor they also appear in every change of variables in an integral.

Goals

Predict

A = [[2, 0], [0, 3]]. What happens to the area of a 1 cm² square under A?

  1. It becomes 5 cm²
  2. It becomes 6 cm²
  3. It stays 1 cm²

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Watch the shaded parallelogram while you change entries. Find three different matrices with det = 1. Then make det negative and describe what happens to the order of î and ĵ. Finally compose two maps and check det(BA) = det(B)·det(A).

What the interactive shows, in words

The diagram shades the image of the unit square, coloured differently when the determinant is negative. The readout gives det A, det B, det(BA) and the new area, and says when orientation flips or the plane collapses.

Understand

Meaning

|det A| is the factor by which A scales areas (2D) or volumes (3D). det A < 0 means orientation is reversed (a mirror image). det A = 0 means some direction is squashed to zero: the image is a line or point, so A is not invertible and its columns are dependent.

Rules worth knowing

det(AB) = det A · det B (scale factors multiply). det(A⁻¹) = 1/det A. det Aᵀ = det A. Row operations: adding a multiple of one row to another leaves det unchanged; swapping two rows flips its sign; scaling a row by k scales det by k. So det = ± (product of pivots) after elimination.

Singularities in robotics

A robot arm's Jacobian J maps joint speeds to hand velocity. Where det J = 0 the arm is at a singularity: some hand directions need infinite joint speed. For a two-link planar arm, det J = L₁L₂ sin θ₂, zero when the arm is straight or folded back.

Explain it another way: intuitive

Paint the unit square. The determinant is how much paint you need after the map: double the paint, det 2; mirror image, negative; flattened to a line, zero paint.

Explain it another way: technical

det is the unique function of the columns that is linear in each column, alternating (swapping two columns flips sign), and equal to 1 on I.

Explain it another way: mathematical

For 3×3, det A = a(ei − fh) − b(di − fg) + c(dh − eg), the signed volume of the parallelepiped spanned by the columns.

Explain it another way: applied

In finite-element analysis, the determinant of each element's mapping Jacobian must stay positive; a negative value means a badly distorted (inside-out) element.

Derivation: ad − bc is the parallelogram's area
  1. The columns (a, c) and (b, d) span a parallelogram; the unit square maps onto it.

  2. Enclose it in the rectangle [0, a + b] × [0, c + d] (for positive entries) of area (a + b)(c + d).

  3. Subtract the corner pieces: two triangles of area ac/2, two of area bd/2, and two rectangles of area bc.

  4. Area = (a + b)(c + d) − ac − bd − 2bc = ad − bc.

  5. Because the map is linear, every small square scales by the same factor, so every region's area is multiplied by |ad − bc|; the sign records orientation.

Try these examples

Example 1

Compute det of [[2, 1, −1], [−3, −1, 2], [−2, 1, 2]] from its LU factorisation.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Find det A for A = [[-4, 1, 6], [6, -1, 2], [3, 0, 6]].

Answer:

2. A maps the unit square to the parallelogram with sides (3, 1) and (1, 2). What is its area?

Answer:

3. det A = 4 and det B = −0.5. What is det(AB)?

Answer:

4. Swapping two rows of A does what to det A?

  • Nothing
  • Flips its sign
  • Sets it to zero

5. A two-link planar arm has det J = L₁L₂ sin θ₂. When is it singular?

  • When θ₁ = 0
  • When θ₂ = 0° or 180°
  • Never, if the links are long enough

Apply it

For a two-link arm with L₁ = L₂ = 1, plot |det J| against θ₂ in the Code Lab and mark where the arm is most 'agile'. Explain what happens at the ends of the range.

Reflect

Where else have you seen a quantity that is zero exactly when something becomes impossible?

Module check: the Jacobian as a linear map

Near any pose, a robot arm behaves like a matrix. What can that matrix tell you about where the arm can and cannot move?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

This module check pulls weeks 1–3 together: linear systems, products, inverses and determinants, applied to a real engineering map. Resolved-rate control and numerical inverse kinematics are exactly this calculation, repeated many times a second.

Goals

Predict

A two-link arm is fully stretched out (θ₂ = 0). Can the hand move straight outwards along the arm with small joint motions?

  1. Yes, easily
  2. No: that direction is lost at this pose
  3. Only if θ₁ is also 0

Write down your guess and your reason. The reveal is in the online lesson.

Discover

In the kinematics lab, move the two joints and watch the hand. Find a pose where turning either joint moves the hand in the same direction: that is a singular pose. Note the joint angles.

What the interactive shows, in words

The kinematics lab shows a two-link arm controlled by two joint-angle sliders, with the hand position given in text. A singular pose is one where both joints move the hand along the same line, such as when the arm is fully stretched.

Understand

Question → method → evidence

Question: at a given pose, which hand motions are possible and how much joint motion do they need? Method: linearise to J, then treat Δp = J·Δθ as a linear system. Evidence: solve for Δθ, compare the predicted hand motion with the exact forward kinematics, and examine det J and the columns of J.

Columns tell the story

Column 1 of J is the hand velocity from turning joint 1 alone; column 2 from joint 2 alone. Their span is the set of achievable hand velocities. If the columns become parallel, the span collapses to a line, exactly as in week 1's column picture.

Near-singular is already bad

Close to a singularity, det J is small and J⁻¹ has huge entries: a modest hand step demands enormous joint speeds, and sensor noise in θ is amplified. Controllers use damped least squares or avoid such poses. This links straight to conditioning in week 5.

Explain it another way: intuitive

Zoom in far enough on any smooth curve and it looks straight. Zoom in on an arm's motion and it looks like a matrix.

Explain it another way: technical

J is the derivative of the forward-kinematics map; Δp = JΔθ is its first-order Taylor approximation, accurate for small Δθ.

Explain it another way: applied

Industrial robots plan paths that stay away from wrist and elbow singularities, because near them the controller would command joint speeds beyond the motors' limits.

Derivation: The two-link Jacobian
  1. Hand position: x = L₁cos θ₁ + L₂cos(θ₁ + θ₂), y = L₁sin θ₁ + L₂sin(θ₁ + θ₂).

  2. Small changes: Δx ≈ (∂x/∂θ₁)Δθ₁ + (∂x/∂θ₂)Δθ₂, and the same for y. In matrix form Δp ≈ J·Δθ.

  3. J = [[−L₁sin θ₁ − L₂sin(θ₁ + θ₂), −L₂sin(θ₁ + θ₂)], [L₁cos θ₁ + L₂cos(θ₁ + θ₂), L₂cos(θ₁ + θ₂)]].

  4. det J = L₁L₂[sin(θ₁ + θ₂)cos θ₁ − cos(θ₁ + θ₂)sin θ₁] = L₁L₂ sin θ₂.

  5. Where det J ≠ 0, Δθ = J⁻¹Δp gives the joint step for a desired hand step. Where det J = 0, J has rank 1 and some Δp cannot be produced.

Try these examples

Example 1

L₁ = L₂ = 1, θ₁ = 0, θ₂ = 90°. Find J and the joint step for Δp = (0, 0.01).

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. L₁ = 0.5 m, L₂ = 0.4 m, θ₂ = 30°. What is det J (in m²)?

Answer: m²

2. A = [[-3, 4], [-3, -3]]. What is the entry in row 2, column 2 of A⁻¹? (Give a decimal.)

Answer:

3. Solve −x₁ + x₂ = -3 and 2x₁ + x₂ = -6. What is x1?

Answer:

4. At θ₂ = 180° (folded back), the rank of J is…

  • 2
  • 1
  • 0

5. Why do controllers avoid poses where det J is small but not zero?

  • The arm becomes heavier
  • J⁻¹ has huge entries, so small hand moves need huge joint speeds
  • The forward kinematics stops working

6. Find det A for A = [[3, 3, -1], [1, -3, 1], [0, -2, 4]].

Answer:

Apply it

Write a resolved-rate loop in the Code Lab: repeatedly compute J, solve J·Δθ = small step towards a target, update θ. Move the target through a singular pose and record what happens to |Δθ|.

Reflect

Which idea from weeks 1–3 did this module check depend on most?

Week 4: Eigenvalues and eigenvectors

This week you will

Eigenvectors: the directions that survive

Push almost any vector through a matrix and it swings round. A few special directions only stretch. Why do engineers care so much about them?

About 40 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Vibration modes of a bridge, principal stress directions in a beam, the slow and fast modes of a robot joint, the ranking in a search engine: all are eigenvectors. In their direction, a complicated matrix acts like a single number.

Goals

Predict

For A = [[2, 1], [1, 2]], which direction do you think A only stretches?

  1. Along (1, 0)
  2. Along (1, 1)
  3. No direction: every vector turns

Write down your guess and your reason. The reveal is in the online lesson.

Discover

For each matrix, sweep the direction slider until the readout says you are on an eigen-line. Record the angle and λ. What happens for the shear and for the rotation?

What the interactive shows, in words

The eigen-finder draws a unit vector x at an angle set by a slider and its image Ax. Text reports how many degrees Ax is turned away from the line of x and announces when x lies on an eigen-line, with the stretch factor λ. A button reveals the eigen-lines and the eigenvalues.

Understand

Definition

A non-zero vector v is an eigenvector of a square matrix A if A·v = λ·v for some number λ, its eigenvalue. The whole line through v is mapped onto itself and stretched by λ. λ > 1 stretches, 0 < λ < 1 shrinks, λ < 0 also flips, λ = 0 squashes the line to the origin (so A is singular).

Special cases

A shear [[1, 1], [0, 1]] has one repeated eigenvalue 1 but only one eigen-line (the x-axis): it is defective. A rotation by 90° turns every real direction, so its eigenvalues are complex, ±i. A symmetric matrix always has real eigenvalues and perpendicular eigenvectors.

Why they matter: decoupling

If A has independent eigenvectors v₁, v₂, write any x = c₁v₁ + c₂v₂. Then Aᵏx = c₁λ₁ᵏv₁ + c₂λ₂ᵏv₂: each mode evolves on its own. The same trick turns coupled vibrations into independent oscillators (week 6) and makes stability a question about the size of each λ.

Explain it another way: intuitive

Stretch a rubber sheet. Most arrows drawn on it change direction, but along the stretch axis they only get longer. Those axes are the eigenvectors.

Explain it another way: technical

A = VΛV⁻¹ when A has n independent eigenvectors (columns of V) and Λ is the diagonal matrix of eigenvalues. Then Aᵏ = VΛᵏV⁻¹.

Explain it another way: applied

In a vibrating structure, each eigenvector of the (mass-normalised) stiffness matrix is a mode shape: a pattern of motion in which every point oscillates at the same frequency.

Try these examples

Example 1

Check that (1, −2) is an eigenvector of A = [[4, 1], [2, 3]].

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Is (1, 1) an eigenvector of [[3, 1], [1, 3]]?

  • Yes, with λ = 4
  • Yes, with λ = 3
  • No

2. Why does a 90° rotation have no real eigenvectors?

  • Its determinant is zero
  • It turns every non-zero vector by 90°, so none stays on its line
  • It is not a linear map

3. A has an eigenvalue 0. What follows?

  • A is the zero matrix
  • A is singular (det A = 0)
  • A is symmetric

4. Find the smaller eigenvalue of the symmetric matrix A = [[0, 2], [2, 3]].

Answer:

5. v is an eigenvector of A with λ = 0.5. What is the length of A⁴v if ‖v‖ = 16?

Answer:

Apply it

Find (by experiment in the eigen-finder, then by algebra) the eigenvectors of [[1, 2], [2, −2]]. Show they are perpendicular and explain why that is guaranteed for this matrix.

Reflect

Describe an eigenvector in one sentence to a friend who has never seen a matrix.

2×2 eigenvalues by hand

Two numbers you can read off a matrix in two seconds, the trace and the determinant, give you its eigenvalues. How?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Most stability and vibration questions in a first engineering design come down to a 2×2 or small block. Doing it by hand, fast and reliably, is a core skill that also lets you sanity-check software.

Goals

Predict

A = [[4, 1], [2, 3]] has trace 7 and determinant 10. Which pair could be its eigenvalues?

  1. 3 and 4
  2. 5 and 2
  3. 7 and 10

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Choose [[4, 1], [2, 3]]. Find both eigen-lines with the slider and read λ. Then press 'Show the eigen-lines' and compare with the characteristic polynomial printed in the readout.

What the interactive shows, in words

The eigen-finder shows a vector and its image under the matrix, reports the turning angle in text, and when revealed prints the characteristic polynomial and the eigenvalues.

Understand

The recipe
  1. Compute tr A and det A. 2. Solve λ² − (tr)λ + det = 0. 3. For each λ, find v from a non-zero row of A − λI. 4. Check A·v = λ·v. Example: [[4, 1], [2, 3]]: λ² − 7λ + 10 = 0, λ = 5, 2. A − 5I = [[−1, 1], [2, −2]] gives v = (1, 1); A − 2I = [[2, 1], [2, 1]] gives v = (1, −2).
Reading the discriminant

Δ = tr² − 4 det. Δ > 0: two distinct real eigenvalues. Δ = 0: a repeated eigenvalue (maybe only one eigen-line). Δ < 0: a complex pair tr/2 ± i√(−Δ)/2. For a system x′ = Ax, the real part tr/2 then sets growth or decay and the imaginary part sets the oscillation frequency.

Triangular and symmetric shortcuts

For a triangular matrix the eigenvalues are the diagonal entries. For a symmetric matrix [[a, b], [b, d]], Δ = (a − d)² + 4b² ≥ 0, so the eigenvalues are always real, and the eigenvectors are perpendicular.

Explain it another way: intuitive

Subtracting λ from the diagonal and asking for a squashed matrix is asking: by how much would I have to 'shift' A so that some direction gets flattened? Those shifts are the eigenvalues.

Explain it another way: technical

The characteristic polynomial p(λ) = det(A − λI) has degree n; its roots (with multiplicity) are the n eigenvalues. Beyond 4×4 there is no general formula, so numerical methods are used.

Explain it another way: mathematical

Cayley–Hamilton: every matrix satisfies its own characteristic polynomial, A² − (tr A)A + (det A)I = 0 for 2×2.

Explain it another way: applied

For a mass–spring–damper written as x′ = Ax, tr A = −c/m and det A = k/m, so a glance tells you damping and stiffness separately.

Derivation: The characteristic polynomial of a 2×2 matrix
  1. A·v = λ·v with v ≠ 0 means (A − λI)·v = 0 has a non-zero solution.

  2. A non-zero solution exists exactly when A − λI is singular: det(A − λI) = 0.

  3. For A = [[a, b], [c, d]]: det [[a − λ, b], [c, d − λ]] = (a − λ)(d − λ) − bc = λ² − (a + d)λ + (ad − bc).

  4. So λ² − (tr A)λ + det A = 0, giving λ = (tr ± √(tr² − 4 det)) / 2, or with m = tr/2 and p = det, λ = m ± √(m² − p).

  5. Comparing with (λ − λ₁)(λ − λ₂) = λ² − (λ₁ + λ₂)λ + λ₁λ₂ shows tr A = λ₁ + λ₂ and det A = λ₁λ₂.

  6. For each λ, solve (A − λI)v = 0: if its first row is (p, q), then v = (q, −p) works (use the other row if the first is zero).

Try these examples

Example 1

Find the eigenvalues of [[0, 1], [−2, −3]].

The worked solution is in the online lesson.

Example 2

Find the eigenvalues of [[1, −2], [2, 1]].

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. A = [[2, 0], [6, -4]]. Find its smaller eigenvalue.

Answer:

2. Find the larger eigenvalue of the symmetric matrix A = [[-3, -3], [-3, 5]].

Answer:

3. A = [[-1, 0], [0, 1]]. Find its larger eigenvalue.

Answer:

4. A 2×2 matrix has tr = 2 and det = 5. Its eigenvalues are…

  • Two distinct real numbers
  • A repeated real number
  • A complex-conjugate pair

5. What is the larger eigenvalue of [[3, 7], [0, −1]]?

Answer:

6. You computed eigenvalues 4 and −1 for [[1, 2], [3, 2]]. Quick check?

  • Sum 3 = tr ✓, product −4 = det ✓
  • Sum 3 ≠ tr, so wrong
  • There is no quick check

Apply it

Write eig2(A) in the Code Lab from the derivation (handle the complex case). Test it on ten random matrices by checking tr = λ₁ + λ₂ and det = λ₁λ₂, and on the real ones by checking A·v = λ·v.

Reflect

Which check (trace, determinant, or A·v = λv) catches the most errors in your own working?

Stability of x[k+1] = A·x[k]

A digital controller updates its state 1000 times a second. One number decides whether that state settles or explodes. Which one?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Sampled controllers, population models, Markov chains and every explicit numerical integrator are iterations x[k+1] = A·x[k]. Eigenvalues tell you, before running anything, whether the iteration settles, oscillates or blows up.

Goals

Predict

A has eigenvalues 0.9 and −1.05. Starting from a generic x[0], what does x[k] do?

  1. Decays to zero
  2. Grows, flipping sign each step
  3. Stays the same size

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Choose the 'stable' and 'unstable' matrices. Step through and watch the unnormalised size ‖Aᵏx₀‖ in the table. Compare with the eigenvalues reported in the readout.

What the interactive shows, in words

The power-iteration diagram plots the normalised iterate on the unit circle and lists, in a table, the eigenvalue estimate and the unnormalised size of A to the power k times x0. The readout states whether the size shrinks (stable) or grows (unstable) and gives the true eigenvalues.

Understand

Modes

Each eigenpair (λ, v) is a mode: start along v and you stay along v, scaled by λ each step. A general start is a mix of modes, and over time the mode with the largest |λ| dominates. That dominance is what power iteration (week 5) exploits.

Continuous versus discrete

For x′ = Ax (continuous time) the test is Re(λ) < 0. For x[k+1] = Ax[k] (discrete) it is |λ| < 1. They are linked: sampling x′ = Ax every h seconds gives a discrete matrix with eigenvalues e^{λh}, and |e^{λh}| < 1 exactly when Re(λ) < 0. Explicit Euler instead gives 1 + hλ, which is why it can go unstable (week 7).

Vibration meaning

Complex eigenvalues of an iteration or ODE mean oscillation. Their imaginary part sets frequency, and their real part (or modulus) sets decay. Lightly damped modes, with eigenvalues close to the stability boundary, ring for a long time and are the ones engineers watch.

Explain it another way: intuitive

Each mode is a ball rolling in its own groove. If any groove tilts outwards (|λ| > 1), that ball rolls away, and the whole system with it.

Explain it another way: technical

x[k+1] = Ax[k] is asymptotically stable iff ρ(A) < 1. For defective A, terms like kλᵏ appear, but they still decay when |λ| < 1.

Explain it another way: mathematical

For a 2×2 real A, the Jury conditions give stability iff |det A| < 1 and |tr A| < 1 + det A.

Explain it another way: applied

A discrete PID loop can be stable at one sample rate and unstable at another, because the closed-loop matrix's eigenvalues move with the sample time.

Derivation: Why the spectral radius decides
  1. Suppose A has independent eigenvectors v₁, v₂. Write x[0] = c₁v₁ + c₂v₂.

  2. Then x[1] = A x[0] = c₁λ₁v₁ + c₂λ₂v₂, and by induction x[k] = c₁λ₁ᵏv₁ + c₂λ₂ᵏv₂.

  3. If every |λᵢ| < 1, every term goes to zero: the iteration is asymptotically stable.

  4. If some |λᵢ| > 1 and its cᵢ ≠ 0, that term grows without bound: unstable.

  5. So stability depends on the spectral radius ρ(A) = max |λᵢ| < 1. Complex λ = re^{iφ} give rotation by φ per step with size rᵏ.

Try these examples

Example 1

Is x[k+1] = [[0.5, 0.4], [0.1, 0.6]]·x[k] stable?

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Eigenvalues 0.5 and 0.99. Stable?

  • Yes, but the 0.99 mode decays slowly
  • No
  • Only if the start is along the 0.5 eigenvector

2. A = [[-11, -8], [16, 13]]. Find its smaller eigenvalue.

Answer:

3. A mode has λ = 0.9. About how many steps until it falls to half its size? (Round to the nearest step.)

Answer:

4. Eigenvalues 0.6 ± 0.9i. Stable?

  • Yes: the real part 0.6 is below 1
  • No: |λ| = √(0.36 + 0.81) ≈ 1.08 > 1
  • Cannot tell without eigenvectors

5. x′ = Ax has eigenvalues −2 and −0.1. Is it stable?

  • Yes: both real parts are negative
  • No: |−2| > 1
  • Only if the sampling is fast

Apply it

Take x′ = [[0, 1], [−4, −0.4]]x (a lightly damped oscillator) and Euler-discretise it: A_h = I + hA. Find the largest h for which ρ(A_h) < 1, and check it in the Code Lab.

Reflect

Which matters more for a robot that must settle quickly: the largest |λ|, or all of them?

Week 5: Numerical linear algebra

This week you will

Conditioning: when small errors become big ones

Your solver is perfect, your sensors are 0.1% accurate, and your answer is 50% wrong. Who is to blame?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Calibration matrices, least-squares fits with similar inputs, and robot poses near singularities can all be ill-conditioned. Knowing κ tells you how many digits of your answer you can trust, regardless of how good the code is.

Goals

Predict

Two equations describe nearly parallel lines. You nudge one line very slightly. What happens to their intersection?

  1. It barely moves
  2. It can slide a long way along the lines
  3. It disappears

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Set ε = 1 and nudge b₂. Then slide ε down to 10⁻⁴. For each, record κ, the relative change in b and the relative change in x. Does the amplification ever exceed κ?

What the interactive shows, in words

The condition explorer draws two lines whose intersection is the solution, plus a dashed nudged line and the new intersection. Sliders set ε and the nudge. Text reports κ, both solutions and the relative changes in b and x.

Understand

A property of the problem

κ(A) ≥ 1 measures how sensitive the solution of Ax = b is to changes in b (and in A). κ ≈ 1 is perfect (rotations, orthogonal matrices); κ = 10⁶ means relative data errors may be magnified up to a million times. It is a property of the problem itself, so no algorithm can beat it.

Determinant is not the test

det(0.01·I) in 10 dimensions is 10⁻²⁰, yet κ = 1: it is perfectly conditioned, just scaled. [[1, 1], [1, 1.0001]] has det 10⁻⁴ and κ ≈ 4×10⁴. Use κ, not det, to judge closeness to singularity.

Problem versus algorithm

Conditioning is about the problem; stability is about the algorithm. Elimination without pivoting on the tiny-pivot example is an unstable algorithm on a well-conditioned problem (κ ≈ 2.6). Pivoting fixes the algorithm. For an ill-conditioned problem, the fix is to change the problem: better sensor placement, rescaling, or more independent measurements.

Explain it another way: intuitive

Locating a point from two compass bearings works well when the bearings cross at a right angle, badly when they are nearly parallel. κ measures how shallow the crossing is.

Explain it another way: technical

σᵢ are the square roots of the eigenvalues of AᵀA. For symmetric positive definite A, κ = λmax/λmin.

Explain it another way: mathematical

For A = [[1, 1], [1, 1 + ε]], κ ≈ 4/ε for small ε.

Explain it another way: applied

In GPS, poor satellite geometry gives a large 'dilution of precision', which is a condition number: the same range errors produce much larger position errors.

Derivation: The error-amplification bound
  1. Exact: Ax = b. Perturbed data: A(x + δx) = b + δb. Subtract: A·δx = δb, so δx = A⁻¹δb.

  2. Take norms: ‖δx‖ ≤ ‖A⁻¹‖·‖δb‖. Also ‖b‖ = ‖Ax‖ ≤ ‖A‖·‖x‖, so 1/‖x‖ ≤ ‖A‖/‖b‖.

  3. Multiply: ‖δx‖/‖x‖ ≤ ‖A‖·‖A⁻¹‖·‖δb‖/‖b‖.

  4. Define κ(A) = ‖A‖·‖A⁻¹‖. In the 2-norm this is σmax/σmin, the ratio of the largest to smallest singular value.

  5. Rule of thumb: you can lose about log₁₀ κ significant digits. With double precision (about 16 digits) and κ = 10¹⁰, expect about 6 good digits.

Try these examples

Example 1

κ(A) = 10⁴ and the measurements in b have 0.01% relative error. What is the worst-case relative error in x?

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. What is κ of the diagonal matrix diag(10, 0.1) in the 2-norm?

Answer:

2. κ = 500, relative error in b is 0.002 (0.2%). What is the worst-case relative error in x?

Answer:

3. Which matrix is closest to singular in the sense that matters numerically?

  • 0.001·I (2×2)
  • [[1, 1], [1, 1.001]]
  • [[2, 0], [0, 3]]

4. Working with about 16 significant digits and κ = 10⁹, roughly how many digits of x can you trust?

Answer:

5. A calibration matrix has κ = 10⁷. What actually helps?

  • Use a more accurate solver
  • Redesign the measurements so the columns are less alike
  • Round the answer to fewer digits

Apply it

Two strain gauges are mounted at angles α and β to a beam's axis to measure two strain components. Write the 2×2 measurement matrix, plot κ against β − α in the Code Lab, and recommend a mounting angle.

Reflect

Name a measurement you rely on whose geometry might make it ill-conditioned.

Power iteration: eigenvalues by repetition

Multiply a random vector by a matrix again and again. Why does it always end up pointing the same way?

About 40 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

For big matrices nobody solves the characteristic polynomial. Iterative methods built on repeated multiplication find the eigenvalues engineers need: the dominant vibration mode, the slowest-decaying mode, the stationary state of a Markov chain.

Goals

Predict

A has eigenvalues 1.0 and 0.9. How quickly will power iteration settle on the dominant eigenvector?

  1. In one or two steps
  2. Slowly: the error shrinks by only about 10% per step
  3. Never

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Step through [[2, 1], [1, 2]] and then the 'close eigenvalues' matrix. Count how many steps each needs before the estimate stops changing in the third digit, and compare with |λ₂/λ₁| in the readout.

What the interactive shows, in words

The power-iteration animator steps a unit vector through repeated multiplication by A, plotting previous iterates as dots and the dominant eigen-line as a band. A table lists the estimate at each step; a step button works without animation, and Play is disabled under reduced motion.

Understand

The algorithm

Start with x₀ (not perpendicular to the dominant eigenvector). Repeat: y = A·xₖ, xₖ₊₁ = y/‖y‖. Estimate λ with the Rayleigh quotient r = xᵀAx / xᵀx. Normalising stops the numbers overflowing or underflowing; it does not change the direction.

Why it works and how fast

Write x₀ = c₁v₁ + c₂v₂ with |λ₁| > |λ₂|. Then Aᵏx₀ = λ₁ᵏ(c₁v₁ + c₂(λ₂/λ₁)ᵏv₂). The v₂ part dies like |λ₂/λ₁|ᵏ. For symmetric A, the Rayleigh quotient error dies even faster, like |λ₂/λ₁|²ᵏ.

Variations

If |λ₁| = |λ₂| (for example eigenvalues 2 and −2, or a complex pair), the direction never settles. Inverse iteration (apply A⁻¹, by solving with LU) finds the smallest eigenvalue; shifted inverse iteration with (A − σI)⁻¹ finds the one nearest σ. Production libraries use the QR algorithm, which is a sophisticated relative.

Explain it another way: intuitive

Shout into a canyon: echoes at every pitch come back, but the canyon's resonant pitch keeps getting reinforced, until it is all you hear.

Explain it another way: technical

Each step costs one matrix–vector product, O(n²) for dense A and O(nnz) for sparse A, which is why it scales to enormous matrices.

Explain it another way: applied

Finding a structure's lowest natural frequency uses inverse iteration on the stiffness and mass matrices, because the lowest mode is usually the most dangerous.

Try these examples

Example 1

One step of power iteration on A = [[2, 1], [1, 2]] from x₀ = (1, 0). Find the new estimate.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Run 3 steps of power iteration on A = [[4, 2], [2, 0]] from x₀ = (1, 0), normalising each time. What is the Rayleigh-quotient estimate xᵀAx / xᵀx of the dominant eigenvalue after step 3?

Answer:

2. Run 1 step of power iteration on A = [[1, 1], [1, 4]] from x₀ = (1, 0), normalising each time. What is the Rayleigh-quotient estimate xᵀAx / xᵀx of the dominant eigenvalue after step 1?

Answer:

3. With |λ₂/λ₁| = 0.5, about how many steps reduce the unwanted component by a factor of 10⁶? (Nearest whole step.)

Answer:

4. Power iteration on [[0, 1], [1, 0]] from (1, 0) does what?

  • Converges to (1, 1)/√2
  • Flips between (1, 0) and (0, 1) for ever
  • Converges to zero

5. To find the smallest-magnitude eigenvalue, you…

  • Run power iteration on A for longer
  • Run power iteration on A⁻¹ (solving with LU each step)
  • Use the trace

Apply it

Implement power and inverse iteration in the Code Lab. Use them on the two-mass stiffness matrix K = [[2, −1], [−1, 2]] to find both natural frequencies (ω² = eigenvalues for unit masses) and compare with the exact values 1 and 3.

Reflect

Why is 'one matrix–vector product per step' such an attractive property for very large problems?

Least squares and the normal equations

Seven measurements, two unknowns, no exact solution. What is the most honest 'best' answer?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Every calibration curve, every fitted model parameter and every estimator in the next term starts here. Least squares is the bridge from linear algebra to data.

Goals

Predict

At the least-squares line, what is the sum of the residuals (not squared)?

  1. Always zero
  2. Always positive
  3. It depends on the data

Write down your guess and your reason. The reveal is in the online lesson.

Discover

On 'Spring calibration', drag your slope and intercept to make Σr² as small as you can. Then reveal the least-squares line. Switch to the outlier set and see how far one bad reading drags the line.

What the interactive shows, in words

The least-squares diagram plots data points, your adjustable line and vertical residual segments. Sliders set slope and intercept; text gives your sum of squared residuals, and a button reveals the optimal line and its sum.

Understand

Over-determined systems

More equations than unknowns, with noise, means no exact solution. Least squares chooses p to minimise ‖y − Ap‖²: the total squared vertical miss. The answer always exists, and it is unique when A's columns are independent (for a line: at least two distinct x values).

Reading residuals

Plot residuals against x. Random scatter around zero suggests the model is adequate. A curve suggests the wrong model (try a quadratic or a transformation). A funnel suggests noise growing with x. One huge residual suggests an outlier, and squaring gives it a lot of influence.

Linear in the parameters

'Linear' least squares means linear in p, not in x. y = a + bx + cx² is still linear least squares (three columns 1, x, x²). Exponential decays can be fitted by taking logs: ln(peak) = ln A₀ − ζω t, a straight line in t. You will use this in week 8.

Explain it another way: intuitive

Imagine springs pulling the line vertically towards each point, with energy proportional to stretch squared. The line settles where the total spring energy is least.

Explain it another way: technical

p̂ = (AᵀA)⁻¹Aᵀy, and the fitted values Ap̂ = Py, where P = A(AᵀA)⁻¹Aᵀ is the projection onto col(A).

Explain it another way: mathematical

Under independent, equal-variance, zero-mean noise, the least-squares estimator is unbiased and has the smallest variance among linear unbiased estimators (Gauss–Markov).

Explain it another way: applied

Calibrating a load cell: hang known masses, record raw counts, fit counts = m·force + c. The slope is the sensitivity and the intercept is the zero offset.

Derivation: Normal equations for a straight line
  1. Model yᵢ ≈ m·xᵢ + c. Stack all points: A·p ≈ y with A = [[x₁, 1], …, [xₙ, 1]] and p = (m, c). With n > 2 points there is usually no exact solution.

  2. Residual vector r = y − A·p. Minimise S(p) = ‖r‖² = Σ (yᵢ − m xᵢ − c)².

  3. ∂S/∂m = −2 Σ xᵢ(yᵢ − m xᵢ − c) = 0 and ∂S/∂c = −2 Σ (yᵢ − m xᵢ − c) = 0.

  4. So m Σxᵢ² + c Σxᵢ = Σxᵢyᵢ and m Σxᵢ + c·n = Σyᵢ. In matrix form: AᵀA·p = Aᵀy.

  5. Solve: m = (nΣxy − ΣxΣy)/(nΣx² − (Σx)²), c = (Σy − mΣx)/n. Geometrically, Aᵀr = 0: the residual is perpendicular to every column of A.

  6. Caution: κ(AᵀA) = κ(A)², so for ill-conditioned fits, libraries solve via QR instead of forming AᵀA.

Try these examples

Example 1

Fit a line to (0, 1), (1, 3), (2, 4), (3, 6).

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Fit y = m·x + c by least squares to the points (0, 1.3), (1, 1.8), (2, 1.8), (3, 2.6), (4, 3.2). What is the slope m?

Answer:

2. Fit y = m·x + c by least squares to the points (0, 0.3), (1, -0.3), (2, -1.2), (3, -2.8). What is the intercept c?

Answer:

3. At the least-squares solution, the residual vector r satisfies…

  • r = 0
  • Aᵀr = 0
  • ‖r‖ = 1

4. Which model can be fitted by linear least squares directly?

  • y = a·sin(ωt) with unknown ω
  • y = a + b·t + c·t²
  • y = a·e^{bt} without taking logs

5. One reading is wildly wrong. What happens to the least-squares line?

  • Nothing: one point cannot matter
  • It is pulled noticeably towards the outlier
  • The fit fails to compute

Apply it

In the Code Lab, generate 20 noisy points from y = 2x + 1, fit them with the normal equations, and repeat 200 times. Plot the histogram of fitted slopes: how wide is it, and how does it change with 80 points?

Reflect

When would you prefer a method less sensitive to outliers than least squares?

Week 6: Ordinary differential equations

This week you will

Linear ODEs you can solve by hand

Tap a wine glass, pluck a guitar string, release a car's suspension: one second-order equation describes them all. What does it predict?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Linear ODEs with constant coefficients are the workhorses of engineering dynamics. Knowing their exact solutions gives you benchmarks to test every numerical integrator you will write.

Goals

Predict

A 1 kg mass on a 4 N/m spring with damping c = 0.8 N·s/m is released. What does it do?

  1. Creeps back without overshooting
  2. Oscillates with slowly shrinking amplitude
  3. Oscillates for ever at constant amplitude

Write down your guess and your reason. The reveal is in the online lesson.

Discover

In 'Mass–spring–damper' mode, set k = 4 and sweep c from 0 to 6. Watch the trajectories change from circles (c = 0) to spirals to straight-in curves. Note the value of c where the eigenvalues become real, and compare with 2√k.

What the interactive shows, in words

The phase-portrait diagram plots velocity against position with direction arrows and six trajectories. Sliders set stiffness and damping; text gives the eigenvalues, the critical damping value and the type of equilibrium (centre, spiral or node).

Understand

First order

dx/dt = −kx has solution x(t) = x₀ e^{−kt}. The time constant τ = 1/k is the time to fall to about 37%. After 5τ it is under 1%. RC circuits, cooling and many sensor lags are first-order.

Second order

m x″ + c x′ + k x = 0 needs two initial conditions (position and velocity). Its behaviour is set by ω_n (how fast it wants to oscillate) and ζ (how strongly it is damped). Engineers often design for ζ around 0.6–0.7: quick, with little overshoot.

Benchmarks for numerics

With c = 0, m = k = 1 and x(0) = 1, x′(0) = 0, the exact solution is x = cos t and the energy ½x′² + ½x² stays at 0.5 for ever. That exact answer is what week 7 uses to measure integrator errors.

Explain it another way: intuitive

Stiffness wants to bring the mass back; inertia makes it overshoot; damping drains energy. ζ is the referee: below 1 the mass swings past, above 1 it creeps home.

Explain it another way: technical

The roots r of the characteristic equation are exactly the eigenvalues of the state matrix A = [[0, 1], [−k/m, −c/m]] (next lesson).

Explain it another way: mathematical

Underdamped log decrement: ln(xₙ/xₙ₊₁) = 2πζ/√(1 − ζ²), a way to measure ζ from successive peaks.

Explain it another way: applied

Car suspensions are tuned to about ζ = 0.2–0.4 for comfort; precision instrument mounts and door closers aim near critical damping.

Derivation: Solving m x″ + c x′ + k x = 0
  1. Try x = e^{rt}. Then x′ = r e^{rt}, x″ = r² e^{rt}, and the equation becomes (m r² + c r + k) e^{rt} = 0.

  2. So r solves the characteristic equation m r² + c r + k = 0: r = (−c ± √(c² − 4mk)) / (2m).

  3. Write ω_n = √(k/m) and ζ = c/(2√(km)). Then r = −ζω_n ± ω_n√(ζ² − 1).

  4. ζ > 1 (overdamped): two negative real roots, x = A e^{r₁t} + B e^{r₂t}. ζ = 1 (critical): x = (A + Bt) e^{−ω_n t}.

  5. ζ < 1 (underdamped): r = −ζω_n ± iω_d with ω_d = ω_n√(1 − ζ²), so x = e^{−ζω_n t}(A cos ω_d t + B sin ω_d t).

  6. A and B come from the initial position and velocity. By linearity, any combination of solutions is a solution (week 1).

Try these examples

Example 1

m = 2 kg, k = 50 N/m, c = 4 N·s/m. Find ω_n, ζ and ω_d.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. A mass–spring–damper has m = 2 kg, k = 8 N/m, c = 4 N·s/m. What is its damping ratio ζ?

Answer:

2. A sensor obeys dx/dt = −4x (t in seconds). What is its time constant?

Answer: s

3. A mass–spring–damper has m = 1 kg, k = 32 N/m, c = 4 N·s/m. What is its damping ratio ζ?

Answer:

4. m = 0.5 kg, k = 200 N/m. What is ω_n in rad/s?

Answer: rad/s

5. For m = 1 kg and k = 9 N/m, what damping gives critical damping?

  • c = 3
  • c = 6
  • c = 9

Apply it

In the Code Lab, plot the exact solutions for ζ = 0.1, 0.7, 1 and 2 with ω_n = 2 rad/s and x(0) = 1, x′(0) = 0. Mark the 2% settling time on each and say which you would choose for a camera gimbal.

Reflect

Where in daily life have you felt an underdamped system ring?

Mass–spring systems in state space

Why do simulators, controllers and estimators all insist on first-order equations, even for a second-order mass on a spring?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

State space is the common language of simulation, control and estimation. Once a model is x′ = Ax (+ Bu), the same eigenvalue tools, the same integrators and, next term, the same Kalman filter apply to it.

Goals

Predict

For x″ + 3x′ + 2x = 0 written as a state-space system, what are the eigenvalues of A?

  1. 3 and 2
  2. −1 and −2
  3. 1 and 2

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Switch to 'Any 2×2 matrix'. Find settings that give each type: stable node, stable spiral, centre, saddle, unstable spiral. For each, record the signs of tr A and det A and of tr² − 4det.

What the interactive shows, in words

In general mode, four sliders set the entries of A. The phase portrait shows direction arrows, trajectories and real eigen-lines; text gives the trace, determinant, discriminant, eigenvalues and the equilibrium type.

Understand

The general recipe

For an nth-order equation, use the output and its first n − 1 derivatives as states. With several masses, use every position and every velocity. With inputs, x′ = Ax + Bu. The state is everything you need to know now to predict the future.

Classifying equilibria

For 2×2 A: det < 0 gives a saddle (one positive and one negative real eigenvalue). det > 0 and tr² > 4det gives a node (two real eigenvalues of the same sign). det > 0 and tr² < 4det gives a spiral (complex pair). tr = 0 with det > 0 gives a centre. Stable if tr < 0 and det > 0.

Eigenvectors in the portrait

For real eigenvalues, the eigenvectors are straight-line trajectories: start on one and you stay on it, moving in or out like e^{λt}. Near a stable node, trajectories arrive along the slower eigenvector, because the faster mode has already died away.

Explain it another way: intuitive

A phase portrait is a weather map for the state: at every point an arrow says where it goes next. Equilibria are calm spots; eigen-lines are the main roads.

Explain it another way: technical

The solution is x(t) = e^{At}x(0), where the matrix exponential equals V e^{Λt} V⁻¹ for diagonalisable A.

Explain it another way: applied

An inverted pendulum (a balancing robot) linearised about upright is a saddle: one unstable mode, which the controller must move into the left half-plane.

Derivation: From x″ to x′ = Ax, and back to the characteristic equation
  1. Start from m x″ + c x′ + k x = 0. Choose states x₁ = x (position) and x₂ = x′ (velocity).

  2. Then x₁′ = x₂ and x₂′ = x″ = −(k/m)x₁ − (c/m)x₂.

  3. In matrix form: (x₁, x₂)′ = [[0, 1], [−k/m, −c/m]]·(x₁, x₂). Call the matrix A.

  4. det(A − λI) = (−λ)(−c/m − λ) + k/m = λ² + (c/m)λ + k/m. Multiplying by m gives m λ² + c λ + k: the characteristic equation.

  5. So tr A = −c/m (damping) and det A = k/m (stiffness), and the eigenvalues of A are the roots r. Solutions are x(t) = Σ cᵢ e^{λᵢt} vᵢ.

Try these examples

Example 1

Classify x′ = [[1, 2], [3, 0]]x.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. For m x″ + c x′ + k x = F(t), which state vector works?

  • (x, F)
  • (x, x′)
  • (x′, x″)

2. tr A = −1, det A = 2. The origin is a…

  • Stable node
  • Stable spiral
  • Saddle

3. A = [[-1, 0], [0, 1]]. Find its larger eigenvalue.

Answer:

4. In state space, m = 2 kg and c = 3 N·s/m. What is tr A?

Answer:

5. A linearised model has a saddle at its equilibrium. Practically, this means…

  • It is stable
  • Almost every small disturbance grows: unstable
  • It oscillates for ever

Apply it

Write the state-space model of two masses joined by springs (four states). Use eig in the Code Lab to find its eigenvalues with and without damping, and explain why the undamped ones are purely imaginary.

Reflect

Which do you find more informative for a 2×2 system: the formula, or the phase portrait?

Module check: modal analysis of two masses

Push one of two connected masses and the motion wanders back and forth between them. What hidden simple motions are adding up?

About 55 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

This module check joins eigenvalues (week 4) with ODEs (week 6). Modal analysis is how engineers keep machines, buildings and vehicles away from resonance, and it is the core of the term project.

Goals

Predict

Two equal masses, equal outer springs, and a weak spring between them. You push only the left mass. What happens?

  1. Only the left mass moves
  2. The motion slowly transfers to the right mass and back
  3. Both masses immediately move identically

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Show Mode 1 and Mode 2 and describe each shape. Then choose 'Push mass 1 only', set the coupling spring to about 0.1 and step time forward. Measure the time for the motion to move fully to mass 2 and compare with half the beat period in the readout.

What the interactive shows, in words

The two-mass diagram draws a wall, spring, mass, spring, mass, spring, wall, with mass positions set by the time slider. Chips choose mode 1, mode 2 or 'push mass 1 only'. Text gives both natural frequencies, the mode shapes and, for the push case, the beat period. Play is disabled under reduced motion; a step button advances time.

Understand

Question → method → evidence

Question: what are the natural motions of the chain? Method: build M and K, solve the 2×2 eigenproblem, interpret. Evidence: animate each mode; check K v = ω² M v by substitution; compare the predicted beat period with what the diagram shows.

Mode shapes

In the low mode the masses move together and the middle spring barely works, so the frequency is low. In the high mode they move in opposition, stretching the middle spring twice as much, so it is stiffer and faster. Unequal masses tilt the shapes: the lighter mass moves more in the higher mode.

Why engineers care

A structure driven at a natural frequency resonates. Modal analysis tells designers where those frequencies are and which parts move most, so they can stiffen, add mass, add damping or move the operating speed away. Mode shapes also show where to place sensors (at large motions) and where not to (at nodes).

Explain it another way: intuitive

Modes are the 'pure notes' of a structure. Any vibration is a chord made from them.

Explain it another way: technical

For symmetric positive definite M and K, eigenvalues ω² are real and positive and the mode shapes are M-orthogonal: v₁ᵀMv₂ = 0. This is what lets modal coordinates decouple the equations.

Explain it another way: applied

Footbridges are checked so that no vertical mode sits near walking pace (roughly 1.5–2.5 Hz). When a mode does, tuned mass dampers can be added.

Derivation: From Newton's law to an eigenproblem
  1. Chain: wall–k₁–m₁–k₂–m₂–k₃–wall, displacements x₁, x₂ from equilibrium.

  2. Newton for each mass: m₁x₁″ = −k₁x₁ + k₂(x₂ − x₁), m₂x₂″ = −k₂(x₂ − x₁) − k₃x₂.

  3. Matrix form: M x″ + K x = 0 with M = diag(m₁, m₂) and K = [[k₁ + k₂, −k₂], [−k₂, k₂ + k₃]].

  4. Try a synchronous motion x = v cos(ωt). Then −ω²Mv + Kv = 0, i.e. K v = ω² M v, or (M⁻¹K) v = ω² v.

  5. For m₁ = m₂ = m, k₁ = k₃ = k, k₂ = k_c: v = (1, 1) gives ω₁² = k/m; v = (1, −1) gives ω₂² = (k + 2k_c)/m.

  6. Free motion: x(t) = a₁v₁cos(ω₁t + φ₁) + a₂v₂cos(ω₂t + φ₂). Pushing mass 1 alone excites both modes equally, giving beats.

Try these examples

Example 1

m = 1 kg, k = 1 N/m, k_c = 1 N/m. Find both natural frequencies.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Two equal masses m = 2 kg sit between walls: wall–k–m–k_c–m–k–wall with k = 2 N/m and coupling k_c = 4 N/m. What is the lower natural frequency ω, in rad/s?

Answer: rad/s

2. Two equal masses m = 0.5 kg sit between walls: wall–k–m–k_c–m–k–wall with k = 16 N/m and coupling k_c = 1 N/m. What is the higher natural frequency ω, in rad/s?

Answer: rad/s

3. In the higher-frequency mode of two equal masses, the masses…

  • Move together
  • Move in opposition
  • Do not move

4. ω₁ = 1.00 rad/s and ω₂ = 1.10 rad/s. What is the beat period 2π/(ω₂ − ω₁) in seconds?

Answer: s

5. Find the smaller eigenvalue of the symmetric matrix A = [[5, -4], [-4, 0]].

Answer:

6. A motor runs at 9.5 rad/s. The structure's modes are at 3 and 10 rad/s. What is the concern?

  • None: 9.5 is not exactly 10
  • Near-resonance with the 10 rad/s mode, especially if lightly damped
  • The 3 rad/s mode, because it is lower

Apply it

Choose m₂ = 2 kg in the diagram. Predict by hand (solve the 2×2 eigenproblem) the two frequencies and shapes, then check them against the readout. Write three sentences on how the shapes changed and why.

Reflect

What did this module check need from week 4 that you had to revisit?

Week 7: Numerical integration

This week you will

Euler, semi-implicit Euler and RK4

Simulate a frictionless spring with Euler's method and it gains energy from nowhere. Is the physics wrong, or the arithmetic?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Every simulator you will use, from game physics to spacecraft trajectory tools, rests on a time-stepping method. Choosing one badly gives plausible-looking, wrong answers. The undamped oscillator is the classic test because we know the exact answer.

Goals

Predict

Simulate x″ = −x for one full period with explicit Euler and h = 0.1. The true energy is 0.5. Roughly what does Euler report?

  1. About 0.5
  2. About 0.94
  3. About 0.05

Write down your guess and your reason. The reveal is in the online lesson.

Discover

In 'Oscillator energy', set h = 0.2 and run 10 periods. Which curve drifts up, which stays bounded, which slowly sinks? Halve h and see which drift shrinks fastest.

What the interactive shows, in words

The integrator diagram plots energy against time for explicit Euler, semi-implicit Euler (dashed) and RK4, with the exact energy 0.5 as a dashed line. Text lists each method's final energy and the Euler growth factor per step.

Understand

The three methods

For y′ = f(t, y):

Accuracy versus structure

RK4 is far more accurate per step: with h = 0.1 over t = 10 its position error is about 4×10⁻⁶, against about 0.6 for explicit Euler. But RK4 still slowly loses energy (with h = 0.2 over 10 periods, about 0.4998 instead of 0.5). Semi-implicit Euler is only first-order accurate, yet its energy never drifts away. For long orbital or molecular simulations, that structure can matter more than raw accuracy.

Cost

Count function evaluations, the expensive part for real models. RK4 costs four per step, Euler one. RK4 with step 4h therefore costs the same as Euler with step h, and is still usually far more accurate.

Explain it another way: intuitive

Euler is driving by looking only at the road directly under the car. RK4 glances ahead three times and averages. Semi-implicit Euler drives sloppily but never leaves the circuit.

Explain it another way: technical

Explicit Euler on the oscillator has amplification matrix [[1, h], [−h, 1]] with |λ| = √(1 + h²) > 1. Semi-implicit Euler's matrix has determinant exactly 1 (area-preserving).

Explain it another way: mathematical

RK4's update matches the Taylor series of the exact solution up to the h⁴ term, so its local error is O(h⁵).

Explain it another way: applied

Many game and robotics physics engines use semi-implicit Euler because it is cheap and stays bounded for springs and contacts.

Derivation: Why explicit Euler gains energy on the oscillator
  1. Write x″ = −x as x′ = v, v′ = −x. Energy E = ½(x² + v²) is exactly conserved by the true solution.

  2. Explicit Euler: xₙ₊₁ = xₙ + h vₙ, vₙ₊₁ = vₙ − h xₙ.

  3. Then xₙ₊₁² + vₙ₊₁² = xₙ² + 2h xₙvₙ + h²vₙ² + vₙ² − 2h xₙvₙ + h²xₙ² = (1 + h²)(xₙ² + vₙ²).

  4. So Eₙ = (1 + h²)ⁿ E₀: exponential growth for any h > 0. Over a fixed time T = nh, Eₙ ≈ E₀ e^{hT}, which tends to E₀ only as h → 0.

  5. Semi-implicit Euler updates v first and uses the new v for x. It conserves a slightly modified energy exactly, so its energy error stays bounded for all time (it is symplectic).

Try these examples

Example 1

One explicit Euler step for x′ = v, v′ = −x from (1, 0) with h = 0.1.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. For dy/dt = -0.5y + 2 with y(0) = 1, take one explicit Euler step of size h = 0.2. What is y₁?

Answer:

2. For dy/dt = -2y with y(0) = 3, take one classical RK4 step with h = 0.1. What is y₁? (4 decimal places.)

Answer:

3. Explicit Euler on x″ = −x with h = 0.05: by what factor does the energy grow per step?

Answer:

4. Why might a long satellite-orbit simulation use a symplectic method instead of RK4?

  • It is more accurate per step
  • Its energy error stays bounded over very long times
  • It needs no step size

5. For dy/dt = 0.5y + 1 with y(0) = 2, take one explicit Euler step of size h = 0.05. What is y₁?

Answer:

6. With the same number of function evaluations, which is usually more accurate on smooth problems?

  • Euler with step h
  • RK4 with step 4h
  • They are always equal

Apply it

Implement all three methods in the Code Lab with a common interface step(f, t, y, h). Reproduce the energy plot from the diagram for h = 0.1 over 20 periods and add the error in x(t) against cos t.

Reflect

In a project you care about, which matters more: accuracy at one moment or behaviour over a long time?

Local and global error, and the convergence study

Halve the step and RK4's error drops about sixteen times. How can you prove that from your own code, not from a textbook?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

A convergence study is the single most useful test of simulation code. If the observed order matches theory, the method is probably implemented correctly; if not, there is a bug. It is also how you justify the step size in a report.

Goals

Predict

A method has global error order 2. You halve h. What happens to the error at the final time?

  1. Halves
  2. Falls to about a quarter
  3. Falls to about an eighth

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Read the convergence table below the energy plot. For each method, divide the h error by the h/2 error and the h/2 error by the h/4 error. Change h and see which ratios settle near 2 and which near 16.

What the interactive shows, in words

Below the energy plot, a table lists for each method the error in x at t = 10 for steps h, h/2 and h/4, and the observed order computed from the last two. Changing h updates the table.

Understand

Question → method → evidence

Question: is my integrator correct, and is my step size small enough? Method: solve a problem with a known answer at h, h/2, h/4 (and smaller), measure the error at a fixed time, compute ratios. Evidence: ratios close to 2ᵖ confirm the order; a final error below your tolerance justifies the step.

When there is no exact answer

Use the finest run as a reference, or use differences between successive runs: E(h) ≈ |y_h − y_{h/2}|·2ᵖ/(2ᵖ − 1). Richardson extrapolation combines two runs, (2ᵖ y_{h/2} − y_h)/(2ᵖ − 1), to cancel the leading error term.

Limits of the study

Very small h eventually hits round-off error, which grows as steps multiply, so the error curve flattens or turns up. Very large h may be outside the asymptotic range or even unstable. Report the range of h where the ratio is steady, and plot error against h on log–log axes: the slope is the order.

Explain it another way: intuitive

Like checking a map's scale: if doubling the zoom always doubles the detail, the map is behaving. If RK4 does not give about 16× better results at half the step, something in the code is off.

Explain it another way: technical

A common bug is evaluating k₂ or k₃ at the wrong time or state; it usually drops the observed order of RK4 to 1 or 2, which a convergence study catches at once.

Explain it another way: applied

Verification standards for engineering simulation ask for exactly this kind of grid- or step-refinement study before results are used.

Derivation: Evidence for RK4's fourth order
  1. Local error: if a method matches the exact Taylor series through the hᵖ term, one step from exact data is off by about C hᵖ⁺¹.

  2. Global error: reaching a fixed time T takes N = T/h steps. Roughly adding the local errors gives N·C hᵖ⁺¹ = C T hᵖ, so global order is p.

  3. Euler matches up to h¹ (p = 1). RK4 matches up to h⁴ (p = 4): its local error is O(h⁵), global O(h⁴).

  4. Test: with E(h) ≈ C hᵖ, E(h)/E(h/2) ≈ 2ᵖ, so p ≈ log₂(E(h)/E(h/2)).

  5. Evidence from this term's code (x″ = −x, x(0) = 1, error in x at t = 10): RK4 with 100, 200, 400 steps gives errors about 3.9×10⁻⁶, 2.6×10⁻⁷, 1.7×10⁻⁸. Ratios 14.9 and 15.5 give p ≈ 3.9 and 3.95, approaching 4.

  6. Explicit Euler on the same test gives 0.57, 0.24, 0.11: ratios 2.3 and 2.2, approaching 2¹ = 2 as h shrinks. The pre-asymptotic ratios are a reminder to test at small enough h.

Try these examples

Example 1

Errors at t = 5 are 2.0×10⁻³ (h = 0.1) and 2.6×10⁻⁴ (h = 0.05). What is the observed order?

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. With step h, the midpoint method (global order 2) gives a global error of 0.0032. Predict the error with step h/2.

Answer:

2. Explicit Euler has global error order 1. By what factor should the global error shrink when h is reduced to h/4?

Answer:

3. E(h) = 0.032 and E(h/2) = 0.0021. What is the observed order p = log₂(E(h)/E(h/2))? (2 d.p.)

Answer:

4. A method's local error is O(h³). Its global error is…

  • O(h³)
  • O(h²)
  • O(h⁴)

5. Your 'RK4' shows observed order 1.0 on a smooth test. Most likely?

  • RK4 is first order
  • A bug in the stages, e.g. a wrong time or state in k₂–k₄
  • The step is too small

Apply it

In the Code Lab, run a convergence study for your three integrators on x″ = −x up to t = 10 with h from 0.4 down to 0.0125. Plot log error against log h, fit a line by least squares (week 5) and report the slopes with the range you used.

Reflect

How would you convince a sceptical reviewer that your simulation's step size is small enough?

Stability regions and stiffness

The fast part of your model died out in a millisecond, yet your simulation still crawls along in microsecond steps. Why?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Circuits with tiny parasitic capacitances, chemical reactions, thermal models with thin layers: real models often mix very fast and very slow dynamics. Explicit methods then need tiny steps for stability, not accuracy, and become absurdly slow.

Goals

Predict

Explicit Euler on y′ = −1000y with h = 0.003. The exact solution decays to zero almost instantly. What does Euler do?

  1. Decays smoothly
  2. Blows up, alternating in sign
  3. Stays constant

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Switch to 'Stiffness test y′ = λy'. Slide z = hλ from −0.5 towards −3.5. Note where Euler starts oscillating, where it blows up, and where RK4 finally fails too.

What the interactive shows, in words

In stiffness mode the diagram plots twenty steps of the numerical solution of y′ = λy for Euler and RK4 at a chosen z = hλ. Text gives each method's amplification factor and says when Euler blows up although the exact solution decays.

Understand

Stability regions

For a system x′ = Ax, each eigenvalue λ of A gives a test equation. An explicit method is stable only if hλ lies inside its stability region for every eigenvalue. So the fastest-decaying mode (largest |λ|) sets the maximum step, even if that mode is physically irrelevant after a moment.

What stiffness means

A problem is stiff when it has decaying modes on very different time scales, and you want to follow the slow one. Example: eigenvalues −1 and −1000. Accuracy for the slow mode would allow h ≈ 0.1, but explicit Euler stability needs h ≤ 0.002: fifty times more steps, purely to avoid blowing up.

The remedy

Implicit methods (backward Euler, the trapezoidal rule, BDF methods) solve an equation each step, often a linear system with (I − hA) via LU from week 2, but stay stable with large steps. Library solvers flagged for stiff problems (such as 'BDF' or 'Radau' options) do this automatically.

Explain it another way: intuitive

A stiff problem is a convoy with a hyperactive scout and a slow lorry. Explicit methods must pace themselves to the scout, long after the scout has stopped.

Explain it another way: technical

Stiffness ratio = max|Re λ| / min|Re λ| over the decaying modes. Ratios of 10³ to 10⁶ are common in circuit and chemistry models.

Explain it another way: applied

A power-electronics simulation with a 1 µs switching transient and a 1 s thermal response is stiff; stiff solvers are the default in circuit simulators for this reason.

Derivation: Amplification factors and stability limits
  1. Test equation: y′ = λy, exact yₙ₊₁ = e^{hλ}yₙ. Let z = hλ.

  2. Explicit Euler: yₙ₊₁ = yₙ + hλyₙ = (1 + z)yₙ, so R(z) = 1 + z.

  3. Stable (no growth) iff |1 + z| ≤ 1. For real λ < 0: −2 ≤ z ≤ 0, so h ≤ 2/|λ|.

  4. RK4 on the test equation gives R(z) = 1 + z + z²/2 + z³/6 + z⁴/24 (the Taylor series of e^z to z⁴). On the negative real axis |R| ≤ 1 for z ≥ about −2.79.

  5. Implicit (backward) Euler: yₙ₊₁ = yₙ + hλyₙ₊₁, so R(z) = 1/(1 − z), with |R| < 1 for every z < 0: stable for any step on decaying problems.

Try these examples

Example 1

x′ = Ax with eigenvalues −2 and −500. Largest stable explicit Euler step?

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Explicit Euler is applied to dy/dt = −50y. What is the largest step h for which the numerical solution does not grow (|1 + hλ| ≤ 1)?

Answer: s

2. Explicit Euler is applied to dy/dt = −5y. What is the largest step h for which the numerical solution does not grow (|1 + hλ| ≤ 1)?

Answer: s

3. Euler on y′ = −50y with h = 0.05. What is R = 1 + hλ?

Answer:

4. Which system is stiff (if we care about the slow behaviour)?

  • Eigenvalues −1 and −2
  • Eigenvalues −0.1 and −10⁴
  • Eigenvalues ±i

5. Why can backward Euler take large steps on y′ = −1000y?

  • It is fourth order
  • R(z) = 1/(1 − z) has |R| < 1 for all z < 0
  • It skips the fast mode

6. For dy/dt = 1y with y(0) = 2, take one classical RK4 step with h = 0.5. What is y₁? (4 decimal places.)

Answer:

Apply it

Simulate y′ = −1000(y − cos t), y(0) = 0, to t = 2 with explicit Euler (h = 0.0019 and 0.0021) and backward Euler (h = 0.05; solve the linear update by hand). Plot all three and explain the difference in one paragraph.

Reflect

How would you notice stiffness in a simulation if nobody told you the eigenvalues?

Week 8: Mathematical modeling

This week you will

Models from first principles, and non-dimensionalising

A door closer, a car suspension and a seismometer have different masses, springs and dampers. Why do they share one curve?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Good models are built deliberately: forces drawn, assumptions written, units checked. Non-dimensionalising then tells you which parameters actually matter, so a study of three parameters collapses into a study of one.

Goals

Predict

m x″ + c x′ + k x = 0 has three parameters. After scaling time by ω_n and position by the initial displacement, how many parameters are left?

  1. Three
  2. One (the damping ratio ζ)
  3. None

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Open the Code Lab. Simulate three mass–spring–dampers with different m, c, k but the same ζ = 0.3 (for example m = 1, k = 4, c = 1.2 and m = 2, k = 50, c = 6). Plot x against ω_n·t: do the curves collapse onto one?

What the interactive shows, in words

The activity is code-based: simulate several mass–spring–dampers with the same damping ratio and plot them against scaled time ω_n·t; the curves should overlap, showing ζ is the only governing parameter.

Understand

A modelling checklist
  1. Purpose: what question must the model answer? 2. System boundary and states. 3. Laws: Newton, Kirchhoff, conservation. 4. Constitutive relations: Hooke's law, linear damping, Ohm's law. 5. Assumptions, written down (small angles, no friction, rigid links). 6. Parameters and units. 7. Checks before trusting it.
Checks before simulating

Units: every term in an equation must have the same units. Limiting cases: c = 0 should conserve energy; k = 0 should give no oscillation; very large c should creep. Conservation: with no damping or input, does energy stay constant? Signs: does a spring pull back, not push away?

Why dimensionless groups help

They reduce the number of experiments or simulations needed, reveal which effects dominate (a tiny group can often be neglected), and let you compare systems of very different sizes. Engineers use them everywhere: Reynolds number in fluids, the damping ratio here, the Biot number in heat transfer.

Explain it another way: intuitive

Measuring time in 'natural oscillation units' and distance in 'starting displacements' strips away size and speed, leaving only the character of the system.

Explain it another way: technical

Buckingham π theorem: a relation among n variables with k independent dimensions can be rewritten in n − k dimensionless groups.

Explain it another way: applied

Scale models in wind tunnels and wave tanks work because they match the relevant dimensionless groups, not the real sizes.

Derivation: Non-dimensionalising the damped oscillator
  1. Start: m d²x/dt² + c dx/dt + k x = 0, with x(0) = X₀, x′(0) = 0.

  2. Introduce dimensionless variables: ξ = x/X₀ and τ = ω_n t with ω_n = √(k/m). Then d/dt = ω_n d/dτ.

  3. Substitute: m ω_n² X₀ ξ″ + c ω_n X₀ ξ′ + k X₀ ξ = 0, where primes are now d/dτ.

  4. Divide by k X₀ (and use m ω_n² = k): ξ″ + (c ω_n / k) ξ′ + ξ = 0.

  5. c ω_n / k = c / √(km) = 2ζ. So ξ″ + 2ζ ξ′ + ξ = 0 with ξ(0) = 1, ξ′(0) = 0: one parameter, ζ.

Try these examples

Example 1

Check the units of c ω_n / k.

The worked solution is in the online lesson.

Example 2

A pendulum: m L θ″ = −m g sin θ − b L θ′. State two assumptions in this model.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. A mass–spring–damper has m = 2 kg, k = 8 N/m, c = 4 N·s/m. What is its damping ratio ζ?

Answer:

2. Which equation is dimensionally consistent (x in m, t in s, k in N/m, m in kg)?

  • m x″ + k x = 0
  • m x″ + k x′ = 0
  • x″ + k x = 0

3. Your damped oscillator code with c = 0 shows energy slowly falling. What should you suspect first?

  • The physics: springs lose energy
  • The integrator or a sign/term error, since c = 0 must conserve energy
  • Nothing: that is expected

4. A model has 6 variables involving 3 independent dimensions (mass, length, time). How many dimensionless groups?

Answer:

5. Two equal masses m = 4 kg sit between walls: wall–k–m–k_c–m–k–wall with k = 4 N/m and coupling k_c = 1 N/m. What is the lower natural frequency ω, in rad/s?

Answer: rad/s

Apply it

Model a door closer as a mass–spring–damper. Write the assumptions, estimate m, k and c from a real door (with stated guesses), compute ζ, and say whether the door would slam, creep or ring.

Reflect

Which assumption in your door model would you test first, and how?

Fitting and validating a model against data

A recorded decay gives you seven peaks. How do you get the damping out of them, and how do you know the model deserved to be fitted?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

A model's parameters are rarely known in advance. Engineers measure, fit, and then test the fit on fresh data. This is the honest loop between theory and reality, and the skills carry straight into estimation next term.

Goals

Predict

Peak amplitudes of a decaying oscillation are plotted as ln(peak) against time. If the model with linear damping is right, what shape do you expect?

  1. A straight line with negative slope
  2. A parabola
  3. A horizontal line

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Choose 'Damped decay, ln(amplitude)'. Fit a line by hand, then reveal the least-squares line. Read the slope: that is −ζω_n. Look at the residuals: are they random?

What the interactive shows, in words

The least-squares diagram with the damped-decay data set plots ln(peak amplitude) against time, with your line, residual segments and, on request, the best-fit line. Text reports slopes, intercepts and sums of squared residuals.

Understand

Question → method → evidence

Question: what is the damping, and does linear damping describe this system? Method: extract peaks, fit ln(peak) against t, then predict a second recording. Evidence: the fitted slope with its uncertainty, residual plot, and prediction error on the held-out recording.

A worked fit

For the diagram's decay data (peaks at t = 0…6 s), least squares gives slope −0.304 per second and intercept 0.012. So ζω_n ≈ 0.30 s⁻¹ and A₀ ≈ e^{0.012} ≈ 1.01. If the peak spacing gives ω_d = 2.0 rad/s, then ω_n ≈ 2.02 rad/s and ζ ≈ 0.15.

Validation, not just fitting

A model can always be fitted to the data it was fitted to. Validation uses different data: a second run, another amplitude, a different day. Report the prediction error there. Patterned residuals (for example a curve in ln(peak)) suggest a wrong assumption, such as friction that does not scale with speed.

Explain it another way: intuitive

Fitting is tailoring a suit to someone; validation is checking it still fits when they walk around.

Explain it another way: technical

Prediction error on held-out data estimates how the model generalises; error on the fitting data is optimistically biased.

Explain it another way: applied

Vehicle engineers fit damper models on a test rig, then validate against road-test recordings before using the model in ride simulations.

Derivation: Turning a decay into a straight-line fit
  1. Underdamped solution: x(t) = A₀ e^{−ζω_n t} cos(ω_d t + φ). Peaks occur about every 2π/ω_d with heights Aₖ ≈ A₀ e^{−ζω_n tₖ}.

  2. Take logs: ln Aₖ = ln A₀ − (ζω_n) tₖ. This is linear in the unknowns (ln A₀, ζω_n).

  3. Fit yₖ = ln Aₖ against tₖ by least squares (week 5): slope m = −ζω_n, intercept c = ln A₀.

  4. With ω_d measured from the peak spacing, ω_n = √(ω_d² + (ζω_n)²), so ζ = (ζω_n)/ω_n.

  5. Caution: taking logs changes the noise. Small peaks have large relative noise, so ln weights them oddly; with good data this is a small effect, but it should be stated.

Try these examples

Example 1

Peaks: 1.00, 0.74, 0.55, 0.41 at t = 0, 1, 2, 3 s. Estimate ζω_n.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Fit y = m·x + c by least squares to the points (0, 1.3), (1, 1.8), (2, 1.8), (3, 2.6), (4, 3.2). What is the slope m?

Answer:

2. A ln(peak) fit gives slope −0.5 s⁻¹ and ω_n = 10 rad/s. What is ζ?

Answer:

3. Which is the best evidence that your fitted model is useful?

  • Tiny residuals on the fitting data
  • Small prediction error on a separate recording
  • A very complicated model

4. ln(peak) residuals curve upwards at late times. A plausible explanation?

  • Perfect linear damping
  • Damping that is not proportional to speed (for example dry friction or amplitude-dependent losses)
  • Random noise only

5. Fit y = m·x + c by least squares to the points (0, 0.1), (1, 2), (2, 4), (3, 6), (4, 7.8), (5, 9.7). What is the slope m?

Answer:

Apply it

Record (or simulate with added noise) two decays of the same oscillator. Fit ζω_n on the first, predict the peaks of the second, and report the root-mean-square prediction error and what it suggests.

Reflect

When have you seen a model fitted and never validated?

Linearising nonlinear models

A pendulum hanging down is stable; balanced upright it falls. One Jacobian matrix explains both. How?

About 45 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Most real systems are nonlinear, yet almost all controller design and much analysis uses linear models. Linearisation is the bridge, and knowing when it breaks is part of honest modelling.

Goals

Predict

A damped pendulum is linearised about the upright position. What type of equilibrium do you expect?

  1. Stable spiral
  2. Saddle
  3. Centre

Write down your guess and your reason. The reveal is in the online lesson.

Discover

In 'Any 2×2 matrix' mode, enter the hanging-down linearisation [[0, 1], [−4, −0.5]], then the upright one [[0, 1], [4, −0.5]] (g/L = 4, b = 0.5). Compare the portraits and the classification.

What the interactive shows, in words

In general mode the phase portrait is set to the pendulum's linearised matrices. Text reports trace, determinant, eigenvalues and the equilibrium type: stable spiral for hanging, saddle for upright.

Understand

The method
  1. Find equilibria by solving f(x*) = 0. 2. Compute the Jacobian J = ∂f/∂x. 3. Evaluate it at each equilibrium. 4. Classify with the eigenvalues (week 6). If no eigenvalue has zero real part, the nonlinear system behaves like its linearisation close to that point (the Hartman–Grobman theorem).
Validity

The linear model is accurate only for small deviations. For the pendulum, sin θ ≈ θ is within 1% for |θ| below about 14°. A centre in the linearisation (zero real parts) is inconclusive: the nonlinear terms decide. Always state the range over which you trust the linear model.

Why controllers love it

Linearise a balancing robot about upright, design a controller that moves the saddle's unstable eigenvalue into the left half-plane, then test the controller on the full nonlinear model to see how big a push it survives.

Explain it another way: intuitive

Zoom in on a curved landscape: near the bottom of a valley it looks like a bowl, near the top of a hill like an upturned bowl. Linearisation is that zoomed-in shape.

Explain it another way: technical

Hartman–Grobman: near a hyperbolic equilibrium (no eigenvalues with zero real part), the nonlinear flow is topologically equivalent to its linearisation.

Explain it another way: applied

Aircraft flight dynamics are linearised about trimmed flight; the eigenvalues give the classic modes (phugoid, short period, Dutch roll).

Derivation: Linearising the pendulum
  1. States θ and ω = θ′: θ′ = ω, ω′ = −(g/L) sin θ − bω. This is x′ = f(x), nonlinear because of sin θ.

  2. Equilibria: f = 0 needs ω = 0 and sin θ = 0, so θ = 0 (hanging) or θ = π (upright).

  3. Near an equilibrium x, write x = x + δ. Taylor: δ′ ≈ J(x*)·δ with J the Jacobian, Jᵢⱼ = ∂fᵢ/∂xⱼ.

  4. Here J = [[0, 1], [−(g/L) cos θ, −b]].

  5. θ = 0: J = [[0, 1], [−g/L, −b]], tr = −b < 0, det = g/L > 0: a stable spiral (for small b). θ = π: J = [[0, 1], [g/L, −b]], det = −g/L < 0: a saddle, unstable.

Try these examples

Example 1

Find and classify the equilibria of x′ = y, y′ = x − x³.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Hanging pendulum, linearised: J = [[0, 1], [−9, −0.6]]. Classify.

  • Stable spiral
  • Saddle
  • Unstable node

2. A = [[-11, -8], [16, 13]]. Find its smaller eigenvalue.

Answer:

3. Upright pendulum, undamped, g/L = 9 s⁻². What is the positive eigenvalue of J = [[0, 1], [9, 0]]?

Answer:

4. For which angle is sin θ ≈ θ least trustworthy?

  • 5°
  • 10°
  • 45°

5. Linearisation gives a centre. What can you conclude about the nonlinear system?

  • It definitely oscillates for ever
  • Nothing definite: nonlinear terms decide
  • It is unstable

Apply it

Simulate the full nonlinear pendulum (RK4) and its linearisation from θ₀ = 5°, 30° and 90°. Plot both and report the angle at which the period error exceeds 5%.

Reflect

Which system in your own projects is usually treated as linear, and what range justifies it?

Week 9: Computational modeling investigation

This week you will

Designing a modal and numerical investigation

You have a two-mass model, two integrators and a week. What exactly will you claim at the end, and what evidence would change your mind?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

The term project is a small research investigation: model a two-degree-of-freedom oscillator, find its modes analytically, simulate it with two integrators, and decide with evidence which integrator to trust. Planning first keeps the study honest.

Goals

Predict

Which question is the best fit for this project?

  1. Is RK4 good?
  2. For the two-mass system with ζ = 0, does RK4 or semi-implicit Euler keep the beat period within 1% of the modal prediction for longer at h = 0.1 s?
  3. What is the best integrator in the world?

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Pick the parameters you will study (for example m₂ = 1, coupling 0.2). Record ω₁, ω₂, the mode shapes and the beat period from the readout. These analytic values are the baseline your simulations must match.

What the interactive shows, in words

The two-mass diagram gives, in text, both natural frequencies, the mode shapes and the beat period for chosen masses and coupling stiffness. These numbers form the analytic baseline for the project plan.

Understand

Question → method → evidence

Question: specific and measurable. Method: state-space model (4 states), analytic modes via K v = ω² M v, simulation with two integrators at several steps. Evidence: frequency or beat-period error against the analytic value, energy drift over a fixed time, observed convergence order.

Pre-commit

Before running anything, write down: parameters (m₁, m₂, k₁, k₂, k₃, initial state), metrics (for example relative error in beat period at t = 200 s, energy drift), step sizes, the decision rule ('we prefer the method with lower energy drift at equal cost, provided its frequency error is below 1%'), and what result would surprise you.

Assumptions to state

Linear springs, point masses, no damping (or a stated small damping), motion along one line, exact parameter values. Simplified educational model: real structures have distributed mass, damping and nonlinear joints, so results describe this model, not a particular machine.

Explain it another way: intuitive

Decide where the goalposts are before kicking the ball.

Explain it another way: technical

The analytic modal solution provides an exact reference, which turns the numerical study into verification: measuring discretisation error rather than guessing it.

Explain it another way: applied

Engineering simulation reports routinely include a verification section like this before any design result is quoted.

Try these examples

Example 1

Draft a decision rule for comparing semi-implicit Euler and RK4.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Two equal masses m = 2 kg sit between walls: wall–k–m–k_c–m–k–wall with k = 2 N/m and coupling k_c = 4 N/m. What is the lower natural frequency ω, in rad/s?

Answer: rad/s

2. Which metric is most directly comparable with the analytic modal solution?

  • How smooth the plot looks
  • Relative error in the measured beat period or natural frequency
  • Run time on your laptop

3. Why fix the decision rule before running the simulations?

  • It is a formality
  • It prevents choosing the metric that flatters a preferred method after seeing results
  • It makes the code faster

4. With step h, the midpoint method (global order 2) gives a global error of 0.4. Predict the error with step h/4.

Answer:

5. Which is an assumption of the two-mass model, not a result?

  • ω₂ > ω₁
  • The springs obey Hooke's law exactly
  • The mode shapes are (1, 1) and (1, −1) for equal masses

Apply it

Write a one-page plan for the term project: question, model and parameters, metrics, step sizes, decision rule, assumptions and the five figures your report will contain.

Reflect

What result would most surprise you, and what would you do if you got it?

Convergence and sensitivity studies

Your simulated frequency is 1.0007 rad/s. Is the 7 from the physics, the step size or a parameter you guessed?

About 55 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

Two questions every computational result must answer: is the number converged (numerical error small), and how much would it change if the inputs were slightly different (sensitivity)? Without both, the result cannot be trusted or compared.

Goals

Predict

For two equal masses, ω₂ = √((k + 2k_c)/m). If the coupling stiffness k_c is 10% uncertain and k_c is small compared with k, how uncertain is ω₂?

  1. About 10%
  2. Much less than 10%
  3. About 20%

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Open the Code Lab. Simulate the two-mass system with RK4 at h = 0.4, 0.2, 0.1, 0.05 s. Measure the beat period (time between energy-transfer peaks) and compare with 2π/(ω₂ − ω₁). Then vary k_c by ±10% and record how the beat period moves.

What the interactive shows, in words

This activity is code-based: simulate the two-mass system at four step sizes, measure the beat period and compare with the analytic value, then repeat with the coupling stiffness changed by plus and minus 10 percent and tabulate the results.

Understand

Convergence first

Run the simulation at several steps and compute the metric each time. Check that the differences shrink by about 2ᵖ per halving. Choose a step where the numerical error is at least ten times smaller than any effect you want to report. Record that choice and the evidence in the report.

Then sensitivity

Change one parameter at a time by a stated amount (for example ±10%) and record the change in each output: a one-at-a-time study. Report relative sensitivities (percentage change in output per percentage change in input). Compare with analytic derivatives where you have them, as in the derivation above.

Separating error sources

A result has numerical error (step size, round-off), parameter uncertainty (k_c known to ±10%) and model error (are springs really linear?). Convergence studies bound the first, sensitivity studies the second; only experiments address the third. Say clearly which you have quantified.

Explain it another way: intuitive

Before saying 'the bridge sways at 1.0 Hz', check the answer does not move when you sharpen the pencil (convergence) or when the steel is a bit stiffer (sensitivity).

Explain it another way: technical

Local sensitivity is the derivative of an output with respect to an input; global methods (Monte Carlo sampling of inputs) capture interactions and nonlinearity, previewed next term.

Explain it another way: applied

Structural engineers report natural frequencies with sensitivity to mass and stiffness, because real masses and joint stiffnesses are uncertain.

Derivation: Sensitivity of the frequencies to the coupling spring
  1. Equal masses m, outer springs k, coupling k_c: ω₁ = √(k/m), ω₂ = √((k + 2k_c)/m).

  2. ∂ω₁/∂k_c = 0: the in-phase mode never stretches the coupling spring.

  3. ∂ω₂/∂k_c = (1/2)(k + 2k_c)^{−1/2} · 2/√m = 1/(m ω₂).

  4. Relative sensitivity: (k_c/ω₂)(∂ω₂/∂k_c) = k_c/(m ω₂²) = k_c/(k + 2k_c), which is small when k_c ≪ k.

  5. Beat period T_b = 2π/(ω₂ − ω₁). For small k_c, ω₂ − ω₁ ≈ k_c/(m ω₁), so T_b ≈ 2π m ω₁ / k_c: a 10% change in k_c gives about a 10% change in T_b.

Try these examples

Example 1

m = 1 kg, k = 1 N/m, k_c = 0.1 N/m. Compute ω₁, ω₂ and T_b, then T_b with k_c = 0.11.

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. With step h, the midpoint method (global order 2) gives a global error of 0.0032. Predict the error with step h/2.

Answer:

2. Equal masses m = 1 kg, k = 1 N/m, k_c = 0.1 N/m. What is the relative sensitivity k_c/(k + 2k_c) of ω₂ to k_c? (3 d.p.)

Answer:

3. Two equal masses m = 1 kg sit between walls: wall–k–m–k_c–m–k–wall with k = 8 N/m and coupling k_c = 4 N/m. What is the lower natural frequency ω, in rad/s?

Answer: rad/s

4. Which should you do first?

  • Sensitivity study, then convergence
  • Convergence study, then sensitivity
  • Either: they measure the same thing

5. A convergence study shows the frequency is converged to 0.01%. What does that NOT tell you?

  • That the step size is adequate
  • That the springs in the real device are linear
  • That the integrator works on this problem

Apply it

For your project parameters, produce (1) a convergence table for the beat period with both integrators and (2) a one-at-a-time sensitivity table for ±10% in m₂, k₂ and k₁. Highlight which parameter dominates the uncertainty.

Reflect

Which surprised you more: how sensitive the beat period was, or how insensitive ω₂ was?

Term assessment: reporting a computational study

Your figures are beautiful. Could a stranger regenerate every one of them, and would they agree with your conclusion?

About 50 min · Checked by automated tests · Interactive lesson · Lite lesson (answers checked here)

Why it matters

This term assessment brings everything together. A computational result is only as good as its report: the reader must see what was assumed, how the numbers were checked and what they do not show. Reproducibility is part of the result, not an extra.

Goals

Predict

Which conclusion is best supported by a study of one two-mass model at three step sizes?

  1. RK4 is the best integrator for vibration problems
  2. For this model and these steps, RK4's frequency error was below 0.1% while semi-implicit Euler's energy stayed bounded and RK4's drifted slowly
  3. Semi-implicit Euler should always be used

Write down your guess and your reason. The reveal is in the online lesson.

Discover

Use the oscillator energy plot and convergence table as a model figure for your report. Choose h and duration so the figure makes one point clearly, then write its caption: what it shows, the parameters, and what the reader should conclude.

What the interactive shows, in words

The integrator diagram shows energy against time for three methods with the exact energy marked, plus a convergence table; all values are also given in text. It is used here as an example figure for writing a caption and a conclusion.

Understand

Report structure

Question (one sentence). Model: equations, parameters, assumptions, stated as a simplified model. Method: analytic modes, integrators, step sizes, metrics, the pre-committed decision rule. Verification: convergence table and observed orders. Results: figures and tables with captions that stand alone. Limitations: what the study does not show. Reproducibility: how to regenerate every figure.

Figures that carry evidence

Every figure needs labelled axes with units, a legend that does not rely on colour alone, the parameters in the caption, and a one-sentence take-away. Log–log axes for error against h make orders visible as slopes. Show the analytic reference wherever there is one.

Honest conclusions

State results with their conditions ('for h ≤ 0.1 s and t ≤ 200 s'). Report deviations from the plan. Distinguish verified (converged), sensitive (parameter-dependent) and unvalidated (never compared with a real device). A clear limitation section increases trust; it never weakens a sound result.

Explain it another way: intuitive

Write the report so that someone who disagrees with you could rerun the study and either agree or show exactly where you went wrong.

Explain it another way: technical

Reproducibility means fixed versions, a single script per figure, recorded parameters and random seeds (if any), and outputs regenerated from raw data rather than edited by hand.

Explain it another way: applied

Simulation reports that support engineering decisions are routinely reviewed for exactly these points: assumptions, verification evidence and stated limits of applicability.

Try these examples

Example 1

Rewrite: 'RK4 is perfect and Euler is useless.'

The worked solution is in the online lesson.

Common mix-ups

Practice questions

Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.

1. Which sentence over-claims?

  • Our model predicts a beat period of 65.8 s for k_c = 0.1 N/m
  • This proves real two-mass machines beat every 65.8 s
  • The beat period was converged to 0.1% at h = 0.05 s

2. What must a good figure caption include?

  • Only the title
  • What is plotted, key parameters and the take-away
  • A paragraph of background theory

3. With step h, the midpoint method (global order 2) gives a global error of 0.0032. Predict the error with step h/4.

Answer:

4. Two equal masses m = 1 kg sit between walls: wall–k–m–k_c–m–k–wall with k = 8 N/m and coupling k_c = 6 N/m. What is the lower natural frequency ω, in rad/s?

Answer: rad/s

5. Which practice best supports reproducibility?

  • Editing numbers in the final table by hand
  • One script per figure, with parameters and versions recorded
  • Keeping only the final plots

6. For dy/dt = 1y with y(0) = 2, take one classical RK4 step with h = 0.5. What is y₁? (4 decimal places.)

Answer:

Apply it

Submit the term project report (see the project brief): modal derivation, simulation code with a convergence study, a comparison of analytic modes with simulated motion, and a limitations section. Every figure must be regenerated by a documented script.

Reflect

Which part of this term's mathematics would you now reach for first in a new engineering problem, and why?