BIT203 ยท 2079 ยท 5 marks
What is least squares method of fitting a function? Fit the second order polynomial for the following data values. | x | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |---|---|---|---|---|---|---|---| | y | 2 | 6 | 7 | 8 | 10 | 12 | 15 |
What is least squares method of fitting a function? Fit the second order polynomial for the following data values.
| x | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| y | 2 | 6 | 7 | 8 | 10 | 12 | 15 |
[5]
Least Squares Method and Second Order Polynomial Fitting
Definition
The least squares method finds the best-fit curve for a set of data points by minimizing the sum of squares of residuals (differences between observed values $y_i$ and fitted values $f(x_i)$):
$$S = \sum_{i=1}^{n} [y_i - f(x_i)]^2 \to \text{minimum}$$
Given Data
$$x: 1, 2, 3, 4, 5, 6, 7$$ $$y: 2, 6, 7, 8, 10, 12, 15$$ $$n = 7$$
Model and Normal Equations
Fit $y = a_0 + a_1 x + a_2 x^2$. The normal equations are:
$$\sum y = na_0 + a_1\sum x + a_2\sum x^2$$ $$\sum xy = a_0\sum x + a_1\sum x^2 + a_2\sum x^3$$ $$\sum x^2y = a_0\sum x^2 + a_1\sum x^3 + a_2\sum x^4$$
Calculation Table
| $x$ | $y$ | $x^2$ | $x^3$ | $x^4$ | $xy$ | $x^2y$ |
|---|---|---|---|---|---|---|
| 1 | 2 | 1 | 1 | 1 | 2 | 2 |
| 2 | 6 | 4 | 8 | 16 | 12 | 24 |
| 3 | 7 | 9 | 27 | 81 | 21 | 63 |
| 4 | 8 | 16 | 64 | 256 | 32 | 128 |
| 5 | 10 | 25 | 125 | 625 | 50 | 250 |
| 6 | 12 | 36 | 216 | 1296 | 72 | 432 |
| 7 | 15 | 49 | 343 | 2401 | 105 | 735 |
| $\Sigma$ | 60 | 140 | 784 | 4676 | 294 | 1634 |
Also $\sum x = 28$.
Substituting
$$60 = 7a_0 + 28a_1 + 140a_2 \quad (1)$$ $$294 = 28a_0 + 140a_1 + 784a_2 \quad (2)$$ $$1634 = 140a_0 + 784a_1 + 4676a_2 \quad (3)$$
Note: The coefficient of $a_0$ in equation (1) must be $\sum x = 28$, while in equation (3) the $a_0$ coefficient is $\sum x^2 = 140$; mixing the two is an easy slip to make.
Solving
Eliminate $a_0$. Multiply (1) by 4 and subtract from (2):
$(2) - 4\times(1)$: $$294 - 240 = (28-28)a_0 + (140-112)a_1 + (784-560)a_2$$ $$54 = 28a_1 + 224a_2 \quad (4)$$
Multiply (1) by 20 and subtract from (3):
$(3) - 20\times(1)$: $$1634 - 1200 = (140-140)a_0 + (784-560)a_1 + (4676-2800)a_2$$ $$434 = 224a_1 + 1876a_2 \quad (5)$$
Eliminate $a_1$. Multiply (4) by 8: $$432 = 224a_1 + 1792a_2 \quad (4')$$
$(5) - (4')$: $$434 - 432 = (1876 - 1792)a_2$$ $$2 = 84a_2 \implies a_2 = 0.02381$$
From (4): $$54 = 28a_1 + 224(0.02381) = 28a_1 + 5.333$$ $$28a_1 = 48.667 \implies a_1 = 1.7381$$
From (1): $$60 = 7a_0 + 28(1.7381) + 140(0.02381)$$ $$60 = 7a_0 + 48.667 + 3.333$$ $$7a_0 = 8.0 \implies a_0 = 1.1429$$
Result
$$\boxed{y = 1.1429 + 1.7381x + 0.0238x^2}$$
Verification (at $x=4$): $1.1429 + 6.9524 + 0.381 = 8.476 \approx 8$ โ (at $x=7$): $1.1429 + 12.167 + 1.167 = 14.48 \approx 15$ โ
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.