## Linear Algebra and Its Applications, Exercise 3.3.24

Exercise 3.3.24. Given the measurements $y = 2, 0, -3, -5$ at $t= -1, 0, 1, 2$ use least squares to find the line of best fit.

Answer: This corresponds to a system of the form $Ax = b$ as follows:

$\begin{bmatrix} 1&-1 \\ 1&0 \\ 1&1 \\ 1&2 \end{bmatrix} \begin{bmatrix} C \\ D \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \\ -3 \\ -5 \end{bmatrix}$

To find the least squares solution we multiply both sides by $A^T$ to create a system of the form $A^TA\bar{x} = A^Tb$. We have

$A^TA = \begin{bmatrix} 1&1&1&1 \\ -1&0&1&2 \end{bmatrix} \begin{bmatrix} 1&-1 \\ 1&0 \\ 1&1 \\ 1&2 \end{bmatrix} = \begin{bmatrix} 4&2 \\ 2&6 \end{bmatrix}$

and

$A^Tb = \begin{bmatrix} 1&1&1&1 \\ -1&0&1&2 \end{bmatrix} \begin{bmatrix} 2 \\ 0 \\ -3 \\ -5 \end{bmatrix} = \begin{bmatrix} -6 \\ -15 \end{bmatrix}$

so that the new system is

$\begin{bmatrix} 4&2 \\ 2&6 \end{bmatrix} \begin{bmatrix} \bar{C} \\ \bar{D} \end{bmatrix} = \begin{bmatrix} -6 \\ -15 \end{bmatrix}$

We can multiply the first equation by $\frac{1}{2}$ and subtract it from the second equation to form the system

$\begin{bmatrix} 4&2 \\ 0&5 \end{bmatrix} \begin{bmatrix} \bar{C} \\ \bar{D} \end{bmatrix} = \begin{bmatrix} -6 \\ -12 \end{bmatrix}$

From the second equation we have $\bar{D} = -\frac{12}{5}$ and can substitute into the first equation to get $4\bar{C} - \frac{24}{5} = -6$ or

$\bar{C} = \frac{1}{4} (-6 + \frac{24}{5}) = \frac{1}{4} (-\frac{6}{5}) = -\frac{3}{10}$

The line of best fit is thus $-\frac{3}{10} - \frac{12}{5}t$.

NOTE: This continues a series of posts containing worked out exercises from the (out of print) book Linear Algebra and Its Applications, Third Edition by Gilbert Strang.

If you find these posts useful I encourage you to also check out the more current Linear Algebra and Its Applications, Fourth Edition, Dr Strang’s introductory textbook Introduction to Linear Algebra, Fifth Edition and the accompanying free online course, and Dr Strang’s other books.

This entry was posted in linear algebra and tagged . Bookmark the permalink.