The Mathematics of Machines
Algebra, functions, trigonometry, vectors, calculus, probability and linear algebra, each with a machine attached
Eleven chapters of the maths that engineers actually reach for, in the order the School teaches it: rearranging formulas, choosing a function, describing angles and arrows, rates and totals, differential equations, chance and matrices. Every chapter composes School lessons, so each idea arrives with an interactive figure and practice checked on the server.
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
1. Algebraic modelling
Most engineering calculations start as a formula that has to be turned round. You know the supply voltage and the current an LED wants, and you need the resistor. This chapter treats a formula as a model: name the quantities and units, rearrange for the one you need, compute it carefully (in code if it helps) and check the answer is sensible.
Figure 1.1. Rearranging for an LED resistor (described in words)
A 5 V supply, a resistor R and an LED in series. The steps: Vs = I·R + Vf, so R = (Vs − Vf) / I. With Vs = 5 V, Vf = 2 V and I = 0.020 A, R = 3 / 0.020 = 150 Ω.
Explanation
1.1 Translate a formula into Python
Two programs compute a voltage divider's output. One says 3.4 V, the other 2211 V. Which pair of brackets is missing?
Python's order of operations
- Brackets. 2. Powers
**(worked right to left). 3. Unary minus, so-3 ** 2is-9. 4.*,/,//,%from left to right. 5.+,-from left to right. When in doubt, add brackets: they cost nothing and show your intent.
A translation recipe
- Name each quantity with its unit:
mass_kg,speed_m_per_s. 2. Replace a fraction bar with/and wrap the whole top and bottom in brackets. 3. Write powers with**. 4. Run it with numbers you can check by hand.
mass_kg = 1.2
speed_m_per_s = 3
energy_j = 0.5 * mass_kg * speed_m_per_s ** 2
print(round(energy_j, 2)) # 5.4Units check and estimate
For E = ½mv²: kg × (m/s)² = kg·m²/s² = J, so the formula is consistent. Estimate: ½ × 1 × 3² ≈ 4.5, close to 5.4. If an answer is out by a factor of 1000 or has the wrong unit, a conversion or bracket is missing.
Derivation: Average speed is total distance over total time
A robot drives d₁ = 120 m in t₁ = 40 s, then d₂ = 80 m in t₂ = 60 s.
Average speed means one steady speed that covers the same total distance in the same total time: v = (d₁ + d₂) / (t₁ + t₂).
Substitute: v = (120 + 80) / (40 + 60) = 200 m / 100 s = 2.0 m/s.
Averaging the two speeds gives (3.0 + 1.33) / 2 ≈ 2.17 m/s, which is wrong because the robot spends longer on the slow leg.
In Python the brackets carry the fraction bar:
(d1_m + d2_m) / (t1_s + t2_s). Without them,d1_m + d2_m / t1_s + t2_sgives 120 + 2 + 60 = 182.0, with meaningless units.
Common mix-ups
Python works out a line from left to right, whatever the operators.
✓ Precedence comes first: ** before * and /, which come before + and −. Left to right only applies within the same level.Extra brackets are bad style.
✓ Brackets that show intent are good style in engineering code, especially around a whole numerator or denominator.
1.2 Rearrange the formula, then compute: an LED resistor
An LED needs 20 mA from a 5 V supply. Ohm's law says R = V/I. Which V, and why does the answer come out 1000 times too small?
The calculator
v_supply = 5.0 # V
v_forward = 2.0 # V, from the LED datasheet
current_ma = 20 # mA, wanted LED current
current_a = current_ma / 1000
r_ohm = (v_supply - v_forward) / current_a
power_w = (v_supply - v_forward) * current_a
print(f"R = {r_ohm:.0f} ohm, P = {power_w:.3f} W")Output: R = 150 ohm, P = 0.060 W
Convert first, in one place
Datasheets mix units: mA, kΩ, mV. Convert everything to base SI units (A, Ω, V) once, near the top, in a clearly named variable such as current_a. Then every formula below can be written exactly as it appears in a textbook.
Pick a real part and check it
Resistors come in standard values, such as 120, 150 and 180 Ω. If the calculation gives 140 Ω, choose the next value up (150 Ω), so the current is slightly lower, never higher. Then check the power against the resistor's rating. This lesson is calculation only: any real circuit is built in the circuit simulator first.
Derivation: From Ohm's law to the LED resistor formula
Ohm's law for the resistor: V_R = I · R, with V_R in volts, I in amps and R in ohms.
Divide both sides by I to make R the subject: R = V_R / I.
The LED and the resistor are in series across the supply, so their voltages add: V_supply = V_forward + V_R, giving V_R = V_supply − V_forward.
Substitute: R = (V_supply − V_forward) / I.
Example: (5.0 V − 2.0 V) / 0.020 A = 3.0 / 0.020 = 150 Ω. Power in the resistor: P = V_R · I = 3.0 × 0.020 = 0.060 W, well under a common 0.25 W rating.
Common mix-ups
Use the supply voltage in R = V / I for an LED resistor.
✓ Use the voltage across the resistor, V_supply − V_forward.Unit conversions can be done in your head while reading the code.
✓ Do them in code, once, in named variables, so every reader and every rerun gets them right.
1.3 Ohm's law: V = I × R
Measure the current through a resistor at 1 V, 2 V and 3 V. One number connects all three readings. Can you find it before the graph does?
The law
For a resistor at a steady temperature, V = I × R. Know any two of voltage (V), current (A) and resistance (Ω) and you can find the third. A 220 Ω resistor with 20 mA through it has 0.02 × 220 = 4.4 V across it.
Units are where answers go wrong
Convert first: mA ÷ 1000 → A, kΩ × 1000 → Ω. A current of 5 mA through 2.2 kΩ is 0.005 A × 2200 Ω = 11 V. Then sanity-check: does the answer have the right size and unit?
Reading the graph
Plot current against voltage. For a resistor you get a straight line through the origin: that is what 'ohmic' means. The slope is I ÷ V = 1 ÷ R, so a steeper line means a smaller resistance.
Not everything is ohmic
A filament lamp's line curves over: as it heats, its resistance rises. An LED passes almost nothing below about 1.8–2 V and then the current shoots up. For these, V ÷ I still gives 'the resistance right now', but it changes from point to point.
Derivation: One law, three forms
Start from the experimental finding: for a resistor, current is proportional to voltage, I ∝ V. The constant of proportionality is 1/R, so I = V ÷ R.
Multiply both sides by R: V = I × R.
Divide both sides of V = I × R by I: R = V ÷ I.
Units: volts = amps × ohms. If I is in mA and R in kΩ, the factors of 1000 cancel (10⁻³ × 10³), so mA × kΩ gives volts directly: 5 mA × 2.2 kΩ = 11 V.
Common mix-ups
R = V ÷ I means resistance depends on the voltage you apply.
✓ For a resistor, R is fixed: change V and I changes in proportion, so V ÷ I stays the same. Only non-ohmic parts change.Ohm's law works for every component.
✓ It describes ohmic components. Lamps, LEDs and diodes do not follow a straight line.
1.4 Models are functions: input in, output out
A robot must stop within 1 m of an obstacle. What's the fastest it may drive? One graph answers that instantly.
One input, one output
A function f takes an input x and gives exactly one output f(x). In engineering both have units: a spring with f(F) = 2.5F turns a load in newtons into an extension in millimetres. Writing f(x) = … makes the rule something you can test, plot and reuse, just like a Python function.
Shapes tell stories
Linear (straight line): equal input steps give equal output steps, like a spring. Inverse: doubling the input halves the output, like effort on a longer lever. Periodic: the output repeats, like an arm's tip height as it turns. Quadratic: the output grows faster and faster, like stopping distance with speed.
Reading backwards
A requirement is a line on the graph: 'stop within 1 m' is a horizontal line at d = 1. Inputs where the curve is below the line pass. For d = 0.2v + v²/4, that's speeds up to about 1.6 m/s. To solve a linear function backwards, undo its steps: if f(x) = 2x + 10 = 50, then x = (50 − 10) ÷ 2 = 20.
Common mix-ups
If the input doubles, the output doubles.
✓ Only for proportional (linear through zero) functions. Inverse, quadratic and periodic functions behave differently.A graph is just a picture of a table.
✓ It also shows the shape, which tells you how sensitive the output is and where a requirement is met.
Examples to try
Worked solutions are in the interactive chapter online.
Translate a formula into Python: example 1
Write F = C × 9/5 + 32 in Python and check it at 100 °C.
Rearrange the formula, then compute: an LED resistor: example 1
A 12 V supply drives a white LED (3.0 V) at 15 mA. Find R and P.
Ohm's law: V = I × R: example 1
A 9 V battery is connected across a 450 Ω resistor. What current flows?
Ohm's law: V = I × R: example 2
A sensor has 3.3 V across it and draws 1.5 mA. What is its resistance?
Models are functions: input in, output out: example 1
A 3D printer's print time is t(m) = 2m + 10 minutes for a part of mass m grams. How long for 25 g? Largest part in 90 minutes?
Interactive figures, in words
Figure 1.2 from “Translate a formula into Python”
Pick 'Voltage divider' and step through each expression: in which step does the wrong one go astray? Then try 'Kinetic energy' (is 1 / 2 * m * v ** 2 right?) and 'Average speed' (why is averaging the two speeds wrong?).
The precedence explorer shows a formula, sliders for its inputs, and several Python expressions. For the chosen expression it lists every evaluation step. Example, voltage divider with 5 V, 1000 Ω, 2200 Ω: v_in * r2 / (r1 + r2) → 5 * 2200 / 3200 → 11000 / 3200 → 3.4375 (matches); v_in * r2 / r1 + r2 → 11000 / 1000 + 2200 → 11.0 + 2200 → 2211.0 (does not match).
Figure 1.3 from “Ohm's law: V = I × R”
Choose the 220 Ω resistor. Record points at 1 V, 2 V, 4 V and 6 V and check that V ÷ I is the same each time. Do the same for the 100 Ω resistor: which line is steeper? Then try the filament lamp and the LED and record three points each. What is different about their V ÷ I?
The V–I plotter shows current (0 to 60 mA) against voltage (0 to 6 V). The 100, 220 and 470 ohm resistors give straight lines through the origin; the 100 ohm line is steepest. The filament lamp's curve bends over as its resistance rises. The LED passes almost no current below about 1.8 V, then rises steeply. Recorded points are listed in a table with V ÷ I for each.
Figure 1.4 from “Models are functions: input in, output out”
Try each example. Move the input slider and read the output; then move the requirement line and read off which inputs pass. For the stopping-distance example, find the top speed that still stops within 1 m.
The function grapher offers four examples: spring extension (linear), lever effort (inverse), arm tip height (periodic) and stopping distance (quadratic). A slider sets the input and a point marks it on the curve; another slider sets a requirement line. The readout gives the output and the range of inputs that meet the requirement, and a table lists five input–output pairs.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Simulation OS: LED current limiting (Simulation OS experiment)
Predict the current for three resistor values with your rearranged formula, then check each against the model.
Open online - Equation Lab: Functions (Equation Lab exploration)
Fit a straight line to a linear sensor and read the gradient with its units.
Open online - Code Lab (Studio)
Write a function that returns the LED resistor for any supply, forward voltage and current, and test it on the 5 V case.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. Which Python line correctly computes V_out = V_in·R2/(R1 + R2)?
- v_out = v_in * r2 / r1 + r2
- v_out = v_in * r2 / (r1 + r2)
- v_out = (v_in * r2 / r1) + r2
Check it in “Translate a formula into Python”
2. A robot drives 300 m in 100 s, then 100 m in 100 s. What is its average speed, in m/s?
Answer: m/s
Check it in “Translate a formula into Python”
3. Someone writes power_w = voltage_v / current_a. What does a units check say?
- Fine: V/A is watts
- Wrong: V/A is ohms; power is V × A
- Fine if the numbers are small
Check it in “Translate a formula into Python”
4. An LED with a forward voltage of 1.8 V should carry 15 mA from a 9 V supply. Using r_ohm = (v_supply - v_forward) / (current_ma / 1000), what resistance is needed, in ohms?
Answer: Ω
Check it in “Rearrange the formula, then compute: an LED resistor”
5. Rearrange V = I · R to find I.
- I = V · R
- I = V / R
- I = R / V
Check it in “Rearrange the formula, then compute: an LED resistor”
6. There are 6 V across a 1.5 kΩ resistor. What current flows, in milliamps?
Answer: mA
Check it in “Ohm's law: V = I × R”
7. 5 mA flows through a 2.2 kΩ resistor. What is the voltage across it, in volts?
Answer: V
Check it in “Ohm's law: V = I × R”
8. A spring's extension is e(F) = 2.5·F mm, with F in newtons. What is the extension for a 12 N load, in mm?
Answer: mm
Check it in “Models are functions: input in, output out”
Engineering applications
Choosing parts
Rearranged formulas pick resistors, gear ratios and battery sizes. The computed value is then rounded to a part that exists, and the formula is run again forwards to check the rounded part still works.
Unit bugs
Writing 20 instead of 0.020 for a current in amperes makes the resistor a thousand times too small. Converting every quantity to SI units in one place, before calculating, prevents a whole class of mistakes.
Summary
- A formula is a model: each symbol is a quantity with a unit and a meaning.
- Rearranging means doing the same operation to both sides until the unknown stands alone.
- Convert to SI units first, compute, then check the size of the answer with an estimate.
- A model is a function: one input gives one output, and its graph shows how the output responds.
Glossary
- Ohm's law
- For a resistor, the voltage across it equals the current through it multiplied by its resistance.
- LED current-limiting resistor
- An LED needs a series resistor to set its current, chosen so that the supply voltage minus the LED's forward voltage, divided by the resistance, gives the desired current.
- SI prefixes and unit conversion
- SI prefixes are powers of ten written in front of a unit symbol, such as k for 10^3 and m for 10^-3, so that very large and very small quantities stay readable.
- Gradient of a straight line
- The gradient of a straight line is the change in y divided by the change in x between any two points on it; in y = mx + c it is m, and c is where the line crosses the y-axis.
- Hooke's law (springs)
- For a spring within its elastic limit, the force needed to stretch or compress it is proportional to the change in length: F = k × x.
Project: A resistor calculator you can trust
Write a small program that chooses an LED resistor for any supply between 3 V and 12 V. It must convert units in one place, round up to a standard resistor value of your choice, and report the resulting current and the resistor's power.
Deliverables
- The rearranged formula with units
- The program with at least three test cases
- A note on what happens if the supply is below the LED's forward voltage
References
2. Functions as models
Choosing the right family of function is half of modelling. A spring is linear, drag grows like a power of speed, a cooling cup decays exponentially and mains voltage repeats as a sinusoid. This chapter gives each family a test you can run on data, explains the domain where a model is allowed to speak, and uses residuals to judge whether the shape is right.
Figure 2.1. Three families, three shapes (described in words)
Three small graphs on the interval 0 to 2. A straight line y = x rises steadily. A power law y = x^2 starts flat and curves upward to 4. An exponential decay y = e^(−x) starts at 1 and falls towards zero, reaching about 0.14 at x = 2.
Explanation
2.1 Functions as engineering models
A spring balance turns a stretch into a force reading. What is the rule inside it, and at what stretch does the rule start lying?
A model is a function with a job
A function takes an input (the independent variable) and returns exactly one output. In engineering both carry units: stretch x in metres, force F in newtons. The parameters are the fixed numbers that tailor a family to one device: stiffness k = 250 N/m. Write all three, every time, or the numbers are meaningless.
Domain: where the model is allowed to speak
Every model has a domain of inputs where it was tested or derived. A thermistor formula may hold from 0 to 100 °C; a spring law up to its elastic limit. Using a model outside its domain is extrapolation. Sometimes it is fine, often it is dangerous, and it must always be said out loud.
Residuals judge the shape
A residual is data minus model at each point. If the model's shape is right, residuals scatter randomly around zero, changing sign often. If they form long runs (all positive in the middle, all negative at the ends) the family is wrong, however small the numbers look. Fit quality has two parts: the size of the residuals and their pattern.
Common mix-ups
If the equation gives a number, the number is right.
✓ A model is only trustworthy inside the domain where it was tested or derived.Small residuals mean the right model.
✓ Residuals must also look random. A patterned residual reveals the wrong shape even when its size is small.
2.2 Power laws and exponentials
Double a cyclist's speed and the air pushes back four times harder. Halve a capacitor's charge and it takes the same time to halve again. Two very different curves: how do you tell them apart?
Scaling test for a power law
For y = k·xⁿ, multiplying x by any factor s multiplies y by sⁿ, whatever x you start from. Drag (n = 2): double speed, four times the force. Cylinder volume against radius at fixed height (n = 2). A beam's deflection against length under its own weight (n = 4). The exponent n carries the physics.
Constant-ratio test for an exponential
For y = A·e^(kx), adding a fixed amount to x multiplies y by a fixed ratio. A capacitor V = V₀·e^(−t/τ) loses 63% of its remaining voltage every τ seconds and halves every τ·ln 2. The quantity τ (the time constant) has the units of time and sets the speed of the whole process.
e and the natural logarithm
e ≈ 2.718 is the base for which the exponential's slope equals its value: d/dx eˣ = eˣ. That makes e^(kt) the natural language of anything whose rate of change is proportional to its size. Its inverse is ln: ln(eˣ) = x. You will use both constantly from week 3 on.
Derivation: Why logarithms straighten both families
Power law: y = k·xⁿ. Take natural logs of both sides: ln y = ln k + n·ln x.
So plotting ln y against ln x gives a straight line with slope n and intercept ln k. A log–log plot that is straight means a power law.
Exponential: y = A·e^(kx). Take logs: ln y = ln A + k·x.
So plotting ln y against x (only the y-axis logged) gives a straight line with slope k. A semi-log plot that is straight means an exponential.
Both tricks need y > 0 (and x > 0 for the power law) because the logarithm of zero or a negative number is not defined. That is why the lab refuses log fits on data that cross zero.
Common mix-ups
Any curve that rises steeply is exponential.
✓ Power laws also rise steeply. Exponentials have a constant ratio per equal step; power laws have a constant ratio per scale factor.The time constant is the time to reach zero.
✓ An exponential decay never reaches zero. After one τ it is at 37%, after 5τ about 0.7%.
2.3 Sinusoids: models that repeat
The voltage in a wall socket swings from +325 V to −325 V fifty times a second. The harbour tide does the same thing twice a day. One function describes both.
Four parameters, four jobs
y = A·sin(2πft + φ) + c. Amplitude A: the peak swing (325 V). Frequency f in hertz: cycles per second. Phase φ in radians: where in the cycle it starts. Offset c: the level it swings around (zero for mains, mean sea level for tides). Period T = 1/f.
Angular frequency
Inside the sine the angle must be in radians. One cycle is 2π radians, so the angle grows at ω = 2πf radians per second. For 50 Hz, ω = 314 rad/s. You will meet ω constantly: in derivatives of sinusoids (week 3), in vibration and in control.
Why other families fail here
Power laws and exponentials are fitted on log axes, and logs need positive values. A sinusoid with zero offset is negative half the time. More fundamentally, neither family can turn round and come back: a periodic quantity needs a periodic model.
Common mix-ups
Angles in sin(2πft) can be in degrees.
✓ The 2πf form assumes radians. In degrees you would need 360·f·t instead, and calculus formulas only work in radians.230 V mains means the voltage never exceeds 230 V.
✓ 230 V is the rms value; the peak is about 325 V.
Examples to try
Worked solutions are in the interactive chapter online.
Functions as engineering models: example 1
A temperature sensor outputs V = 0.01·T + 0.5 volts for 0 ≤ T ≤ 100 °C. Write the inverse function and find T when V = 1.2 V.
Functions as engineering models: example 2
A fit to a spring gives F = 251x − 0.1 N. What do 251 and −0.1 mean?
Power laws and exponentials: example 1
A capacitor discharges as V = 9·e^(−t/1.5) volts. When has it fallen to 4.5 V?
Power laws and exponentials: example 2
Drag measurements: 10 N at 5 m/s and 40 N at 10 m/s. Power law or exponential, and what parameter?
Sinusoids: models that repeat: example 1
v(t) = 325·sin(2π·50·t) volts. What is v at t = 2.5 ms?
Interactive figures, in words
Figure 2.2 from “Functions as engineering models”
Start with the spring test and the linear family. Read the best-fit slope: what are its units? Nudge the slope to 80% and 120% and watch the RMS residual climb. Now switch to the wind-tunnel drag data with a linear model: the residuals form a smile-shaped run. That pattern means the shape, not the noise, is wrong.
The fitter plots data points with a best-fit curve and a residual bar chart beneath it. For the spring data a straight line fits with stiffness about 250 N/m and residuals that flip sign often. For the drag data a straight line leaves a run of positive residuals at both ends and negative in the middle; a power law removes the pattern. The readout states the fitted equation, the RMS residual and how often the residuals change sign.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Functions (Equation Lab exploration)
Switch between the linear, quadratic, sine and exponential families and find which one fits each sample data set.
Open online - Simulation OS: RC charge and discharge (Simulation OS experiment)
Measure the capacitor voltage at equal time steps and show the ratio between successive readings is constant.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. A sensor obeys V = 0.01·T + 0.5 volts (T in °C, valid 0–100 °C). What voltage does it give at 37 °C?
Answer: V
Check it in “Functions as engineering models”
2. A fitted model is battery voltage V (V) against time t (h): V = −0.05t + 12.6. What are the units and meaning of −0.05?
- Volts: the voltage at t = 0
- Volts per hour: the voltage falls by 0.05 V each hour
- Hours per volt: the time to lose one volt
Check it in “Functions as engineering models”
3. Drag F = 0.4·v² newtons (v in m/s). What is the drag at 15 m/s?
Answer: N
Check it in “Power laws and exponentials”
4. V = 9·e^(−t/1.5) volts. How long until V = 4.5 V, in seconds?
Answer: s
Check it in “Power laws and exponentials”
5. You plot ln(y) against x and get a straight line with slope −0.4. What model fits?
- y = A·x^(−0.4)
- y = A·e^(−0.4x)
- y = −0.4x + A
Check it in “Power laws and exponentials”
6. What is the angular frequency ω of a 50 Hz supply, in rad/s?
Answer: rad/s
Check it in “Sinusoids: models that repeat”
7. A tide model is h(t) = 1.8·sin(2πt/12.4 + 0.6) metres with t in hours. What is its frequency in cycles per day?
Answer: cycles/day
Check it in “Sinusoids: models that repeat”
Engineering applications
Calibrating sensors
A temperature sensor's datasheet gives a linear model over a stated range. Outside that range the same formula still returns numbers, but they are no longer evidence of anything.
Battery and capacitor timing
A capacitor discharging through a resistor follows V = V0·e^(−t/RC). After one time constant RC it has fallen to about 37 % of its starting value, which sets how long a backup supply lasts.
Summary
- Linear: equal steps in x give equal steps in y. Power law: doubling x multiplies y by a fixed factor. Exponential: equal steps in x multiply y by a fixed ratio.
- A model has a domain: the range of inputs where it was checked.
- Residuals (data minus model) should look like random scatter; a pattern means the wrong shape.
- A sinusoid A·sin(ωt + φ) + c has amplitude, angular frequency, phase and offset; ω = 2πf.
Glossary
- Exponential growth and decay
- A quantity decays exponentially when its rate of decrease is proportional to how much is left, giving y = y0 × e^(−t/τ).
- Logarithms and decibels
- A logarithm answers 'what power gives this number?'. Decibels use logarithms to express ratios: 10 log10 for power ratios and 20 log10 for amplitude ratios.
- Frequency and period
- Frequency is how many cycles happen per second; the period is the time for one cycle. Each is the reciprocal of the other.
- Linear interpolation
- Linear interpolation estimates a value between two known points by assuming a straight line between them.
Project: Which model fits?
Collect or choose a small data set from a real system (a cooling drink, a bouncing ball's peak heights, a phone battery's charge). Apply the three family tests, fit the best family, plot the residuals and state the domain where you would trust the model.
Deliverables
- The data with units and source
- The family tests and their results
- A residual plot
- A one-sentence domain statement
References
- Gilbert Strang and Edwin Herman (2016). Calculus Volume 1. OpenStax. Link
- K. A. Stroud and Dexter J. Booth (2013). Engineering Mathematics, 7th edition. Palgrave Macmillan.
3. Trigonometry and periodic motion
Robot arms, wheels and waves all turn angles into lengths. Trigonometry starts with similar triangles, whose side ratios depend only on the angle, and names those ratios sine, cosine and tangent. Measuring angles in radians then puts sine and cosine on the unit circle, and a point going round that circle gives the sinusoids that describe anything that repeats.
Figure 3.1. The unit circle at 30° (described in words)
A circle of radius 1 centred at the origin. A radius at 30 degrees (π/6 radians) ends at the point (cos 30°, sin 30°) = (0.866, 0.5). The horizontal leg is labelled cos θ and the vertical leg sin θ.
Explanation
3.1 Same shape, different size: similar triangles
You can't climb the crane, but you have a 1.5 m pole and a sunny afternoon. How do you measure the crane's height without leaving the ground?
What makes triangles similar
Two triangles are similar if their angles match. Then every side of one is the matching side of the other multiplied by the same scale factor k. If one triangle has sides 3, 4, 5 cm and a similar one has a 6 cm shortest side, k = 2 and the others are 8 and 10 cm.
Ratios inside a triangle are fixed
Because every side scales by k, any ratio of two sides of the same triangle, such as height ÷ base, stays the same. Sun rays hit a pole and a crane at the same angle, so height ÷ shadow is the same for both: measure the pole and both shadows, and the crane's height follows.
Areas scale by k²
Area is a length times a length, so it scales by k × k = k². A model at half size (k = 0.5) has a quarter of the area. Volumes scale by k³, which is why a half-size model of a solid part weighs only an eighth as much.
Common mix-ups
Scaling a shape changes its angles too.
✓ Scaling changes lengths only. Angles describe shape, so similar shapes have identical angles.A half-size model has half the area and half the mass.
✓ Area scales by k² (a quarter) and volume, so mass, by k³ (an eighth).
3.2 sin, cos and tan are just ratios
A 10 cm robot link tilted at 30° lifts its tip 5 cm. Make the link twice as long at the same angle. How high does the tip go?
Label the sides first
Mark the angle θ you care about. The hypotenuse is the longest side, opposite the right angle (for a robot link, the link itself). The opposite side is across from θ. The adjacent side is next to θ but isn't the hypotenuse. Mislabelled sides cause most trig mistakes.
Three ratios, one angle
sin θ = opposite ÷ hypotenuse, cos θ = adjacent ÷ hypotenuse and tan θ = opposite ÷ adjacent. Because the hypotenuse is the longest side, sin and cos are never bigger than 1. Some to remember: sin 30° = 0.5, cos 60° = 0.5, tan 45° = 1, sin 90° = 1.
From ratios to robot parts
Rearrange: a link of length L at angle θ reaches L · cos θ across and L · sin θ up. A 12 cm link at 30° lifts its tip 12 × 0.5 = 6 cm. Your calculator must be in degrees for these; next lesson you will meet radians, which most code uses.
Derivation: Why each angle has its own ratios
Take any right-angled triangle with an angle θ. Its three angles are θ, 90° and 90° − θ.
Any other right-angled triangle with the same θ has the same three angles, so the two triangles are similar.
In similar triangles every side is scaled by the same k, so a ratio like opposite ÷ hypotenuse cancels k out: (k·o) ÷ (k·h) = o ÷ h.
So the ratio depends only on θ. We name them: sin θ = opposite ÷ hypotenuse, cos θ = adjacent ÷ hypotenuse, tan θ = opposite ÷ adjacent (SOH CAH TOA).
Rearranged for a link of length L: vertical part = L · sin θ, horizontal part = L · cos θ.
Common mix-ups
A longer link at the same angle has a bigger sin θ.
✓ sin θ depends only on the angle. A longer link has a bigger height, but the ratio height ÷ length is the same.The hypotenuse is whichever side is not touching the angle.
✓ The hypotenuse is always the longest side, opposite the right angle. The side not touching θ is the opposite side.
3.3 Radians and the unit circle
Why would anyone measure a full turn as 6.283… instead of a nice round 360?
What a radian is
Wrap the radius of a circle around its edge: the angle it covers is 1 radian (about 57.3°). A full circle's edge is 2π radii long, so a full turn is 2π rad = 360°, and π rad = 180°. To convert: degrees × π/180 = radians; radians × 180/π = degrees. Arc length is simply s = r·θ when θ is in radians.
Sine and cosine live on a circle
Draw a circle of radius 1 centred on the origin. Go anticlockwise through angle θ from +x. The point you land on is (cos θ, sin θ). That's the definition, and it works for every angle, including 200° and −30°. The triangle definitions (opposite over hypotenuse) are the special case 0° < θ < 90°.
Signs by quadrant
Quadrant 1 (0–90°): both positive. Quadrant 2 (90–180°): cos negative, sin positive. Quadrant 3 (180–270°): both negative. Quadrant 4 (270–360°): cos positive, sin negative. And always cos²θ + sin²θ = 1, because the point sits on a circle of radius 1.
Common mix-ups
Sine and cosine only make sense for angles inside a right-angled triangle.
✓ On the unit circle they're defined for every angle, positive or negative, any size.Radians are just a different number for the same thing, so it doesn't matter which you use.
✓ Software and formulas like s = r·θ assume radians. Mixing them up gives silently wrong results.
3.4 Periodic motion: A·sin(ωt + φ)
A piston, a pendulum and a flapping wing repeat forever. Three numbers describe all of them. Which three?
The shadow of a circle
A point going round a circle of radius A at a steady ω radians per second has height y(t) = A·sin(ωt + φ), where φ is its starting angle. Its shadow on a wall bobs up and down: that is simple periodic (harmonic) motion. A crank pin, a wheel's valve and a rotating cam all make exactly this.
Three numbers
Amplitude A: the biggest distance from the middle. Angular frequency ω (rad/s): how fast the angle grows. One cycle is 2π, so the period T = 2π/ω and the frequency f = 1/T = ω/2π (in hertz). Phase φ: where in the cycle it starts; a positive φ shifts the wave earlier by φ/ω seconds.
Reading a graph
Peak height (from the middle line) = A. Time between two peaks = T, so ω = 2π/T. Where the wave crosses upwards through zero, compared with t = 0, gives the phase. Always check your calculator is in radians: ωt + φ is an angle in radians.
Common mix-ups
A bigger amplitude means a faster oscillation.
✓ Amplitude sets the size; ω alone sets the period T = 2π/ω.Frequency f and angular frequency ω are the same number.
✓ ω = 2πf. A 1 Hz motion has ω ≈ 6.28 rad/s.
Examples to try
Worked solutions are in the interactive chapter online.
Same shape, different size: similar triangles: example 1
A 1.2 m stick casts a 0.8 m shadow. A wind turbine tower nearby casts a 40 m shadow at the same time. How tall is the tower?
Same shape, different size: similar triangles: example 2
A plate drawn at 1 : 2 has an area of 600 mm² on paper. What is the real plate's area?
sin, cos and tan are just ratios: example 1
A 15 cm link points 60° above horizontal. How high is its tip above the joint?
sin, cos and tan are just ratios: example 2
A ramp rises 1 m over 4 m across. What is tan of its angle?
Radians and the unit circle: example 1
A servo turns 2.5 rad. Is that more or less than half a turn, and how many degrees?
Periodic motion: A·sin(ωt + φ): example 1
A test rig shakes a sensor with y(t) = 4 sin(10t) mm. Find the amplitude, period and frequency.
Interactive figures, in words
Figure 3.2 from “Same shape, different size: similar triangles”
Choose 'Scale it'. Change the scale factor k and watch the table: every side multiplies by k, but height ÷ base and the angle stay put. Then set k = 2 and compare the areas. Predict first: does the area double?
The 'Scale it' tool draws a right-angled triangle and a scaled copy on top of it. Sliders set the base, height and scale factor k. A table lists the sides, the ratio height ÷ base, the angle and the area for both triangles: sides multiply by k, the ratio and angle stay the same, and the area multiplies by k².
Figure 3.3 from “sin, cos and tan are just ratios”
Fix the angle at 30° and slide the link length from 5 to 30 cm: the sides change, the three ratios don't. Then try the shelf challenges: predict the angle with sin θ = height ÷ length before you slide.
The diagram draws a robot link from a shoulder joint at an angle you set, with a dashed horizontal line (adjacent side) and a dashed vertical line (opposite side) making a right-angled triangle. Sliders set the link length and the angle. A table shows sin θ = opposite ÷ hypotenuse, cos θ = adjacent ÷ hypotenuse and tan θ = opposite ÷ adjacent with the current numbers; changing the length changes the sides but not the ratios.
Figure 3.4 from “Radians and the unit circle”
On the unit circle, step θ from 0° to 355°. Watch the blue cos bar and orange sin bar. Find the four angles where one of them is exactly 0. Where is cos negative? Where are both negative? Note θ in radians at 90°, 180° and 360°.
The unit-circle explorer draws a circle of radius 1 with a point at angle θ. A blue horizontal bar shows cos θ and an orange vertical bar shows sin θ. The readout gives θ in degrees and radians, both values and the quadrant. At 0°, 90°, 180° and 270° the point is at (1, 0), (0, 1), (−1, 0) and (0, −1).
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Playground: Robotic kinematics (Playground lab)
Set one joint angle and predict the tip's x and y with L·cos θ and L·sin θ before reading them off.
Open online - Equation Lab: Oscillator (Equation Lab exploration)
Change the spring stiffness and read how the period of the sinusoid changes.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. A 1.5 m pole casts a 2 m shadow. At the same moment a tree casts a 12 m shadow. How tall is the tree, in metres?
Answer: m
Check it in “Same shape, different size: similar triangles”
2. A robot link is tilted at angle θ above the horizontal. Relative to θ, which side is the vertical drop from the tip down to the horizontal line?
- The hypotenuse
- The opposite side
- The adjacent side
Check it in “sin, cos and tan are just ratios”
3. tan 45° = 1. A line rises at 45° and goes 8 cm across. How far up does it go, in cm?
Answer: cm
Check it in “sin, cos and tan are just ratios”
4. Convert 60° to radians (3 decimal places).
Answer: rad
Check it in “Radians and the unit circle”
5. At θ = 250°, what are the signs of (cos θ, sin θ)?
- (+, +)
- (−, +)
- (−, −)
- (+, −)
Check it in “Radians and the unit circle”
6. A wheel of radius 0.1 m turns through 3 radians. How far does its rim travel, in metres?
Answer: m
Check it in “Radians and the unit circle”
7. y(t) = 5 sin(4t). What is the period, in seconds? (3 decimal places)
Answer: s
Check it in “Periodic motion: A·sin(ωt + φ)”
8. A motor vibration repeats every 0.02 s. What is its frequency, in hertz?
Answer: Hz
Check it in “Periodic motion: A·sin(ωt + φ)”
Engineering applications
Where is the gripper?
A one-link arm of length L at angle θ puts its tip at x = L·cos θ, y = L·sin θ. Every robot's forward kinematics is built from this one idea, repeated link by link.
Wheel odometry
A wheel of radius r that turns through θ radians rolls a distance r·θ. Measuring angles in radians makes this formula work with no conversion factor.
Summary
- Similar triangles have equal angles, so their side ratios are equal.
- sin θ = opposite/hypotenuse, cos θ = adjacent/hypotenuse, tan θ = opposite/adjacent.
- One radian is the angle that cuts off an arc equal to the radius; 180° = π radians.
- On the unit circle the point at angle θ is (cos θ, sin θ), and the signs follow the quadrant.
- A·sin(ωt + φ) repeats every T = 2π/ω seconds, so f = ω/(2π).
Glossary
- Sine, cosine and tangent
- In a right-angled triangle, sine is opposite over hypotenuse, cosine is adjacent over hypotenuse and tangent is opposite over adjacent, each a function of the angle.
- Radians and degrees
- A radian is the angle at which the arc length equals the radius. A full turn is 2π radians, which is 360 degrees.
- Pythagoras' theorem
- In a right-angled triangle, the square of the hypotenuse equals the sum of the squares of the other two sides.
- Frequency and period
- Frequency is how many cycles happen per second; the period is the time for one cycle. Each is the reciprocal of the other.
Project: Measure a height without climbing
Measure the height of a tall object (a tree, a lamp post, a building) using a known distance along the ground and a measured angle, then check it with a second method based on similar triangles and shadows. Compare the two results and explain the difference.
Deliverables
- Both measurements with units
- Both calculations
- An uncertainty estimate for each
- A sentence on which method you trust more and why
References
- Jay Abramson (2015). Algebra and Trigonometry. OpenStax. Link
- K. A. Stroud and Dexter J. Booth (2013). Engineering Mathematics, 7th edition. Palgrave Macmillan.
4. Vectors
Forces, velocities and displacements have a size and a direction. A vector stores both as components that you can add part by part. This chapter adds vectors, finds their length with Pythagoras, finds their direction with atan2 (which, unlike a plain inverse tangent, knows which quadrant it is in) and uses the dot product to measure how much two directions agree.
Figure 4.1. Adding vectors tip to tail (described in words)
On a grid, vector a = (3, 1) is drawn from the origin, then vector b = (1, 2) from the tip of a. Their sum a + b = (4, 3) goes from the origin to the final tip, with length sqrt(4^2 + 3^2) = 5.
Explanation
4.1 Vectors: arrows you can add
A drone flies 3 m east, then 4 m north. It is 5 m from where it started, not 7. Where did the other 2 m go?
Size and direction, written as components
A vector is a quantity with a size and a direction, such as a displacement, a velocity or a force. In 2D we write it as two components, v = (vx, vy): how far along x, then how far along y, measured in some coordinate frame. The same arrow drawn anywhere on the page is the same vector; only its components matter.
Adding: tip to tail, or part by part
To add a and b, draw b starting where a ends; the sum runs from the start of a to the end of b. Algebraically that is just a + b = (ax + bx, ay + by). Subtraction works the same way: a − b is the arrow from the tip of b to the tip of a. Scaling by a number k multiplies both parts: k·a = (k·ax, k·ay).
Magnitude: Pythagoras in disguise
The components form the two short sides of a right-angled triangle, so the length (magnitude) is |v| = √(vx² + vy²). Lengths do not add like components: |a + b| ≤ |a| + |b|, with equality only when a and b point the same way. That is the drone's missing 2 m: 3 east + 4 north is (3, 4), length 5.
Common mix-ups
The length of a + b is |a| + |b|.
✓ Only when a and b point the same way. In general |a + b| is smaller, and you must add components first.Moving an arrow to a different place on the page makes it a different vector.
✓ A vector is just its components. Position on the page doesn't matter; that is what lets you draw tip to tail.
4.2 Which way is it pointing? Direction with atan2
Your calculator says tan⁻¹(−1 ÷ −1) = 45°. But (−1, −1) points down and to the left. Who is wrong?
Two ways to write the same arrow
Components: (x, y). Polar form: length r and direction θ, measured anticlockwise from +x. To go from polar to components: x = r cos θ, y = r sin θ. To go back: r = √(x² + y²) and θ from the inverse tangent, carefully.
Why tan⁻¹(y/x) lies
tan θ = y/x, but dividing throws away the signs: (1, 1) and (−1, −1) both give y/x = 1. So tan⁻¹ can only answer between −90° and 90°: it is right for vectors pointing rightwards (x > 0) and exactly 180° out for vectors pointing leftwards. At x = 0 it divides by zero.
atan2: the angle that knows its quadrant
atan2(y, x) takes the two parts separately, checks their signs and returns an angle in (−180°, 180°]. Add 360° to negative answers if you want 0–360°. It is in every language: Python's math.atan2, JavaScript's Math.atan2, C's atan2. Note the order: y first. Robot code uses it to turn components back into headings and joint angles.
Common mix-ups
tan⁻¹(y/x) always gives a vector's direction.
✓ Only when x > 0. Use atan2(y, x), which checks both signs.atan2 takes (x, y) like a coordinate.
✓ It takes (y, x): the y component first. Swapping them gives the angle measured from the y axis instead.
4.3 The dot product: how much do two arrows agree?
One number can tell a robot whether a target is in front of it or behind it, without a single angle being measured. How?
The recipe
a · b = ax·bx + ay·by: multiply matching parts and add. The result is a plain number (a scalar), not a vector. Order doesn't matter: a · b = b · a. And a · a = |a|², so the dot product contains Pythagoras.
What the sign says
From a · b = |a||b| cos θ: positive when the angle is under 90° (pointing roughly together), zero when perpendicular, negative when over 90° (pointing roughly apart). Lengths are never negative, so the sign comes entirely from cos θ.
Angles and shadows
Rearranged, cos θ = a · b ÷ (|a||b|), which gives the angle between any two non-zero vectors. And a · b ÷ |b| is the scalar projection of a on b: the length of a's shadow along b's direction. That is how a robot finds the part of a force that acts along a slide, or how far ahead an obstacle is along its heading.
Derivation: Why a · b = |a||b| cos θ (from the law of cosines)
Draw a and b from the same point, with angle θ between them. The third side of the triangle is the vector a − b.
The law of cosines for that triangle says: |a − b|² = |a|² + |b|² − 2|a||b| cos θ.
Expand the left side with components: |a − b|² = (ax − bx)² + (ay − by)² = ax² + ay² + bx² + by² − 2(ax·bx + ay·by).
But ax² + ay² = |a|² and bx² + by² = |b|², so the left side is |a|² + |b|² − 2(ax·bx + ay·by).
Compare the two expressions: the |a|² and |b|² cancel, leaving ax·bx + ay·by = |a||b| cos θ. The component recipe and the geometric meaning are the same number.
Common mix-ups
The dot product of two vectors is another vector.
✓ It is a single number. (Multiplying each part and keeping them separate is a different operation.)A negative dot product means one vector is 'negative'.
✓ It means the angle between them is more than 90°: they point roughly in opposite directions.
Examples to try
Worked solutions are in the interactive chapter online.
Vectors: arrows you can add: example 1
A rover drives a = (5, −2) m, then b = (−1, 6) m. Where does it end up, and how far is that from the start?
Which way is it pointing? Direction with atan2: example 1
Give the direction of (4, −9) in degrees from 0 to 360.
Which way is it pointing? Direction with atan2: example 2
A 2.5 m link points at 200°. Where is its tip?
The dot product: how much do two arrows agree?: example 1
Is the target at r = (−2, 5) ahead of or behind a robot facing h = (0.6, −0.8)?
Interactive figures, in words
Figure 4.2 from “Vectors: arrows you can add”
In 'Add tip to tail', set a = (3, 1) and b = (1, 2.5). Check the green sum against your prediction. Now make b point exactly opposite to a. What happens to a + b? Then find a b for which |a + b| = |a| + |b|.
The vector playground draws vector a in blue from the origin, vector b in orange starting at the tip of a, and their sum in dashed green from the origin to the tip of b. The readout lists every component, the sum and its length, and the same information is in the text above.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Vectors (Equation Lab exploration)
Drag two vectors until their dot product is zero, and measure the angle between them.
Open online - Simulation OS: Two-link reach (Simulation OS experiment)
Describe the arm's tip as the sum of two link vectors and predict its reach before running the model.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. a = (2, −3) and b = (−5, 4). What is the x component of a + b?
Answer:
Check it in “Vectors: arrows you can add”
2. What is the magnitude of the vector (6, 8)?
Answer:
Check it in “Vectors: arrows you can add”
3. atan2(3, −4) is closest to which angle?
- −36.9°
- 36.9°
- 143.1°
- 216.9°
Check it in “Which way is it pointing? Direction with atan2”
4. A target is at (−5, 12) m from a robot. How far away is it, in metres?
Answer: m
Check it in “Which way is it pointing? Direction with atan2”
5. For which vector does tan⁻¹(y/x) give the correct direction?
- (−2, 5)
- (3, −1)
- (−1, −1)
- (0, 4)
Check it in “Which way is it pointing? Direction with atan2”
6. Find a · b for a = (4, −1) and b = (2, 3).
Answer:
Check it in “The dot product: how much do two arrows agree?”
7. Which vector is perpendicular to (2, 5)?
- (5, 2)
- (−5, 2)
- (2, −5)
- (−2, −5)
Check it in “The dot product: how much do two arrows agree?”
8. A 10 N force F = (8, 6) N pushes a cart that can only roll along the x axis. How many newtons act along the rail? (Hint: dot F with the unit vector (1, 0).)
Answer: N
Check it in “The dot product: how much do two arrows agree?”
Engineering applications
Navigation
A rover's heading towards a waypoint is atan2(dy, dx). Using a plain inverse tangent of dy/dx would send it the wrong way whenever the target lies behind and to the left.
Useful work
The work a force does on a moving cart is the dot product of force and displacement. Only the part of the force along the motion counts, so a sideways push does no work on the cart.
Summary
- A vector in the plane is a pair of components (x, y); vectors add component by component.
- The magnitude is sqrt(x^2 + y^2); the direction is atan2(y, x).
- a·b = ax·bx + ay·by = |a|·|b|·cos θ.
- A dot product of zero means the vectors are perpendicular; a negative one means they point more than 90° apart.
Glossary
- Vector addition
- Vectors are added component by component: the x parts add, the y parts add, and the result is the single vector with the same effect as both.
- Vector magnitude and direction
- A 2D vector can be written as components (x, y) or as a magnitude and a direction angle; cosine and sine convert between the two.
- Dot product
- The dot product of two vectors multiplies matching components and adds them; it also equals the product of their lengths and the cosine of the angle between them.
- Pythagoras' theorem
- In a right-angled triangle, the square of the hypotenuse equals the sum of the squares of the other two sides.
Project: Plan a three-leg route
A delivery robot drives three straight legs given as distances and headings. Convert each leg to components, add them, and give the straight-line distance and heading back to the start. Check the result by drawing the route to scale.
Deliverables
- A table of legs with components
- The total displacement, distance and heading
- A scale drawing and the difference between drawing and calculation
References
- Gilbert Strang (2016). Introduction to Linear Algebra, 5th edition. Wellesley-Cambridge Press.
- Erwin Kreyszig (2011). Advanced Engineering Mathematics, 10th edition. Wiley.
5. Matrices and transformations
A 2×2 matrix is a machine that takes in a vector and gives back a moved one. Its columns tell you where the two axis arrows land, which is enough to know where everything else goes. This chapter multiplies matrices and vectors, builds the rotation matrix from scratch, and shows why the order of two transformations matters and how to undo one.
Figure 5.1. Where the columns land (described in words)
A unit square with corners (0,0), (1,0), (1,1), (0,1) is transformed by the matrix with columns (1, 0) and (1, 1). The first axis arrow stays at (1, 0), the second moves to (1, 1), and the square becomes a parallelogram with the same area, because the determinant is 1.
Explanation
5.1 A matrix is a machine that moves vectors
Four numbers in a box can rotate, stretch, shear or flip an entire plane at once. How do they know where everything goes?
The recipe
For M = [a b; c d] and v = (x, y): M·v = (a·x + b·y, c·x + d·y). Each output component is one row of M dotted with v. A 2×2 matrix takes a 2D vector to another 2D vector.
Columns are where the axes land
M·(1, 0) = (a, c), the first column. M·(0, 1) = (b, d), the second column. Any vector (x, y) = x·(1, 0) + y·(0, 1), so M·v = x·(column 1) + y·(column 2). To design a matrix, decide where (1, 0) and (0, 1) should go and write those as columns. Grid lines stay straight, parallel and evenly spaced: that's what 'linear' means.
The determinant
det M = ad − bc is the factor by which areas change. det = 1: areas kept (rotations). det = 2: doubled. Negative: the plane is flipped over (a mirror image). det = 0: the plane is squashed onto a line or a point, information is lost, and the matrix cannot be undone.
Common mix-ups
The rows of a matrix tell you where the axes go.
✓ The columns do: column 1 is where (1, 0) lands, column 2 where (0, 1) lands.A negative determinant means the matrix shrinks things.
✓ The size of det is the area factor; the minus sign means a flip (mirror image).
5.2 The rotation matrix, built from scratch
Every robot, game engine and spacecraft turns things with the same four entries: cos, −sin, sin, cos. Where does that minus sign come from?
Using R(θ)
To rotate a point about the origin by θ (anticlockwise positive): x′ = x cos θ − y sin θ, y′ = x sin θ + y cos θ. For a clockwise rotation, use a negative θ: cos stays the same, sin changes sign. To rotate about some other pivot, shift the pivot to the origin, rotate, then shift back.
What makes it a rotation
Its columns are unit length and perpendicular to each other, so lengths and angles are kept (it is 'orthogonal'), and det = 1, so it doesn't mirror. A matrix with orthonormal columns but det = −1 is a reflection, not a rotation.
Same matrix, two stories
R(θ)·p can mean 'turn the point p by θ' or 'p is given in a frame turned by θ; here it is in the outer frame'. Both are the same calculation. Robotics uses the second story constantly: a link frame rotated by θ1 turns the link's own coordinates into the base frame's.
Derivation: Deriving R(θ)
A matrix is fixed by where it sends (1, 0) and (0, 1): those images are its columns.
Rotating (1, 0) by θ lands on the unit circle at angle θ: (cos θ, sin θ). That's column 1.
(0, 1) starts at 90°, so after rotating it is at θ + 90°: (cos(θ + 90°), sin(θ + 90°)) = (−sin θ, cos θ). That's column 2, and the source of the minus sign.
So R(θ) = [cos θ −sin θ; sin θ cos θ], and R(θ)·(x, y) = (x cos θ − y sin θ, x sin θ + y cos θ).
Check lengths: (x cos θ − y sin θ)² + (x sin θ + y cos θ)² = x²(cos² + sin²) + y²(sin² + cos²) + (cross terms that cancel) = x² + y². Lengths are kept.
Check area: det R = cos θ · cos θ − (−sin θ) · sin θ = cos²θ + sin²θ = 1. No stretching, no flipping.
Common mix-ups
The minus sign in R(θ) goes on the bottom-left entry.
✓ It goes top-right: column 2 is where (0, 1) lands, (−sin θ, cos θ). Rebuild it from a sketch if unsure.A rotation matrix rotates about any point you like.
✓ It rotates about the origin. For another pivot, translate, rotate, translate back (or use a homogeneous transform).
5.3 Order matters: composing and undoing matrices
Shear then rotate, or rotate then shear? A robot's hand ends up in a different place. Why should order matter for multiplication?
Multiplying matrices
(A·B) entry in row i, column j = row i of A · column j of B. For 2×2: [a b; c d]·[e f; g h] = [ae + bg af + bh; ce + dg cf + dh]. The product A·B means 'first B, then A', because (A·B)·v = A·(B·v): the matrix nearest the vector acts first.
Order matters
In general A·B ≠ B·A. Physical intuition: put a book flat, rotate it 90° about a vertical axis, then flip it about a front-to-back axis; now do it the other way round. Different result. Planar rotations happen to commute, R(α)R(β) = R(α + β) = R(β)R(α), but mix in a shear, a scale or 3D rotations and order becomes everything.
Undoing: the inverse
The inverse M⁻¹ satisfies M⁻¹·M = I (the identity, [1 0; 0 1]). For 2×2: M⁻¹ = (1/det)·[d −b; −c a], which exists only when det ≠ 0. For rotations it is beautifully cheap: R(θ)⁻¹ = R(−θ) = R(θ)ᵀ (swap rows and columns). Undoing a turn is turning back.
Common mix-ups
A·B is 'A first, then B'.
✓ Acting on a vector, A·B·v applies B first. Read products right to left.The inverse of a product reverses each matrix but keeps the order.
✓ (AB)⁻¹ = B⁻¹A⁻¹: undo the last thing first.
Examples to try
Worked solutions are in the interactive chapter online.
A matrix is a machine that moves vectors: example 1
Find [2 −1; 1 3]·(4, −2).
The rotation matrix, built from scratch: example 1
Rotate (3, 4) by 90° clockwise.
Order matters: composing and undoing matrices: example 1
Find the inverse of M = [2 1; 5 3] and check it.
Interactive figures, in words
Figure 5.2 from “A matrix is a machine that moves vectors”
Try each preset and describe it in words. Then choose Custom and build: (a) a matrix that triples heights only, (b) one that swaps x and y, (c) one that squashes the plane onto a line. For each, watch where the orange (1, 0) and green (0, 1) arrows land, and the determinant.
The matrix grid shows the plane before (fine grid) and after (blue grid) applying the matrix. An orange arrow shows where (1, 0) lands, a green arrow where (0, 1) lands, and a purple patch shows the transformed unit square. A test point (1.5, 1) and its image P′ are joined by a dashed arrow. The readout lists the matrix, both columns, P′ and the determinant.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Matrices (Equation Lab exploration)
Build a rotation by 90°, apply it twice and predict the result before you look.
Open online - Playground: Robotic kinematics (Playground lab)
Treat each joint as a rotation and check that changing the order of two rotations moves the tip somewhere else.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. [3 1; 0 2]·(2, 5): what is the first component?
Answer:
Check it in “A matrix is a machine that moves vectors”
2. Which matrix sends (1, 0) to (0, 2) and (0, 1) to (−1, 0)?
- [0 −1; 2 0]
- [0 2; −1 0]
- [0 −1; 0 2]
- [2 0; 0 −1]
Check it in “A matrix is a machine that moves vectors”
3. What is the determinant of [4 2; 3 1]?
Answer:
Check it in “A matrix is a machine that moves vectors”
4. Which matrix is R(90°)?
- [0 1; −1 0]
- [0 −1; 1 0]
- [1 0; 0 1]
- [−1 0; 0 −1]
Check it in “The rotation matrix, built from scratch”
5. The point (5, 12) is rotated by 73°. What is its distance from the origin afterwards?
Answer:
Check it in “The rotation matrix, built from scratch”
6. Rotate (3, 1) by 90° about the pivot (2, 1) (not the origin). What is the new y coordinate?
Answer:
Check it in “The rotation matrix, built from scratch”
7. [1 2; 3 4]·[5 6; 7 8]: what is the entry in row 2, column 1?
Answer:
Check it in “Order matters: composing and undoing matrices”
8. In A·B·v, which transformation is applied to v first?
- A
- B
- Both at once
- It depends on the determinant
Check it in “Order matters: composing and undoing matrices”
Engineering applications
Robot frames
A camera on a robot arm sees the world in its own frame. A chain of rotation (and translation) matrices converts what it sees into the frame of the robot's base.
Graphics and screens
Every rotated, scaled or sheared shape on a screen is drawn by multiplying its corner coordinates by a matrix, usually millions of times a second.
Summary
- A·v is a combination of A's columns weighted by v's components.
- The columns of A are where the axis vectors (1, 0) and (0, 1) land.
- R(θ) = [[cos θ, −sin θ], [sin θ, cos θ]] rotates by θ and keeps lengths.
- A·B means apply B first, then A; in general A·B ≠ B·A.
- The determinant is the area scale factor; zero means the matrix squashes the plane flat and cannot be undone.
Glossary
- Matrix multiplication
- Multiplying matrices combines rows of the first with columns of the second: each entry of the result is a dot product of a row and a column.
- 2D rotation matrix
- A 2D rotation by angle θ anticlockwise maps (x, y) to (x cos θ − y sin θ, x sin θ + y cos θ), written as a 2×2 matrix.
- Vector addition
- Vectors are added component by component: the x parts add, the y parts add, and the result is the single vector with the same effect as both.
Project: A two-joint arm with matrices
Compute the tip position of a two-link planar arm for three pairs of joint angles using rotation matrices. Then swap the order of the two rotations in your calculation and show, with numbers, that the answer changes.
Deliverables
- The matrices used
- Tip positions for three poses
- The swapped-order result and an explanation
References
- Gilbert Strang (2016). Introduction to Linear Algebra, 5th edition. Wellesley-Cambridge Press.
- MIT OpenCourseWare (2010). 18.06 Linear Algebra (Spring 2010). Massachusetts Institute of Technology. Link
6. Rates of change
Speed is the rate at which position changes; current is the rate at which charge flows. The derivative makes "rate at an instant" precise. This chapter builds it from the slope of a secant line between two nearby points, takes the limit as the gap shrinks, and then collects the rules (power, product and chain) that make derivatives quick to compute.
Figure 6.1. From secant to tangent (described in words)
The curve y = x^2 from x = 0 to 2. A secant line through (1, 1) and (2, 4) has slope 3. The tangent line at (1, 1) has slope 2. As the second point slides towards the first, the secant slope approaches the tangent slope.
Explanation
6.1 Limits: where is it heading?
Put x = 0 into sin(x)/x and your calculator says error. Put in 0.001 and it says 0.9999998. What is the function trying to tell you?
What a limit says
lim (x→a) f(x) = L means: you can make f(x) as close to L as you like by taking x close enough to a, from both sides, never needing x = a itself. A limit is about the trend near a point, not the value at it.
Three ways to find one
Numerically: tabulate f(a − h) and f(a + h) for h = 0.1, 0.01, 0.001 and watch both columns. Graphically: zoom in; a smooth function looks like a straight line through the point. Algebraically: simplify (factorise, cancel, expand) until substituting a no longer gives 0/0.
When numbers lie
Computers store about 16 significant digits. For tiny h, f(a + h) − f(a) loses most of its digits to rounding (catastrophic cancellation), so tables go wrong for h around 10⁻⁸ and below. Use h down to about 10⁻⁴, then confirm with algebra.
Derivation: A 0/0 limit by factorising
f(x) = (x² − 4)/(x − 2). At x = 2 this is 0/0: not defined.
Factorise the top: x² − 4 = (x − 2)(x + 2).
For every x ≠ 2, f(x) = (x − 2)(x + 2)/(x − 2) = x + 2. Cancelling is allowed precisely because x − 2 is not zero.
As x → 2, x + 2 → 4. So lim (x→2) f(x) = 4, even though f(2) does not exist. The graph is the line y = x + 2 with a single hole at (2, 4).
Common mix-ups
If substituting gives 0/0, the limit is 0 (or does not exist).
✓ 0/0 is a signal to simplify; the limit can be any number.Smaller h on a computer always gives a better estimate.
✓ Below about 10⁻⁸, rounding error swamps the result. Use moderate h and confirm with algebra.
6.2 From average speed to speed at an instant
Your phone's speedometer shows a speed at one instant. But speed is distance divided by time, and in one instant you travel no distance in no time. How?
Average rate = secant slope
Over an interval [a, a + h], the average rate of change is [f(a + h) − f(a)]/h. Graphically it is the slope of the secant line through the two points. Its units are output units per input unit: metres per second, volts per second, litres per minute.
Instantaneous rate = limit = tangent slope
The instantaneous rate at a is the limit of the average rate as h → 0. Graphically it is the slope of the tangent line, the line the curve hugs when you zoom in. Where the limit exists the function is differentiable at a. This limit is the derivative, written f′(a) or df/dt.
What the gap tells you
For a smooth curve, average minus instantaneous rate is roughly proportional to h: halve the interval, halve the error. That simple fact is what makes numerical rate estimates (week 4) and numerical integration (week 7) predictable, and it is something you can measure in the lab table.
Derivation: The average speed of a falling ball, then its limit
s(t) = 4.9t². Over the interval from t to t + h: Δs = 4.9(t + h)² − 4.9t².
Expand: 4.9(t² + 2th + h²) − 4.9t² = 9.8th + 4.9h².
Average speed = Δs/h = 9.8t + 4.9h (for h ≠ 0).
As h → 0 the second term vanishes: the instantaneous speed is v(t) = 9.8t m/s. At t = 1 s, 9.8 m/s; at 2 s, 19.6 m/s.
The gap between average and instantaneous speed is exactly 4.9h: proportional to h, just as the lab's table shows.
Common mix-ups
Instantaneous speed is 0/0, so it cannot be calculated.
✓ It is the limit of Δs/Δt as Δt → 0, which is a perfectly good number.Average speed over an interval equals the speed at its midpoint, always.
✓ That is only exactly true for quadratics like s = ct². In general they differ.
6.3 The derivative from first principles
You can find the slope of x³ at any point with nothing but algebra and one limit. Do it once properly and every derivative rule stops being magic.
The definition
f′(x) = lim (h→0) [f(x + h) − f(x)]/h. The recipe: write f(x + h), subtract f(x), simplify until you can divide every term by h, then let h → 0. If the limit exists, f is differentiable at x.
The derivative is a function
Doing the algebra with a general x gives a new function f′(x) that returns the slope at every point. For the shuttle s = t³ − 6t² + 9t, v(t) = 3t² − 12t + 9 = 3(t − 1)(t − 3), so it stops at t = 1 s and t = 3 s and moves backwards in between.
Notation
f′(x), dy/dx, ds/dt, d/dx[f]: all the same idea. Leibniz's dy/dx reminds you it came from Δy/Δx and carries units: if y is metres and x is seconds, dy/dx is metres per second. ẋ (x with a dot) is used in physics and control for a time derivative.
Derivation: Differentiating x³ from the definition
Definition: f′(x) = lim (h→0) [f(x + h) − f(x)]/h with f(x) = x³.
Expand (x + h)³ = x³ + 3x²h + 3xh² + h³ (binomial expansion).
Subtract f(x): f(x + h) − f(x) = 3x²h + 3xh² + h³.
Divide by h (h ≠ 0): 3x² + 3xh + h².
Take the limit h → 0: f′(x) = 3x². The extra terms are the secant's error, which shrinks like h.
Same steps for xⁿ: (x + h)ⁿ = xⁿ + n·xⁿ⁻¹h + (terms with h² or higher), so the derivative is n·xⁿ⁻¹: the power rule.
Common mix-ups
You can set h = 0 at the start.
✓ Setting h = 0 first gives 0/0. You must simplify and cancel h first, then take the limit.The derivative of a function is a single number.
✓ f′(a) at one point is a number; f′(x) is a whole function giving the slope everywhere.
6.4 The power rule and friends
One rule, d/dx xⁿ = n·xⁿ⁻¹, differentiates every polynomial you will ever meet. Add sin, cos and eˣ and you can differentiate most engineering models in your head.
Three rules for polynomials
Power: d/dx xⁿ = n·xⁿ⁻¹ (any real n, so √x = x^½ gives ½x^(−½)). Constant multiple: d/dx [c·f] = c·f′. Sum: d/dx [f + g] = f′ + g′. A constant on its own has derivative 0: it does not change.
Three functions to know by heart
d/dx sin x = cos x, d/dx cos x = −sin x (angles in radians), d/dx eˣ = eˣ. The sine result rests on the limit sin(h)/h → 1 from week 2; the exponential result on (eʰ − 1)/h → 1.
Reading f′ from a graph
Where f rises, f′ > 0; where it falls, f′ < 0; at peaks, troughs and flat spots, f′ = 0; where f is steepest, |f′| is largest. You can sketch f′ without any formula, and engineers do this constantly with sensor plots.
Common mix-ups
d/dx eˣ = x·eˣ⁻¹ by the power rule.
✓ The power rule is for xⁿ (variable base, fixed power). eˣ has a fixed base and variable power; its derivative is eˣ.Where f = 0, f′ = 0.
✓ Roots of f and stationary points are different things. Check the slope, not the height.
6.5 Product and chain rules
A capacitor's voltage is 12·e^(−t/2). How fast is it falling at t = 1 s? You need a rule for a function inside a function.
Product rule
d/dt [u·v] = u′·v + u·v′. Picture a rectangle of sides u and v: when both grow, the area gains a strip along each side. It is not u′·v′. Example: d/dt [t²·sin t] = 2t·sin t + t²·cos t.
Chain rule
If y = f(g(t)), then dy/dt = f′(g(t))·g′(t): the outer slope (evaluated at the inner value) times the inner slope. The workhorse cases: d/dt e^(kt) = k·e^(kt); d/dt sin(ωt) = ω·cos(ωt); d/dt (at + b)ⁿ = n·a·(at + b)ⁿ⁻¹.
Why e^(kt) matters so much
d/dt e^(kt) = k·e^(kt): the rate is k times the value. A capacitor V = V₀·e^(−t/τ) therefore falls at a rate −V/τ, proportional to the voltage left. Any quantity whose rate is proportional to itself must be an exponential: that is week 8 in one line.
Derivation: Where does t·e^(−t) peak?
f(t) = t·e^(−t) is a product of u = t and v = e^(−t). This shape models, for example, a drug concentration or the current pulse in some circuits.
u′ = 1. For v, the chain rule with inner function −t gives v′ = e^(−t)·(−1) = −e^(−t).
Product rule: f′ = u′v + uv′ = e^(−t) − t·e^(−t) = (1 − t)·e^(−t).
e^(−t) is never zero, so f′ = 0 only when 1 − t = 0: t = 1.
For t < 1, f′ > 0 (rising); for t > 1, f′ < 0 (falling): a maximum, f(1) = e⁻¹ ≈ 0.368.
Common mix-ups
(uv)′ = u′·v′.
✓ (uv)′ = u′v + uv′. Check with u = v = t: (t²)′ = 2t, but u′v′ = 1.d/dt sin(ωt) = cos(ωt).
✓ The chain rule adds a factor ω: ω·cos(ωt). Faster oscillation means bigger rates.
Examples to try
Worked solutions are in the interactive chapter online.
Limits: where is it heading?: example 1
Find lim (h→0) [(3 + h)² − 9]/h.
From average speed to speed at an instant: example 1
A tank's volume is V(t) = 2t² + 3t litres (t in minutes). Find the average filling rate from t = 2 to t = 2.1 min, then the instantaneous rate at t = 2.
The derivative from first principles: example 1
From first principles, differentiate f(x) = 5x² − x and evaluate at x = 2.
The power rule and friends: example 1
Differentiate f(x) = 4x³ − 2√x + 7 and evaluate at x = 4.
Product and chain rules: example 1
V(t) = 12·e^(−t/2) volts. Find dV/dt at t = 1 s.
Product and chain rules: example 2
Differentiate y = (3t + 1)⁴.
Interactive figures, in words
Figure 6.2 from “Limits: where is it heading?”
Start with (x² − 4)/(x − 2). Zoom in step by step: the graph flattens into a line through a hollow point. Read the table: what value do both columns approach? Repeat with sin(x)/x and (eˣ − 1)/x. Then try 1/x: what is different?
The zoom lab shows a function near a chosen point with a table of values on both sides. For (x² − 4)/(x − 2) both sides approach 4 (3.9999 and 4.0001 at h = 0.0001) and the graph has a hollow point at (2, 4). sin(x)/x and (eˣ − 1)/x both approach 1. For 1/x the values grow without bound in opposite directions.
Figure 6.3 from “From average speed to speed at an instant”
Choose the dropped ball with a = 1. Start with h = 1, then drag h smaller. Watch the orange secant swing until it lies along the curve. Read the table: by how much does the gap fall each time h shrinks tenfold? Predict the limit, then reveal the tangent.
The secant lab draws s = 4.9t² with a secant line from t = 1 to t = 1 + h. As h shrinks from 1 to 0.001 the secant slope falls from 14.7 to 9.8049 m/s, approaching the tangent slope of 9.8 m/s; the table shows the gap shrinking tenfold each time h does.
Figure 6.4 from “The power rule and friends”
Choose x³ − 3x and hide f′. Slide the point from left to right and predict, out loud, whether the slope is positive, negative or zero. Sketch f′ on paper. Then show f′ and compare. Repeat with sin x: which familiar function appears below it?
The derivative grapher shows f on top and f′ below, linked by the chosen point. For x³ − 3x, f′ = 3x² − 3 is a parabola that crosses zero at x = −1 and x = 1, exactly where f has a peak and a trough. For sin x the lower graph is cos x. The readout states the value, the slope and whether f is rising, falling or stationary.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Derivatives (Equation Lab exploration)
Shrink the step size and watch the difference quotient settle, then make it so small that rounding error takes over.
Open online - Code Lab (Studio)
Estimate a speed from logged positions with a forward and a central difference, and compare their errors.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. Find lim (x→3) (x² − 9)/(x − 3).
Answer:
Check it in “Limits: where is it heading?”
2. f(2) is not defined but lim (x→2) f(x) = 4. Which statement is true?
- That is impossible: a limit needs f(2)
- f(x) gets as close to 4 as we like for x near (but not equal to) 2
- f(2) must secretly equal 4
Check it in “Limits: where is it heading?”
3. A trolley's position is s(t) = 4.9t² + 0t metres. What is its average velocity between t = 3 s and t = 3.01 s, in m/s?
Answer: m/s
Check it in “From average speed to speed at an instant”
4. Using average speed = 9.8t + 4.9h from the derivation, what is the instantaneous speed of the ball at t = 2 s, in m/s?
Answer: m/s
Check it in “From average speed to speed at an instant”
5. From first principles, find the derivative of f(x) = x² at x = 3. (Hint: simplify [(3 + h)² − 9]/h first.)
Answer:
Check it in “The derivative from first principles”
6. The shuttle s = t³ − 6t² + 9t has v = 3t² − 12t + 9. At which time after t = 1 s does it stop again, in seconds?
Answer: s
Check it in “The derivative from first principles”
7. A joint angle follows θ(t) = 2t³ + 5t + 7 radians. Using the power rule, find the angular velocity dθ/dt at t = 1 s, in rad/s.
Answer: rad/s
Check it in “The power rule and friends”
8. The charge on a plate is Q(t) = 0.002·sin(50t) coulombs. The current is I = dQ/dt. What is I at t = 0.02 s, in amps?
Answer: A
Check it in “Product and chain rules”
Engineering applications
Velocity from encoders
A wheel encoder gives position samples. Dividing the change in position by the time between samples is a secant slope, an estimate of speed whose accuracy depends on the gap.
Finding the best setting
Where a smooth quantity such as efficiency reaches its peak, its derivative is zero. Engineers find optimum operating points by looking for that zero.
Summary
- Average rate of change over an interval is the slope of the secant line.
- The derivative f′(x) is the limit of [f(x + h) − f(x)] / h as h approaches 0: the slope of the tangent.
- Power rule: the derivative of x^n is n·x^(n−1). Derivatives of sums are sums of derivatives.
- Product rule: (uv)′ = u′v + uv′. Chain rule: the derivative of f(g(x)) is f′(g(x))·g′(x).
Glossary
- Derivative (rate of change)
- The derivative of a quantity is its instantaneous rate of change: the gradient of its graph at a point.
- Gradient of a straight line
- The gradient of a straight line is the change in y divided by the change in x between any two points on it; in y = mx + c it is m, and c is where the line crosses the y-axis.
- Equations of uniform acceleration
- When acceleration is constant, displacement, initial velocity, final velocity, acceleration and time are linked by four short equations.
Project: Speed from a position log
Record (or take from a lesson) a position log with time stamps. Estimate speed at every sample with forward and central differences, plot both, and explain where they disagree. State the sampling interval and how it limits your answer.
Deliverables
- The log with units
- Both speed estimates and a plot
- A paragraph on error and noise
References
7. Accumulation and integrals
If a derivative turns a total into a rate, an integral turns a rate back into a total: power into energy, flow into volume, speed into distance. This chapter adds up thin strips (Riemann sums), makes the sum exact with antiderivatives, and arrives at the fundamental theorem of calculus, which says the two operations undo each other.
Figure 7.1. Four strips under y = x^2 (described in words)
The curve y = x^2 from 0 to 2 with four right-endpoint rectangles of width 0.5 and heights 0.25, 1, 2.25 and 4. Their total area is 3.75, an overestimate of the exact area 8/3 ≈ 2.67.
Explanation
7.1 Riemann sums: adding up thin strips
A drone's climb rate changes every moment. How high has it gone after 4 seconds? Chop time into strips, pretend the rate is constant in each, and add.
Rate × width, added up
Split [a, b] into n strips of width Δt = (b − a)/n. In each, take one sample of the rate and multiply by Δt. Left uses the start of each strip, right the end, midpoint the middle. Each product has the units of the total: (m/s) × s = m.
Bracketing and error
For an increasing rate, left sums underestimate and right sums overestimate, so the truth lies between. Doubling n halves the left or right error (error ∝ Δt). The midpoint sum is far better: its error falls by about 4 each time n doubles (∝ Δt²).
The definite integral
As n → ∞ every rule converges to the same number, the definite integral ∫ₐᵇ f(t) dt: the exact accumulated quantity and the area under the curve (counting area below the axis as negative). The ∫ is a stretched S for 'sum' and dt recalls Δt.
Common mix-ups
The area under a velocity curve is a velocity.
✓ Area has units of height × width: (m/s) × s = metres. It is the distance.More strips always mean a different answer, so integrals are never exact.
✓ The sums converge to one exact limit: the definite integral.
7.2 Definite integrals, exactly
A thousand thin strips give 14.666 m. A million give 14.6666… Is there a way to get the exact answer without adding forever?
Antiderivatives
F is an antiderivative of f if F′ = f. Reverse the power rule: ∫tⁿ dt = tⁿ⁺¹/(n + 1) + C for n ≠ −1. Constants and sums carry through: ∫(4t³ + 2t + 5) dt = t⁴ + t² + 5t + C. Also ∫e^(kt) dt = e^(kt)/k and ∫cos t dt = sin t.
Evaluating F(b) − F(a)
∫ₐᵇ f(t) dt = F(b) − F(a), written [F(t)]ₐᵇ. The constant C cancels. For the drone: ∫₀⁴ (0.5t² + 1) dt = [t³/6 + t]₀⁴ = 64/6 + 4 = 14.667 m, the exact limit of last lesson's sums.
Signed area
Area below the axis counts as negative. ∫ of a velocity that goes negative gives displacement (net change in position), not total distance travelled. For distance, integrate |v| by splitting at the zeros. Units still multiply: A × s = C, W × s = J.
Derivation: ∫₀ᴮ t² dt from a Riemann sum
Right sum with n strips: Δt = B/n and tᵢ = iB/n for i = 1 … n.
Sum: Σ (iB/n)²·(B/n) = (B³/n³)·Σ i².
Use the formula Σᵢ₌₁ⁿ i² = n(n + 1)(2n + 1)/6.
So the sum = (B³/6)·(n + 1)(2n + 1)/n² = (B³/6)·(2 + 3/n + 1/n²).
As n → ∞ the 1/n terms vanish: ∫₀ᴮ t² dt = B³/3. That matches the antiderivative t³/3 evaluated from 0 to B.
Common mix-ups
∫ t² dt = 2t.
✓ That is the derivative. The antiderivative raises the power: t³/3.The integral of velocity is always the distance travelled.
✓ It is the displacement. For distance, integrate the speed |v|.
7.3 The fundamental theorem: slope of the total
Why should 'area under a curve' and 'slope of a curve' have anything to do with each other? The answer is the single most useful idea in calculus.
Accumulation functions
Fix a start a and let the end vary: A(x) = ∫ₐˣ f(t) dt is the total accumulated up to x. For a power trace, A(x) is the energy used so far; for a current, the charge delivered so far. A(a) = 0, and A grows wherever f is positive.
The theorem
Part 1: A′(x) = f(x). Adding a sliver from x to x + h adds about f(x)·h, so [A(x + h) − A(x)]/h → f(x). Part 2: if F is any antiderivative of f, then ∫ₐᵇ f = F(b) − F(a). Part 2 is what you used last lesson; Part 1 is why it works.
Reading graphs both ways
Where the rate f is large, the total A climbs steeply; where f = 0, A is flat (a stationary point); where f < 0, A falls. The total's slope is the rate, so every skill from week 3 (sketching f′) now runs in reverse: sketch the total from the rate.
Common mix-ups
The integral and the derivative are unrelated operations.
✓ They undo each other: d/dx ∫ₐˣ f = f, and ∫ₐᵇ f′ = f(b) − f(a).A running total is largest where the rate is largest.
✓ The total is growing fastest there; it is largest where the rate drops to zero (if the rate then goes negative).
Examples to try
Worked solutions are in the interactive chapter online.
Riemann sums: adding up thin strips: example 1
Left, right and midpoint sums for v = 0.5t² + 1 on [0, 4] with n = 4.
Definite integrals, exactly: example 1
A current I(t) = 2t + 1 A flows from t = 1 s to t = 3 s. How much charge passes?
Definite integrals, exactly: example 2
v(t) = 4 − 2t m/s from 0 to 3 s. Find the displacement and the distance travelled.
The fundamental theorem: slope of the total: example 1
A(x) = ∫₀ˣ 3t² dt. Find A(x) and A′(2).
Interactive figures, in words
Figure 7.2 from “Riemann sums: adding up thin strips”
Choose the drone climb rate, rule Left and n = 4. Read the estimate. Switch to Right and Midpoint. Then double n repeatedly: by what factor does the left-sum error shrink each time? What about the midpoint error?
The accumulator draws rectangles under the drone climb-rate curve. With 4 left strips the estimate is 11 m against an exact 14.67 m; right strips give 19 m; midpoint 14.5 m. Doubling the strips halves the left and right errors and quarters the midpoint error, as the readout's error ratio shows.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Integrals (Equation Lab exploration)
Increase the number of strips and record how the error shrinks each time you double them.
Open online - Code Lab (Studio)
Integrate a logged power trace to find the energy used, and give the answer in joules and watt-hours.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. A drone's climb rate is v(t) = 2t² + 0 m/s. Estimate the height gained from t = 0 to t = 4 s with a midpoint Riemann sum of 6 equal strips, in metres.
Answer: m
Check it in “Riemann sums: adding up thin strips”
2. Right Riemann sum of v = 0.5t² + 1 m/s on [0, 4] with 4 strips, in metres.
Answer: m
Check it in “Riemann sums: adding up thin strips”
3. A tank drains with an outflow rate that decreases over time. A left Riemann sum of the outflow will…
- underestimate the water lost
- overestimate the water lost
- be exact
Check it in “Riemann sums: adding up thin strips”
4. Find the exact distance travelled (velocity in m/s) from t = 1 s to t = 5 s when v(t) = -1t² + 1t + 10.
Answer: m
Check it in “Definite integrals, exactly”
5. Find ∫₀⁴ (0.5t² + 1) dt exactly, in metres (3 decimal places).
Answer: m
Check it in “Definite integrals, exactly”
6. ∫₀⁶ v(t) dt = 0 for a robot's velocity. What can you conclude?
- The robot never moved
- The robot ended where it started
- The robot travelled 0 m in total
Check it in “Definite integrals, exactly”
7. A(x) = ∫₀ˣ 3t² dt. What is A′(2)?
Answer:
Check it in “The fundamental theorem: slope of the total”
8. Which statement is the fundamental theorem (Part 1)?
- d/dx ∫ₐˣ f(t) dt = f(x)
- ∫ f′ = f′
- Every function has an integral equal to its area
Check it in “The fundamental theorem: slope of the total”
Engineering applications
Battery energy
A drone's battery monitor samples power several times a second. Summing power × time step gives the energy used so far, which is how the remaining flight time is estimated.
Charge from current
The charge delivered by a varying current is the integral of current over time. A current of 2 A for 30 minutes delivers 3600 C, which is 1 A·h.
Summary
- A Riemann sum adds rate × width over thin strips; left and right sums bracket the true value for a monotonic function.
- The definite integral is the limit of Riemann sums as the strips get thinner.
- If F′ = f, then the integral of f from a to b equals F(b) − F(a).
- Area below the axis counts as negative: the integral is signed.
Glossary
- Integral as accumulated area
- An integral adds up a rate over time: the area under a rate graph gives the total accumulated amount.
- Work done by a force
- Work is the energy transferred when a force moves something: the force multiplied by the distance moved in the direction of the force.
- Battery capacity and runtime
- A battery's capacity in ampere-hours says how long it can supply a current; multiplied by its voltage it gives stored energy in watt-hours.
Project: An energy audit
Log (or take from a lesson) the power drawn by a device over a working cycle. Integrate it with the trapezoid rule, express the energy in joules and watt-hours, and estimate how long a stated battery would last.
Deliverables
- The power log with units
- The integration and result
- Battery-life estimate with its main assumptions
References
8. Differential equations
Many machines are described not by a formula for their output but by a rule for how it changes: the rate of cooling depends on the temperature difference, a spring's acceleration depends on its stretch. This chapter writes those rules as differential equations, solves the simplest ones by hand, and steps the rest forward numerically with Euler's method and RK4, watching for error and instability.
Figure 8.1. Euler's method against the exact decay (described in words)
The exact solution y = e^(−t/τ) of dy/dt = −y/τ, starting at 1, plotted from t = 0 to 2τ. Euler steps of size h = 0.5τ give 1, 0.5, 0.25, 0.125, 0.0625. At t = τ the exact value is about 0.368 and Euler gives 0.25.
Explanation
8.1 Rate equations and exponential decay
A hot drink cools fastest when it is hottest. A capacitor discharges fastest when it is fullest. Write that sentence as an equation and the solution writes itself.
Writing the equation
RC discharge: the current through R is V/R and it drains the capacitor: C·dV/dt = −V/R, so dV/dt = −V/(RC), τ = RC. Newton's cooling: heat flow is proportional to the temperature difference, so dT/dt = −k(T − Tₐ). Both: rate ∝ distance from equilibrium.
The time constant
τ (seconds or minutes) sets the speed. After 1τ, 37% of the initial difference remains; after 3τ, 5%; after 5τ, under 1%. Engineers call a first-order system 'settled' after about 4–5τ. For R = 10 kΩ and C = 100 µF, τ = 1 s.
Why the solution must be exponential
Only one family has a rate proportional to its value: e^(kt), from week 3's chain rule. So once you see 'rate ∝ amount', you can write the exponential solution straight away, then fit k (week 9). The equation also gives the units: k is per second, so kt has no units, as an exponent must.
Derivation: Solving dy/dt = −ky
Model: the rate of decrease is proportional to the amount: dy/dt = −k·y, k > 0, with y(0) = y₀.
Separate variables (for y > 0): (1/y) dy = −k dt.
Integrate both sides: ln y = −kt + C.
Exponentiate: y = e^C·e^(−kt). At t = 0, y = e^C = y₀, so y(t) = y₀·e^(−kt).
Check by differentiating: dy/dt = y₀·(−k)·e^(−kt) = −k·y ✓.
Time constant τ = 1/k: y(τ) = y₀e⁻¹ ≈ 0.368y₀. Half-life: e^(−kt) = ½ gives t½ = ln 2/k = τ·ln 2.
Cooling: let u = T − Tₐ; then du/dt = dT/dt = −k·u, so T(t) = Tₐ + (T₀ − Tₐ)e^(−kt).
Common mix-ups
After one time constant the quantity has halved.
✓ After τ it is at 37%; it halves after τ·ln 2 ≈ 0.69τ.The drink cools towards 0 °C.
✓ It cools towards the room temperature Tₐ: only the difference decays.
8.2 Euler's method and step-size error
Most differential equations have no formula solution. So computers cheat: take the slope now, step forward a little, repeat. When does that cheating go badly wrong?
The method
Know the state yₙ at time tₙ. Compute the slope f(tₙ, yₙ) from the equation. Step: yₙ₊₁ = yₙ + h·f(tₙ, yₙ), tₙ₊₁ = tₙ + h. Repeat. That is all, and it is exactly how the week 4 forward difference is used in reverse.
Accuracy: first order
Euler's global error ∝ h. To get ten times more accurate, take ten times more steps. Check any simulation by halving h: if the answer changes noticeably, the step was too large. Better methods (such as Runge–Kutta) reach error ∝ h⁴ for a little more work per step.
Stability: a separate danger
Accuracy and stability are different. Too large a step can make a decaying system grow without limit. For dy/dt = −y/τ the limit is h < 2τ, and smooth results need h < τ. Fast processes (small τ) therefore force small steps even when you only care about slow ones.
Derivation: Euler's step factor, its error and its stability limit
For dy/dt = −k·y, one Euler step gives yₙ₊₁ = yₙ + h·(−k·yₙ) = (1 − kh)·yₙ.
The exact solution multiplies by e^(−kh) = 1 − kh + (kh)²/2 − … each step. The difference per step is about (kh)²/2: the local error ∝ h².
To reach a fixed time T takes T/h steps, so the errors add to about (T/h)·h² ∝ h: the global error is first order. Halve h, halve the error.
After n steps yₙ = y₀(1 − kh)ⁿ. This decays only if |1 − kh| < 1, that is 0 < kh < 2, or h < 2τ.
For 1 < kh < 2 the factor is negative: the numerical solution overshoots zero every step while shrinking. For kh > 2 it grows without bound: numerical instability, not physics.
Common mix-ups
If a simulation blows up, the physical system is unstable.
✓ It may be numerical instability from too large a step. Halve h and see if it persists.A stable simulation is an accurate one.
✓ Stable only means it does not explode. Accuracy needs a convergence check.
8.3 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?
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.
Derivation: Solving m x″ + c x′ + k x = 0
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.
So r solves the characteristic equation m r² + c r + k = 0: r = (−c ± √(c² − 4mk)) / (2m).
Write ω_n = √(k/m) and ζ = c/(2√(km)). Then r = −ζω_n ± ω_n√(ζ² − 1).
ζ > 1 (overdamped): two negative real roots, x = A e^{r₁t} + B e^{r₂t}. ζ = 1 (critical): x = (A + Bt) e^{−ω_n t}.
ζ < 1 (underdamped): r = −ζω_n ± iω_d with ω_d = ω_n√(1 − ζ²), so x = e^{−ζω_n t}(A cos ω_d t + B sin ω_d t).
A and B come from the initial position and velocity. By linearity, any combination of solutions is a solution (week 1).
Common mix-ups
More damping always makes a system settle faster.
✓ Beyond critical damping, it creeps more slowly. Fastest settling without overshoot is at ζ = 1.The damped frequency equals the natural frequency.
✓ ω_d = ω_n√(1 − ζ²) is a little lower, noticeably so for large ζ.
8.4 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?
The three methods
For y′ = f(t, y):
- Explicit Euler: yₙ₊₁ = yₙ + h f(tₙ, yₙ). One slope, at the start.
- Semi-implicit (symplectic) Euler for x′ = v, v′ = a(x): vₙ₊₁ = vₙ + h a(xₙ), then xₙ₊₁ = xₙ + h vₙ₊₁.
- RK4: k₁ = f(tₙ, yₙ), k₂ = f(tₙ + h/2, yₙ + h k₁/2), k₃ = f(tₙ + h/2, yₙ + h k₂/2), k₄ = f(tₙ + h, yₙ + h k₃); yₙ₊₁ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄).
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.
Derivation: Why explicit Euler gains energy on the oscillator
Write x″ = −x as x′ = v, v′ = −x. Energy E = ½(x² + v²) is exactly conserved by the true solution.
Explicit Euler: xₙ₊₁ = xₙ + h vₙ, vₙ₊₁ = vₙ − h xₙ.
Then xₙ₊₁² + vₙ₊₁² = xₙ² + 2h xₙvₙ + h²vₙ² + vₙ² − 2h xₙvₙ + h²xₙ² = (1 + h²)(xₙ² + vₙ²).
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.
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).
Common mix-ups
If the simulation looks smooth, it is accurate.
✓ Euler's spiral looks smooth and is completely wrong about energy. Compare with an exact or converged answer.Higher order always wins.
✓ It wins on accuracy for smooth problems; structure (energy, stability) can matter more over long times.
Examples to try
Worked solutions are in the interactive chapter online.
Rate equations and exponential decay: example 1
R = 10 kΩ, C = 100 µF, V(0) = 9 V. Find τ and V at 2 s.
Euler's method and step-size error: example 1
dV/dt = −V/2, V(0) = 5 V, h = 0.5 s. Take two Euler steps.
Linear ODEs you can solve by hand: example 1
m = 2 kg, k = 50 N/m, c = 4 N·s/m. Find ω_n, ζ and ω_d.
Euler, semi-implicit Euler and RK4: example 1
One explicit Euler step for x′ = v, v′ = −x from (1, 0) with h = 0.1.
Interactive figures, in words
Figure 8.2 from “Rate equations and exponential decay”
Choose the capacitor data. Turn on the log view: the points should lie on a straight line. Adjust k until the model line matches, then press Best fit. Read τ and the half-life. Why is ln(V) straight when V is curved?
In the decay-fit lab the capacitor readings fall from 9 V towards zero. In the log view, ln V against time is a straight line whose slope is −k; the best fit gives k close to 0.45 per second, so τ ≈ 2.2 s and a half-life of about 1.5 s. The readout states k, τ, half-life and the RMS error.
Figure 8.3 from “Euler's method and step-size error”
Start with τ = 2 and h = 0.5: read the error table and its ratio. Now try h = 1, 2, 2.5 and watch the regime change from smooth, to overshooting, to oscillating forever, to unstable. Change τ: does the boundary move with h/τ?
The Euler lab plots the exact exponential decay with Euler's points. With τ = 2 and h = 0.5 the points track the curve slightly low and the error halves when h halves. At h = 3 they zigzag about zero while shrinking; at h = 4 they oscillate with constant size; at h = 5 they zigzag and grow. The readout names the regime from h/τ.
Figure 8.4 from “Linear ODEs you can solve by hand”
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.
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).
Figure 8.5 from “Euler, semi-implicit Euler and RK4”
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.
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.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: First-order systems (Equation Lab exploration)
Change the time constant and check that the response reaches about 63 % of its final value after one τ.
Open online - Equation Lab: Oscillator (Equation Lab exploration)
Vary the damping ratio and classify each response as under-, critically or over-damped.
Open online - Simulation OS: RC charge and discharge (Simulation OS experiment)
Compare the simulated capacitor voltage with the exact exponential at three times.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. A cooling temperature difference halves every 12 minutes. What is its time constant τ, in minutes?
Answer: min
Check it in “Rate equations and exponential decay”
2. What percentage of the initial value remains after 5 time constants?
Answer: %
Check it in “Rate equations and exponential decay”
3. dV/dt = −V/τ with τ = 2 s and V(0) = 5 V. One Euler step of h = 0.5 s gives what V, in volts?
Answer: V
Check it in “Euler's method and step-size error”
4. For dy/dt = −y/τ with τ = 2 s, what is the largest Euler step (in seconds) that does not blow up?
Answer: s
Check it in “Euler's method and step-size error”
5. A mass–spring–damper has m = 2 kg, k = 8 N/m, c = 4 N·s/m. What is its damping ratio ζ?
Answer:
Check it in “Linear ODEs you can solve by hand”
6. For m = 1 kg and k = 9 N/m, what damping gives critical damping?
- c = 3
- c = 6
- c = 9
Check it in “Linear ODEs you can solve by hand”
7. Explicit Euler on x″ = −x with h = 0.05: by what factor does the energy grow per step?
Answer:
Check it in “Euler, semi-implicit Euler and RK4”
8. 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
Check it in “Euler, semi-implicit Euler and RK4”
Engineering applications
Simulators
Every physics engine and circuit simulator steps differential equations forward. Choosing the method and step size is a trade between accuracy, stability and computing time.
Suspension and control tuning
The damping ratio of a mass–spring–damper decides whether a vehicle's suspension bounces or settles smoothly. The same second-order model describes many feedback loops.
Summary
- dy/dt = −y/τ has the solution y = y0·e^(−t/τ); after one τ about 37 % remains, after 5τ less than 1 %.
- Euler's method: y(n+1) = y(n) + h·f(t(n), y(n)). Its error per unit time shrinks in proportion to h (first order).
- For decay, Euler is stable only if h < 2τ; a large step can make the numbers explode.
- A second-order system's behaviour is set by its natural frequency ωn and damping ratio ζ.
- RK4 uses four slope evaluations per step and is fourth-order accurate; symplectic methods conserve energy better over long runs.
Glossary
- Exponential growth and decay
- A quantity decays exponentially when its rate of decrease is proportional to how much is left, giving y = y0 × e^(−t/τ).
- First-order system and time constant
- A first-order system responds to a step by approaching its new value exponentially; its time constant τ is the time to cover 63.2 % of the change.
- RC time constant
- When a capacitor charges or discharges through a resistor, the voltage changes exponentially with time constant τ = R × C.
- Damping ratio
- The damping ratio ζ describes how quickly oscillations die out in a second-order system: below 1 it oscillates, exactly 1 is critically damped, above 1 it creeps to the target without overshoot.
- Hooke's law (springs)
- For a spring within its elastic limit, the force needed to stretch or compress it is proportional to the change in length: F = k × x.
Project: How small a step?
Simulate a cooling model dT/dt = −(T − Ta)/τ with Euler's method for three step sizes, compare each with the exact solution, and find the largest step that keeps the error below 1 °C over the run. Repeat with RK4 and compare the cost.
Deliverables
- The model with parameter values and units
- Error tables for each step size and method
- The chosen step size with justification
References
- William E. Boyce and Richard C. DiPrima (2012). Elementary Differential Equations and Boundary Value Problems, 10th edition. Wiley.
- J. C. Butcher (2016). Numerical Methods for Ordinary Differential Equations, 3rd edition. Wiley.
- Erwin Kreyszig (2011). Advanced Engineering Mathematics, 10th edition. Wiley.
9. Probability and uncertainty
Sensors are noisy, parts are sometimes faulty and tests sometimes lie. Probability lets engineers reason about all of that with numbers. This chapter counts its way through Bayes' rule, defines expectation and variance, meets the three distributions that turn up most often (binomial, Poisson and normal) and shows, by simulation, why averages of many readings become normal.
Figure 9.1. A fault test in natural frequencies (described in words)
A tree starting with 10,000 parts. 100 are faulty and 9,900 are good. The test flags 90 of the 100 faulty parts and 495 of the 9,900 good ones. Of the 585 flagged parts, only 90 are faulty: about 15 %.
Explanation
9.1 Conditional probability, Bayes and base rates
A detector catches 90% of faults and false-alarms only 5% of the time. A part is flagged. Is it probably faulty?
Events and conditions
An event is something that does or doesn't happen: 'faulty', 'flagged'. P(F) is its probability over all parts. A conditional probability P(F | +) restricts attention to the cases where + happened. Reading '|' as 'among those that' keeps it straight: the share faulty among those that were flagged.
Count, don't juggle formulas
The safest way to apply Bayes' rule is a frequency tree: pick a population (10,000 is convenient), split it by the base rate, then split each branch by the detector's rates, and finally compare the branches that match the evidence. The formula and the counts give the same answer; the counts are harder to get wrong.
Base rates rule
When the condition is rare, false alarms from the huge 'good' group can outnumber real detections from the tiny 'faulty' group. Two remedies: reduce the false-positive rate, or confirm a flag with a second, independent check, using the first answer as the new base rate. Independence is an assumption: two sensors fooled by the same glare are not independent.
Derivation: Bayes' rule from a frequency table
Events: F = 'part is faulty', + = 'detector flags it'. P(A | B) means 'the probability of A among the cases where B happened'.
Imagine N parts. Faulty: N·P(F). Of those, flagged: N·P(F)·P(+ | F).
Good: N·(1 − P(F)). Of those, flagged: N·(1 − P(F))·P(+ | not F).
Among all flagged parts, the share that are faulty is P(F | +) = N·P(F)·P(+ | F) ÷ [N·P(F)·P(+ | F) + N·(1 − P(F))·P(+ | not F)].
N cancels. The denominator is P(+), the overall chance of a flag. So P(F | +) = P(+ | F)·P(F) ÷ P(+): Bayes' rule.
Numbers: P(F) = 0.01, P(+ | F) = 0.9, P(+ | not F) = 0.05: P(F | +) = 0.009 ÷ (0.009 + 0.0495) = 0.009 ÷ 0.0585 ≈ 0.154.
P(F | +) and P(+ | F) are different questions: 15% versus 90%. Confusing them is called the base-rate fallacy.
Common mix-ups
If a test is 95% accurate, a positive result is 95% likely to be right.
✓ That depends on the base rate. For rare conditions a positive can still be more likely wrong than right.Two checks always multiply the evidence.
✓ Only if their errors are independent. Checks fooled by the same cause add little.
9.2 Random variables, expectation and variance
A rover's camera finds its landmark 7 times in 10. Is that a good camera or a lucky day? First we need a number for 'how much does this wobble'.
A random variable is a number from chance
A random variable X assigns a number to each outcome of an experiment: the number of sightings in 10 tries, the error of one range reading. A discrete X has a probability mass function p(x) = P(X = x), with every p(x) ≥ 0 and Σ p(x) = 1.
Expectation: the balance point
E[X] = Σ x·p(x). It is the long-run average over many repeats, not necessarily a value X can take (a die never shows 3.5). Expectation is linear: E[aX + bY + c] = aE[X] + bE[Y] + c, even if X and Y are dependent.
Variance: the typical squared wobble
Var(X) = E[(X − μ)²] = E[X²] − (E[X])², and the standard deviation σ = √Var(X) has the same units as X. Shifting X does not change its spread, scaling does: Var(aX + b) = a²·Var(X). For independent X and Y, Var(X + Y) = Var(X) + Var(Y): variances add, standard deviations do not.
Common mix-ups
The expected value is the most likely value.
✓ It is the long-run average. A die's expectation, 3.5, is impossible on any single roll.Independent errors add up linearly.
✓ Their variances add, so σ grows like √n. Only biases add linearly.
9.3 Binomial, Poisson and normal
Counting sightings, counting cosmic-ray hits, measuring a range: three different questions, three distributions engineers reach for again and again.
Binomial: n tries, fixed p
X = number of successes in n independent trials with the same probability p. P(X = k) = C(n, k)·pᵏ(1 − p)ⁿ⁻ᵏ, mean np, variance np(1 − p). Landmark sightings in 10 attempts are binomial if each attempt is independent; dust storms that come in bursts break that assumption.
Poisson: rare events in time
X = number of events in an interval when they happen independently at a steady average rate λ. P(X = k) = e^(−λ)λᵏ/k!, mean λ, variance λ. Bit-flips from radiation, micrometeoroid hits and photon counts in a star tracker pixel are classic Poisson counts.
Normal: sums of many small effects
Density f(x) = (1/(σ√(2π)))·exp(−(x − μ)²/(2σ²)). To find a probability, standardise with z = (x − μ)/σ and look up Φ(z) = P(Z < z): Φ(1) ≈ 0.8413, Φ(1.645) ≈ 0.95, Φ(1.96) ≈ 0.975. Binomial and Poisson both look normal once their mean and variance are large (roughly ≥ 5–10).
Common mix-ups
Any count is binomial.
✓ Binomial needs a fixed n, independent trials and a constant p. Events at a rate with no natural n are Poisson; bursty events are neither.Normal probabilities need integration every time.
✓ Standardise to z and use Φ: a z-table (or Φ function) is that integral done once for everyone.
9.4 The central limit theorem by simulation
A reading that is either 0 or 10 looks nothing like a bell curve. Average 30 of them and, astonishingly, a bell curve appears. Why?
The theorem
If X₁, …, Xₙ are independent with the same mean μ and finite variance σ², then the sample mean X̄ has mean μ and standard deviation σ/√n, and as n grows its distribution approaches Normal(μ, σ²/n) whatever the shape of the Xᵢ.
How big must n be?
For symmetric populations (uniform, a die) n ≈ 5 already looks normal. Skewed or lumpy populations need more: the 0/10 population still looks lopsided at n = 10 and is close to normal by n = 30–100. Heavy-tailed noise with infinite variance never obeys the theorem.
Standard error
σ/√n is the standard error of the mean. It is what makes averaging a powerful but slow tool: 100 readings give 10× precision, 10,000 give 100×. It only shrinks random error; a bias shared by every reading survives any amount of averaging.
Common mix-ups
The CLT says the data become normal if you collect enough.
✓ The data keep their shape. It is the distribution of the sample MEAN that becomes normal.Averaging fixes all errors.
✓ It shrinks independent random error like 1/√n and does nothing to a shared bias.
Examples to try
Worked solutions are in the interactive chapter online.
Conditional probability, Bayes and base rates: example 1
Base rate 10%, sensitivity 80%, false positives 10%. P(faulty | flagged)?
Random variables, expectation and variance: example 1
X takes values 0, 1, 2, 3 with probabilities 0.1, 0.2, 0.3, 0.4. Find E[X] and Var(X).
Random variables, expectation and variance: example 2
Each of 25 independent wheel steps has error with σ = 2 cm and mean 0. What is the σ of the total error?
Binomial, Poisson and normal: example 1
Landmark sightings succeed with p = 0.8 independently. Probability of exactly 8 in 10?
Binomial, Poisson and normal: example 2
Range readings are normal with μ = 50 m, σ = 2 m. What is P(reading < 47 m)?
The central limit theorem by simulation: example 1
A gyro sample has σ = 0.8 °/s. How many samples must be averaged for SE = 0.1 °/s?
Interactive figures, in words
Figure 9.2 from “Conditional probability, Bayes and base rates”
Start at base rate 1%, sensitivity 90%, false positives 5%. Read the counts in each branch and check the answer by hand. Then raise the base rate to 20%. Then go back to 1% and halve the false-positive rate. Which change helps the flags most? Finally, try 'tested a second time'.
The base-rate tree splits 10,000 parts by base rate into faulty and good, then each into flagged and not flagged. At base rate 1%, sensitivity 90% and false positives 5%: 100 faulty (90 flagged, 10 missed) and 9,900 good (495 flagged, 9,405 passed). P(faulty | flagged) = 90 ÷ 585 ≈ 15.4%. A second independent flag raises it to about 77%.
Figure 9.3 from “Binomial, Poisson and normal”
Start with Binomial n = 10, p = 0.3 and move the threshold to see P(X ≤ x). Then raise n to 40: when do the bars look normal? Switch to Poisson and check that mean = variance. Finally use the normal curve to find the area within ±2σ.
The distribution explorer draws bars (binomial, Poisson) or a curve (normal, uniform) with a movable threshold. Its readout states the mean, variance and P(X ≤ x) in words, so every number can be followed without the picture.
Figure 9.4 from “The central limit theorem by simulation”
Pick the skewed 0/10 population with n = 1: no bell. Step n through 2, 5, 10, 30. Record the observed spread each time and compare with σ/√n. Then try the exponential population and press 'draw' a few times to see run-to-run variation.
The simulator draws 1,000 sample means as a histogram with the predicted normal curve over it. The readout states the observed mean and spread beside σ/√n, so the result can be read entirely as numbers.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Distributions (Equation Lab exploration)
Change the sample size and watch the spread of the sample mean shrink like 1/sqrt(n).
Open online - Simulation OS: Two-sensor fusion (Simulation OS experiment)
Combine two noisy sensors and check that the fused variance is smaller than either one.
Open online - Playground: Sensor fusion (Playground lab)
Compare each sensor's error with the fused estimate while the camera drops out.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. Out of 1000 parts, 20 are faulty and flagged and 60 are good but flagged. What is P(faulty | flagged), as a percentage?
Answer: %
Check it in “Conditional probability, Bayes and base rates”
2. P(flagged | faulty) = 0.95. Which statement follows?
- P(faulty | flagged) = 0.95
- Nothing about P(faulty | flagged) without the base rate and false-positive rate
- P(faulty | flagged) = 0.05
Check it in “Conditional probability, Bayes and base rates”
3. What is the variance of 3X + 5, where X is one roll of a fair die (Var(X) = 35/12)?
Answer:
Check it in “Random variables, expectation and variance”
4. Which statement is true for ANY two random variables X and Y?
- E[X + Y] = E[X] + E[Y]
- Var(X + Y) = Var(X) + Var(Y)
- E[XY] = E[X]E[Y]
- σ(X + Y) = σ(X) + σ(Y)
Check it in “Random variables, expectation and variance”
5. Which count is best modelled as Poisson?
- Heads in 20 coin flips
- Cosmic-ray memory upsets in one hour
- Correct answers in a 10-question quiz
- The height of a rover's mast
Check it in “Binomial, Poisson and normal”
6. A camera succeeds with p = 0.25 on each of n = 40 independent attempts. What is the variance of the number of successes?
Answer:
Check it in “Binomial, Poisson and normal”
7. Readings have σ = 4 mm. How many must be averaged to get a standard error of 0.5 mm?
Answer:
Check it in “The central limit theorem by simulation”
8. Which condition is essential for the CLT as stated in this lesson?
- The readings are normally distributed
- The readings have finite variance and are independent
- n is at least 1000
- The population is symmetric
Check it in “The central limit theorem by simulation”
Engineering applications
Quality control
When faults are rare, even a good test flags more good parts than faulty ones, as the figure shows. Factories confirm flagged parts with a second, independent check before rejecting them.
Averaging sensor readings
Averaging n independent readings divides the standard deviation of the noise by sqrt(n). Four readings halve it; a hundred cut it to a tenth, at the cost of time.
Summary
- P(A | B) is the probability of A among the cases where B happened; it is not the same as P(B | A).
- Counting natural frequencies (out of 10,000, say) is the safest way to apply Bayes' rule.
- E[aX + b] = a·E[X] + b and Var(aX + b) = a^2·Var(X); variances of independent variables add.
- Binomial: n tries with fixed p. Poisson: counts of rare events in a fixed time. Normal: sums of many small effects.
- The sample mean of n independent readings has standard error σ/sqrt(n), and its distribution becomes close to normal as n grows.
Glossary
- Mean and median
- The mean is the sum of the values divided by how many there are; the median is the middle value once the values are sorted.
- Standard deviation
- Standard deviation measures how spread out values are around their mean: the square root of the average squared distance from the mean.
- Standard error of the mean
- The standard error of the mean estimates how much a sample mean would vary between repeated experiments: the sample standard deviation divided by the square root of the number of readings.
- Random and systematic error
- Random errors scatter readings unpredictably above and below the true value; systematic errors shift every reading the same way.
Project: Is the alarm worth trusting?
A smoke alarm detects 95 % of real fires and false-alarms on 1 % of ordinary days; real fires happen on 1 day in 10,000. Use natural frequencies to find how often an alarm means a real fire, then propose a second check that would raise that figure and show the new calculation.
Deliverables
- A frequency tree with every count
- P(fire | alarm) before and after your second check
- A sentence on the cost of a missed fire versus a false alarm
References
- Joseph K. Blitzstein and Jessica Hwang (2019). Introduction to Probability, 2nd edition. CRC Press.
- Barbara Illowsky and Susan Dean (2013). Introductory Statistics. OpenStax. Link
10. Linear systems
Circuits, structures and fitted models all lead to many linear equations in many unknowns, written A·x = b. This chapter reads A·x as a combination of A's columns, uses rank to decide whether there is one solution, none or infinitely many, and solves systems the way computers do: Gaussian elimination, back substitution and the LU factorisation that lets one elimination serve many right-hand sides.
Figure 10.1. Two equations, one crossing (described in words)
Two straight lines on a grid: 2x + y = 5 and x − y = 1. They cross at the single point (2, 1), which is the unique solution of the system.
Explanation
10.1 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?
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.
Common mix-ups
Two vectors in the plane always span the plane.
✓ Only if they are not parallel (det ≠ 0). Parallel vectors span a line.A vector space means arrows.
✓ Any set closed under addition and scaling counts, including lists of sensor readings and solutions of linear ODEs.
10.2 Rank: one, none or infinitely many
Three equations, three unknowns, and yet no answer at all. How can counting fail?
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.
- rank A < rank [A | b]: a row reads 0 = non-zero, so no solution.
- rank A = rank [A | b] = n: unique solution.
- rank A = rank [A | b] < n: infinitely many, with n − r free variables.
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.
Common mix-ups
n equations in n unknowns always have exactly one solution.
✓ Only if the equations are independent (rank n). Dependent equations give none or infinitely many.A row of zeros means no solution.
✓ A row (0 … 0 | 0) is harmless; (0 … 0 | c) with c ≠ 0 means no solution.
10.3 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?
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.
Derivation: Elimination is A = LU
Subtracting ℓ₂₁ × row 1 from row 2 is left-multiplication by E₂₁ = I − ℓ₂₁e₂e₁ᵀ (the identity with −ℓ₂₁ in position (2, 1)).
Forward elimination is a product of such matrices: E₃₂E₃₁E₂₁·A = U, upper triangular.
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).
Therefore A = LU. To solve Ax = b, solve Ly = b by forward substitution, then Ux = y by back substitution.
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.
Common mix-ups
To solve Ax = b on a computer, compute A⁻¹ and multiply.
✓ Factorise and use triangular solves: cheaper and more accurate.Row swaps change the solution.
✓ Swapping equations does not change which x satisfies them.
Examples to try
Worked solutions are in the interactive chapter online.
Vectors, combinations and span: example 1
Is b = (1, 5) a combination of a₁ = (2, 1) and a₂ = (−1, 1)?
Vectors, combinations and span: example 2
Are (1, 2, 3), (2, 3, 4) and (3, 5, 7) independent?
Rank: one, none or infinitely many: example 1
Solve x₁ + x₂ + x₃ = 6, x₁ + 2x₂ + 3x₃ = 14, 2x₁ + 3x₂ + 4x₃ = 20.
Gaussian elimination, back substitution and LU: example 1
Solve 2x₁ + x₂ − x₃ = 8, −3x₁ − x₂ + 2x₃ = −11, −2x₁ + x₂ + 2x₃ = −3.
Interactive figures, in words
Figure 10.2 from “Vectors, combinations and span”
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.
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.
Figure 10.3 from “Rank: one, none or infinitely many”
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.
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.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Matrices (Equation Lab exploration)
Make the two columns of a matrix parallel and see the transformed grid collapse onto a line.
Open online - Code Lab (Studio)
Write Gaussian elimination for a 3×3 system and check your answer by multiplying A by x.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
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
Check it in “Vectors, combinations and span”
2. Find x₂ so that x₁(1, 1) + x₂(1, −1) = (5, 1).
Answer:
Check it in “Vectors, combinations and span”
3. 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)
Check it in “Rank: one, none or infinitely many”
4. A 4×6 matrix has rank 3. What is the dimension of its null space?
Answer:
Check it in “Rank: one, none or infinitely many”
5. In A = [[2, 1, −1], [−3, −1, 2], [−2, 1, 2]], what multiplier ℓ₂₁ clears the (2, 1) entry?
Answer:
Check it in “Gaussian elimination, back substitution and LU”
6. Solve A·x = b with A = [[-2, 3, -2], [-2, 3, 4], [-3, 4, -3]] and b = (-11, 7, -15). What is x3?
Answer:
Check it in “Gaussian elimination, back substitution and LU”
7. 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²
Check it in “Gaussian elimination, back substitution and LU”
8. Factorising costs about (2/3)n³ operations. Roughly how many times longer does n = 2000 take than n = 1000?
Answer:
Check it in “Gaussian elimination, back substitution and LU”
Engineering applications
Circuit analysis
Kirchhoff's current law at each node of a resistor network gives one linear equation per node. Solving A·x = b gives every node voltage at once, which is what circuit simulators do.
Structures
The forces in a truss satisfy one balance equation per joint and direction. If the rank is too low the structure is a mechanism and can move; engineers check rank before trusting a design.
Summary
- A·x = b asks which combination of A's columns makes b.
- Rank is the number of independent columns; comparing rank(A) with rank([A | b]) decides one, none or infinitely many solutions.
- Gaussian elimination reduces A to upper-triangular form; back substitution then solves from the bottom up.
- A = L·U stores the elimination, so new right-hand sides cost far less than a fresh elimination; pivoting avoids dividing by small numbers.
Glossary
- Matrix multiplication
- Multiplying matrices combines rows of the first with columns of the second: each entry of the result is a dot product of a row and a column.
- Kirchhoff's current law (KCL)
- At any junction in a circuit, the total current flowing in equals the total current flowing out.
- Vector addition
- Vectors are added component by component: the x parts add, the y parts add, and the result is the single vector with the same effect as both.
Project: Solve a resistor network
Choose a resistor network with three unknown node voltages. Write the node equations as A·x = b, solve them by elimination by hand, check with code, and confirm the currents at one node add to zero.
Deliverables
- The circuit with values
- The matrix equation
- Hand and code solutions
- A current check at one node
References
- Gilbert Strang (2016). Introduction to Linear Algebra, 5th edition. Wellesley-Cambridge Press.
- MIT OpenCourseWare (2010). 18.06 Linear Algebra (Spring 2010). Massachusetts Institute of Technology. Link
11. Eigenvalues and stability
Some directions survive a transformation: the matrix only stretches them. These eigenvectors, and their stretch factors the eigenvalues, explain how structures vibrate, whether a feedback loop settles, and which pattern dominates after many steps. This chapter starts from the determinant as area scaling, finds 2×2 eigenvalues by hand and uses them to judge stability.
Figure 11.1. The directions that survive (described in words)
The matrix with rows (2, 1) and (1, 2) applied to two vectors. The vector (1, 1) becomes (3, 3): same direction, three times as long, eigenvalue 3. The vector (1, −1) is unchanged, eigenvalue 1.
Explanation
11.1 The determinant as area scaling
Why does a single number, ad − bc, tell you whether a whole system of equations can be solved?
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.
Derivation: ad − bc is the parallelogram's area
The columns (a, c) and (b, d) span a parallelogram; the unit square maps onto it.
Enclose it in the rectangle [0, a + b] × [0, c + d] (for positive entries) of area (a + b)(c + d).
Subtract the corner pieces: two triangles of area ac/2, two of area bd/2, and two rectangles of area bc.
Area = (a + b)(c + d) − ac − bd − 2bc = ad − bc.
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.
Common mix-ups
det(A + B) = det A + det B.
✓ The determinant is multiplicative, not additive. Try A = B = I in 2D: det(2I) = 4, not 2.A negative determinant means the map shrinks things.
✓ The sign is orientation; the size |det| is the scaling.
11.2 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?
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 λ.
Common mix-ups
Every matrix has a full set of real eigenvectors.
✓ Rotations have complex eigenvalues and shears are defective (too few eigenvectors).The zero vector is an eigenvector of everything.
✓ Eigenvectors are non-zero by definition; otherwise every λ would work.
11.3 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?
The recipe
- 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.
Derivation: The characteristic polynomial of a 2×2 matrix
A·v = λ·v with v ≠ 0 means (A − λI)·v = 0 has a non-zero solution.
A non-zero solution exists exactly when A − λI is singular: det(A − λI) = 0.
For A = [[a, b], [c, d]]: det [[a − λ, b], [c, d − λ]] = (a − λ)(d − λ) − bc = λ² − (a + d)λ + (ad − bc).
So λ² − (tr A)λ + det A = 0, giving λ = (tr ± √(tr² − 4 det)) / 2, or with m = tr/2 and p = det, λ = m ± √(m² − p).
Comparing with (λ − λ₁)(λ − λ₂) = λ² − (λ₁ + λ₂)λ + λ₁λ₂ shows tr A = λ₁ + λ₂ and det A = λ₁λ₂.
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).
Common mix-ups
The eigenvalues are the diagonal entries.
✓ Only for triangular (or diagonal) matrices.Eigenvectors are unique.
✓ Any non-zero multiple of an eigenvector is also one; we choose a convenient scaling.
11.4 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?
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.
Derivation: Why the spectral radius decides
Suppose A has independent eigenvectors v₁, v₂. Write x[0] = c₁v₁ + c₂v₂.
Then x[1] = A x[0] = c₁λ₁v₁ + c₂λ₂v₂, and by induction x[k] = c₁λ₁ᵏv₁ + c₂λ₂ᵏv₂.
If every |λᵢ| < 1, every term goes to zero: the iteration is asymptotically stable.
If some |λᵢ| > 1 and its cᵢ ≠ 0, that term grows without bound: unstable.
So stability depends on the spectral radius ρ(A) = max |λᵢ| < 1. Complex λ = re^{iφ} give rotation by φ per step with size rᵏ.
Common mix-ups
For any linear system, |λ| < 1 means stable.
✓ That is the discrete-time test. For x′ = Ax, use Re(λ) < 0.If most eigenvalues are stable, the system is stable.
✓ One unstable mode makes the whole system unstable (unless it is never excited, which noise will eventually do).
Examples to try
Worked solutions are in the interactive chapter online.
The determinant as area scaling: example 1
Compute det of [[2, 1, −1], [−3, −1, 2], [−2, 1, 2]] from its LU factorisation.
Eigenvectors: the directions that survive: example 1
Check that (1, −2) is an eigenvector of A = [[4, 1], [2, 3]].
2×2 eigenvalues by hand: example 1
Find the eigenvalues of [[0, 1], [−2, −3]].
2×2 eigenvalues by hand: example 2
Find the eigenvalues of [[1, −2], [2, 1]].
Stability of x[k+1] = A·x[k]: example 1
Is x[k+1] = [[0.5, 0.4], [0.1, 0.6]]·x[k] stable?
Interactive figures, in words
Figure 11.2 from “The determinant as area scaling”
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).
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.
Figure 11.3 from “Eigenvectors: the directions that survive”
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?
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.
Figure 11.4 from “Stability of x[k+1] = A·x[k]”
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.
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.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Matrices (Equation Lab exploration)
Find a matrix with a negative determinant and describe what it does to the orientation of the grid.
Open online - Equation Lab: Oscillator (Equation Lab exploration)
Relate the oscillator's decay and frequency to the eigenvalues of its state matrix.
Open online - Nexus: Virtual robotic arm (Nexus project)
Find a pose where the arm is fully stretched and explain, with the determinant idea, why it cannot move its tip outward.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. Find det A for A = [[-4, 1, 6], [6, -1, 2], [3, 0, 6]].
Answer:
Check it in “The determinant as area scaling”
2. A maps the unit square to the parallelogram with sides (3, 1) and (1, 2). What is its area?
Answer:
Check it in “The determinant as area scaling”
3. 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
Check it in “The determinant as area scaling”
4. Is (1, 1) an eigenvector of [[3, 1], [1, 3]]?
- Yes, with λ = 4
- Yes, with λ = 3
- No
Check it in “Eigenvectors: the directions that survive”
5. 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
Check it in “Eigenvectors: the directions that survive”
6. A = [[2, 0], [6, -4]]. Find its smaller eigenvalue.
Answer:
Check it in “2×2 eigenvalues by hand”
7. 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
Check it in “2×2 eigenvalues by hand”
8. 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
Check it in “Stability of x[k+1] = A·x[k]”
Engineering applications
Vibration
A structure's natural frequencies come from the eigenvalues of its stiffness and mass model. Designers keep those frequencies away from the frequencies of motors and footsteps.
Digital control
A discrete-time controller x[k+1] = A·x[k] settles only if every eigenvalue of A has magnitude below 1. Checking eigenvalues is the first test of a new controller design.
Summary
- det(A) is the factor by which A scales areas; a negative determinant flips orientation, zero squashes the plane.
- An eigenvector v satisfies A·v = λ·v: A only stretches it, by the eigenvalue λ.
- For a 2×2 matrix, the eigenvalues solve λ^2 − (trace)·λ + det = 0.
- x[k+1] = A·x[k] is stable when every eigenvalue has |λ| < 1; the largest |λ| sets how fast it settles.
Glossary
- Matrix multiplication
- Multiplying matrices combines rows of the first with columns of the second: each entry of the result is a dot product of a row and a column.
- 2D rotation matrix
- A 2D rotation by angle θ anticlockwise maps (x, y) to (x cos θ − y sin θ, x sin θ + y cos θ), written as a 2×2 matrix.
- Damping ratio
- The damping ratio ζ describes how quickly oscillations die out in a second-order system: below 1 it oscillates, exactly 1 is critically damped, above 1 it creeps to the target without overshoot.
Project: Will it settle?
Choose a two-state discrete model, such as a thermostat's temperature and heater state or a population of two species. Find the eigenvalues of its matrix by hand, predict whether it settles, then simulate 20 steps in code and compare.
Deliverables
- The model and its matrix
- Eigenvalues by hand and by code
- The simulation plot
- A sentence on what changes would make it unstable
References
- Gilbert Strang (2016). Introduction to Linear Algebra, 5th edition. Wellesley-Cambridge Press.
- MIT OpenCourseWare (2010). 18.06 Linear Algebra (Spring 2010). Massachusetts Institute of Technology. Link
- Erwin Kreyszig (2011). Advanced Engineering Mathematics, 10th edition. Wiley.
Known limitations
- Not yet tested by a person using a screen reader; only automated structure checks have run.
- Some interactive lesson diagrams need a pointer or keyboard and a recent browser; their text alternatives carry the same idea without the interaction.
- Mathematics is written as plain text (for example x^2 and sqrt(x)), like the School lessons, not typeset notation.