ENG 303 · Engineering Mathematics V (Numerical Methods and Computer Application)
Our notes
1 min readThe 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
-
Best pick Kaw, Numerical Methods with Applications: Linear regression
Textbook chapter (PDF, about 0.9 MB) with worked examples and a short quiz at the end.
(opens nm.mathforcollege.com in a new tab)
Kaw, Numerical Methods with Applications, Kaw, Numerical Methods with Applications: Linear regression, CC BY-NC-ND 4.0 · licence
-
Kaw, Numerical Methods with Applications: Nonlinear regression
Textbook chapter (PDF, about 0.5 MB) with worked examples and a short quiz at the end.
(opens nm.mathforcollege.com in a new tab)
Kaw, Numerical Methods with Applications, Kaw, Numerical Methods with Applications: Nonlinear regression, CC BY-NC-ND 4.0 · licence
-
Least squares
(opens en.wikipedia.org in a new tab)
Wikipedia, Least squares, CC BY-SA 4.0 · licence
-
Kaw, Numerical Methods with Applications (the whole free textbook)
Every chapter as a separate PDF (0.2 to 1.5 MB each), with videos and quizzes for each method.
(opens nm.mathforcollege.com in a new tab)
Kaw, Numerical Methods with Applications, Kaw, Numerical Methods with Applications (the whole free textbook), CC BY-NC-ND 4.0 · licence
Watch
-
Linear Regression: Derivation Part 1 of 2
6 min · ≈ 27 MB · about ₦15
(opens youtube.com in a new tab)
-
Chapter 06.03: Lesson: Deriving the Linear Regression Formula
14 min · ≈ 63 MB · about ₦35
(opens youtube.com in a new tab)
-
Linear Regression Using Least Squares Method - Line of Best Fit Equation
15 min · ≈ 68 MB · about ₦38
(opens youtube.com in a new tab)
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.