Linear Algebra and Its Applications, Exercise 3.3.26

Exercise 3.3.26. A middle-aged man is stretched on a rack with various forces. Given the measurements of length L = 5, 6, 7 (in feet) at forces F= 1, 2, 4 (in tons), and assuming that Hooke’s Law a + bF applies, use least squares to find the man’s length a when no force is applied.

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

\begin{bmatrix} 1&1 \\ 1&2 \\ 1&4 \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} 5 \\ 6 \\ 7 \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&2&4 \end{bmatrix} \begin{bmatrix} 1&1 \\ 1&2 \\ 1&4 \end{bmatrix} = \begin{bmatrix} 3&7 \\ 7&21 \end{bmatrix}

and

A^Tb = \begin{bmatrix} 1&1&1 \\ 1&2&4 \end{bmatrix} \begin{bmatrix} 5 \\ 6 \\ 7 \end{bmatrix} = \begin{bmatrix} 18 \\ 45 \end{bmatrix}

so that the new system is

\begin{bmatrix} 3&7 \\ 7&21 \end{bmatrix} \begin{bmatrix} \bar{a} \\ \bar{b} \end{bmatrix} = \begin{bmatrix} 18 \\ 45 \end{bmatrix}

We can multiply the first equation by \frac{7}{3} and subtract it from the second equation to form the system

\begin{bmatrix} 3&7 \\ 0&\frac{14}{3} \end{bmatrix} \begin{bmatrix} \bar{a} \\ \bar{b} \end{bmatrix} = \begin{bmatrix} 18 \\ 3 \end{bmatrix}

From the second equation we have \bar{b} = 3 \cdot \frac{3}{14} = \frac{9}{14} and can substitute into the first equation to get 3\bar{a} + 7 \cdot \frac{9}{14} = 18 or

\bar{a} = \frac{1}{3} (18 - \frac{9}{2}) = \frac{1}{3} (\frac{27}{2}) = \frac{9}{2}

The man’s length when not stretched is thus \bar{a} = \frac{9}{2} or 4.5 feet.

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.

Posted in linear algebra | Tagged | Leave a comment

Linear Algebra and Its Applications, Exercise 3.3.25

Exercise 3.3.25. Given the measurements y = 2, 0, -3, -5 at t= -1, 0, 1, 2 from the previous exercise, what would be the coefficient matrix A, the unknown vector x, and the data vector b if we wish to fit the data using a parabola of the form y = C + Dt + Et^2?

Answer: We would need to change the unknown vector x to add the additional unknown parameter E and add a third column to the coefficient matrix A to reflect the values of t^2 for the various measurements. The vector b containing the data values would remain the same. The system Ax = b would then be as follows:

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

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.

Posted in linear algebra | Tagged | Leave a comment

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.

Posted in linear algebra | Tagged | Leave a comment

Linear Algebra and Its Applications, Exercise 3.3.23

Exercise 3.3.23. Given measurements y_1, y_2, \dots, y_m show that the best least squares fit to the horizontal line y = C is given by

C = (y_1 + y_2 + \cdots + y_m)/m

Answer: This corresponds to the system Ax = b where A is an m by 1 matrix with all entries equal to 1 and b = (y_1, y_2, \cdots, y_m). To find the least squares solution we form the system A^TA\bar{x} = A^Tb. We have

A^TA = \begin{bmatrix} 1&1&\cdots&1 \end{bmatrix} \begin{bmatrix} 1 \\ 1 \\ \vdots \\ 1 \end{bmatrix} = \sum_{i=1}^m 1 = m

and

A^Tb = \begin{bmatrix} 1&1&\cdots&1 \end{bmatrix} \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_m \end{bmatrix} = \sum_{i=1}^m y_i

The system A^TA\bar{x} = A^Tb thus reduces to m\bar{C} = \sum_{i=1}^m y_i so that

\bar{C} = (y_1 + y_2 + \cdots + y_m)/m

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.

Posted in linear algebra | Tagged , | Leave a comment

Linear Algebra and Its Applications, Exercise 3.3.22

Exercise 3.3.22. Given measurements of b = 4, 2, -1, 0, 0 at t = -2, -1, 0, 1, 2 use least squares to find the line of best fit of the form C + Dt.

Answer: This corresponds to a system Ax = b as follows:

\begin{bmatrix} 1&-2 \\ 1&-1 \\ 1&0 \\ 1&1 \\ 1&2 \end{bmatrix} \begin{bmatrix} C \\ D \end{bmatrix} = \begin{bmatrix} 4 \\ 2 \\ -1 \\ 0 \\ 0 \end{bmatrix}

To find the least squares solution we form the system A^TA\bar{x} = A^Tb. We have

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

= \begin{bmatrix} 5&0 \\ 0&10 \end{bmatrix}

and

A^Tb = \begin{bmatrix} 1&1&1&1&1 \\ -2&-1&0&1&2 \end{bmatrix} \begin{bmatrix} 4 \\ 2 \\ -1 \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 5 \\ -10 \end{bmatrix}

The system A^TA\bar{x} = A^Tb is then

\begin{bmatrix} 5&0 \\ 0&10 \end{bmatrix} \begin{bmatrix} \bar{C} \\ \bar{D} \end{bmatrix} = \begin{bmatrix} 5 \\ -10 \end{bmatrix}

