Unit 25 · Semester 2 · mathematical modelling
Math bridge: vectors, calculus and optimization
Mission: Fit one straight calibration line to three labelled toy points and account for every miss. Prerequisites: Foundations Chapters 9–10. This 100-minute introduction is distinct from the full unit of about three weeks and 20–30 focused hours.
The interactive version of this unit needs JavaScript. Below are its steps as text.
Steps
1. See three observations
Press Show points to place the three labelled toy observations on the board.
Why it matters: The sample index is a dimensionless label, not time. These points are invented for this example.
2. Shift the intercept
Press Raise line to move the horizontal prediction from 0 to 1 cm.
Why it matters: The intercept is the predicted distance at index zero. Moving it shifts every prediction equally.
3. Tilt the line
Press Tilt line to change a from 0 to 0.5 cm per index, keeping b at 1 cm.
Why it matters: The slope tells how much the prediction changes for one index. It is not a velocity because the index is not time.
4. Collect predictions
Press Gather predictions to reveal the ordered predictions for all three indices.
Why it matters: An ordered list of values is a vector. Its order must match the observations.
5. Build the transformation
Press Show rows to reveal how each index and the constant 1 multiply the same two coefficients.
Why it matters: The rows form a design matrix. Multiplying that matrix by the coefficient vector produces the prediction vector.
6. Account for every miss
Press Show misses to draw the vertical prediction minus observation at each point.
Why it matters: A residual is prediction minus observation in cm. A negative residual means the line is below the observation.
7. Square the misses
Press Square misses to compare the residual bars with their squared sizes.
Why it matters: Squaring makes negative and positive misses contribute positively. It also gives larger misses more weight.
8. Compare the total
Press Compare loss to reveal the sum for two lines.
Why it matters: The chosen objective is the sum of squared errors, SSE. Lower SSE answers this objective only, not every possible notion of best.
9. Ask how loss changes
Press Probe change to compare a small increase in slope with the exact gradient at a=0, b=1 cm.
Why it matters: A finite change compares two values; a derivative describes the limiting local rate. The gradient collects both derivatives of this specified SSE objective.
10. Take a small step
Press Step downhill to apply alpha 0.1 to the negative gradient.
Why it matters: Subtract alpha times the gradient to change both coefficients. This step reduces this example’s loss, but a step size is not universally safe.
11. Find the exact fit
Press Compare fit to reveal the least-squares line and its residual plot.
Why it matters: The exact least-squares line has zero SSE gradient, not zero residuals. The signed residuals cancel even though their squares do not.
12. Bound the conclusion
Press Show limits to inspect what the fit cannot establish, then use the blank notebook.
Why it matters: Probability models uncertainty only with assumptions and evidence such as repeated measurements. Residuals alone do not establish a distribution or confidence. Correlation is not causation, and extrapolation beyond these indices is risky.
Go deeper
Equations and units
For dimensionless sample index x and distance y in cm: prediction = ax + b, residual r = prediction − observation, SSE = Σr² in cm². Both a and b are in cm; ∂SSE/∂a = 2Σxr and ∂SSE/∂b = 2Σr, in cm. Gradient descent subtracts alpha times this gradient; here alpha=0.1 is dimensionless. MSE divides SSE by the number of points and changes the gradient and step scale.
At (a,b)=(0,1) cm the gradient is (−6,−4) cm. Alpha 0.1 gives (0.6,1.4) cm and SSE 0.52 cm². Alpha 1 gives (6,5) cm and SSE 322 cm²: a large step can overshoot. If x is seconds instead, slope is cm/s and coefficient scales and appropriate step sizes change.
Distinct x values are required for a unique intercept-and-slope least-squares fit. Use finite bounded inputs and consistent units; missing is never zero. The design matrix has rows [x,1]; rank deficiency makes its two columns dependent. A line fitted within observed indices need not extrapolate safely.
Reproducible standard-library Python
Copy the script shown in the notebook panel, replace the explicitly toy dataset with your own chosen rows, and record the Python version and output. It independently computes the fit, residuals, SSE and gradient.
Read and watch
MIT 18.06 Lecture 1 (archived 2010) supports the geometry of linear equations; the same course’s projections and least-squares material extends it. These sources do not validate this page or establish probability or causation.