UNIHIVE

Study Hub UNIPORT ENG 303

ENG 303 · Engineering Mathematics V (Numerical Methods and Computer Application)

Data fitting by least squares

Fitting a straight line to noisy data, the normal equations, goodness of fit, and fitting curves that can be linearised.

Our notes

1 min read

The idea

Measured data contain noise, so a curve through every point (interpolation) is misleading. Least squares chooses the curve that makes the sum of squared residuals (vertical distances from the points) as small as possible.

Straight line y = a + bx

Minimising S = Σ(yᵢ − a − bxᵢ)² gives the normal equations:
na + bΣx = Σy and aΣx + bΣx² = Σxy, so
b = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²) and a = (Σy − bΣx)/n.
Worked example. Points (1, 2), (2, 3), (3, 5), (4, 6): n = 4, Σx = 10, Σy = 16, Σxy = 2 + 6 + 15 + 24 = 47, Σx² = 30.
b = (4 × 47 − 10 × 16)/(4 × 30 − 100) = (188 − 160)/20 = 1.4; a = (16 − 1.4 × 10)/4 = 0.5.
Line: y = 0.5 + 1.4x. Residuals: 0.1, −0.3, 0.3, −0.1 (they sum to zero, a check); sum of squares = 0.20.

Goodness of fit

  • Standard error of estimate: s = √[S/(n − 2)] = √(0.20/2) = 0.316.
  • Coefficient of determination r² = 1 − S/Σ(y − ȳ)². Here ȳ = 4, Σ(y − ȳ)² = 4 + 1 + 1 + 4 = 10, so r² = 1 − 0.2/10 = 0.98: the line explains 98% of the variation.

Linearising curves

  • Exponential y = ae^(bx): fit ln y = ln a + bx.
  • Power law y = ax^b: fit log y = log a + b log x.
  • Saturation or rate laws can be inverted (1/y against 1/x).

Fitting in the transformed scale weights errors differently; for accurate work use non-linear least squares.

Polynomials and more variables

Fitting y = a₀ + a₁x + a₂x² gives three normal equations; fitting y = a₀ + a₁x₁ + a₂x₂ (multiple regression) is similar. In matrix form the normal equations are XᵀXa = Xᵀy; QR factorisation solves them more stably.

Exams usually ask: derive and solve the normal equations for a straight line; compute r²; fit an exponential or power law by linearising.

Common mistake: computing (Σx)² when Σx² is needed, or the other way round. Keep separate columns for x, y, xy and x² in your table.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All ENG 303 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.