From the second equation we have \bar{D} = -1 and from the first equation we have \bar{C} = 1. The line of best fit is therefore 1 - 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.

Posted in linear algebra | Tagged | Leave a comment

Linear Algebra and Its Applications, Exercise 3.3.21

Exercise 3.3.21. Given three vectors a_1, a_2, and b, and the two lines L_1 through the origin and a_1 and L_2 through b in the direction of a_2, we want to find scalar values x_1 and x_2 such that the distance \| x_1a_1 - x_2a_2 - b \| between the points x_1a_1 and b + x_2a_2 is at a minimum. Write down equations for x_1 and x_2. Solve the equations for x = (x_1, x_2) when a_1 = (1, 1, 0), a_2 = (0, 1, 0), and b = (2, 1, 4).

Answer: We approach the problem by taking partial derivatives of \| x_1a_1 - x_2a_2 - b \|^2 with respect to x_1 and x_2 and then setting those partial derivatives to zero. We have

\| x_1a_1 - x_2a_2 - b \|^2 = (x_1a_1 - x_2a_2 - b)^T(x_1a_1 - x_2a_2 - b)

We take advantage of the facts that for two vectors v and w we have v^Tw = w^Tv (the inner product is the same no matter in which order we calculate it) and (v-w)^T = v^T - w^T (the transpose of a difference is the same as the difference of the transposes). We then have

\| x_1a_1 - x_2a_2 - b \|^2 = (x_1a_1^T - x_2a_2^T - b^T)(x_1a_1 - x_2a_2 - b)

= x_1^2a_1^Ta_1 - x_1x_2a_1^Ta_2 - x_1a_1^Tb - x_2x_1a_2^Ta_1 + x_2^2a_2^Ta_2

+ x_2a_2^Tb - x_1b^Ta_1 + x_2b^Ta_2 + b^Tb

= x_1^2a_1^Ta_1 + x_2^2a_2^Ta_2 - 2x_1x_2a_1^Ta_2 - 2x_1a_1^Tb + 2x_2a_2^Tb + b^Tb

Next we take the partial derivatives with respect to x_1:

\frac{\partial}{\partial x_1} \| x_1a_1 - x_2a_2 - b \|^2

= \frac{\partial}{\partial x_1} (x_1^2a_1^Ta_1 + x_2^2a_2^Ta_2 - 2x_1x_2a_1^Ta_2 - 2x_1a_1^Tb + 2x_2a_2^Tb + b^Tb)

= 2x_1a_1^Ta_1 - 2x_2a_1^Ta_2 - 2a_1^Tb

and with respect to x_2:

\frac{\partial}{\partial x_2} \| x_1a_1 - x_2a_2 - b \|^2

= \frac{\partial}{\partial x_2} (x_1^2a_1^Ta_1 + x_2^2a_2^Ta_2 - 2x_1x_2a_1^Ta_2 - 2x_1a_1^Tb + 2x_2a_2^Tb + b^Tb)

= 2x_2a_2^Ta_2 - 2x_1a_1^Ta_2 + 2a_2^Tb

Equating the partial derivatives to zero gives us the following system of equations (after simplifying by dividing by 2 and rearranging terms):

\begin{bmatrix} a_1^Ta_1&-a_1^Ta_2 \\ -a_1^Ta_2&a_2^Ta_2 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} = \begin{bmatrix} a_1^Tb \\ -a_2^Tb \end{bmatrix}

When a_1 = (1, 1, 0), a_2 = (0, 1, 0), and b = (2, 1, 4) we have a_1^Ta_1 = 2, a_2^Ta_2 = 1, a_1^Ta_2 = 1, a_1^Tb = 3, and a_2^Tb = 1. The system of equations is then

\begin{bmatrix} 2&-1 \\ -1&1 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} = \begin{bmatrix} 3 \\ -1 \end{bmatrix}

We can solve this by multiplying both sides of the equation on the left by

\begin{bmatrix} 2&-1 \\ -1&1 \end{bmatrix}^{-1} = \frac{1}{2 - (-1)(-1)} \begin{bmatrix} 1&1 \\ 1&2 \end{bmatrix} = \begin{bmatrix} 1&1 \\ 1&2 \end{bmatrix}

to get

\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} = \begin{bmatrix} 1&1 \\ 1&2 \end{bmatrix} \begin{bmatrix} 3 \\ -1 \end{bmatrix} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}

The solution is thus x = (2, 1).

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.

Posted in linear algebra | Tagged | Leave a comment

Linear Algebra and Its Applications, Exercise 3.3.20

Exercise 3.3.20. Given the matrix P_R that projects onto the row space of A, find the matrix P_N that projects onto the nullspace of A.

Answer: The null space of A is orthogonal to the row space of A. The two spaces are orthogonal complements, with \mathcal{N}(A) = \mathcal{R}(A^T)^\perp. Recall from exercise 3.3.11 that if P is a projection matrix onto S and Q a projection matrix onto S^\perp then we have P+Q=I.

So in this case we have P_R + P_N = I or P_N = I - P_R.

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.

Posted in linear algebra | Tagged , , | Leave a comment