Linear Algebra and Its Applications, Exercise 3.4.21

Exercise 3.4.21. Given the function f(x) = \sin 2x on the interval -\pi \le x \le \pi, what is the closest function a \cos x + b \sin x to f? What is the closest line c + dx to f?

Answer: To find the closest function a \cos x + b \sin x to the function f(x) = \sin 2x we first project f onto the function \cos x on the given interval to obtain a, and then project f onto \sin x to obtain b.

We project f onto \cos x by taking the dot product of f with \cos x and then normalizing by dividing by the dot product of \cos x with itself:

a = (f, \cos x)/(\cos x, \cos x)

The numerator is

(f, \cos x) = \int_{-\pi}^{\pi} f(x) \cos x \;\mathrm{d}x = \int_{-\pi}^{\pi} \sin 2x \cos x \;\mathrm{d}x

= 2 \int_{-\pi}^{\pi} \sin x \cos^2 x \;\mathrm{d}x

where we used the trigonometric identity \sin 2\theta = \sin \theta \cos \theta.

To integrate we substitute the variable u = \cos x so that \mathrm{d}u = -\sin x \;\mathrm{d}x. We then have

\int \sin x \cos^2 x \;\mathrm{d}x = -\int \cos^2 x (-\sin x) \;\mathrm{d}x

-\int u^2 \;\mathrm{d}u = -\frac{1}{3}u^3 = -\frac{1}{3} \cos^3 x

We then have

(f, \cos x) = 2 \int_{-\pi}^{\pi} \sin x \cos^2 x \;\mathrm{d}x = 2 (-\frac{1}{3} \cos^3 x) \;\big|_{-\pi}^{\pi}

= -\frac{2}{3} \cos^3 \pi - [-\frac{2}{3} \cos^3 (-\pi)] = -\frac{2}{3} (-1)^3 - [-\frac{2}{3} (-1)^3]

= -\frac{2}{3} \cdot (-1) - [-\frac{2}{3} \cdot (-1)] = \frac{2}{3} - \frac{2}{3} = 0

Since the numerator in the expression for a is zero, we have a = 0.

(Note that we do not need to calculate the denominator in the expression for a. We know it must be positive, and thus the quotient is defined. See below for a sketch of a proof of this.)

We next project f onto \sin x by taking the dot product of f with \sin x and then normalizing by dividing by the dot product of \sin x with itself:

a = (f, \sin x)/(\sin x, \sin x)

The numerator is

(f, \sin x) = \int_{-\pi}^{\pi} f(x) \sin x \;\mathrm{d}x = \int_{-\pi}^{\pi} \sin 2x \sin x \;\mathrm{d}x

= 2 \int_{-\pi}^{\pi} \sin^2 x \cos x \;\mathrm{d}x

where we used the trigonometric identity \sin 2\theta = \sin \theta \cos \theta.

To integrate we substitute the variable u = \sin x so that \mathrm{d}u = \cos x \;\mathrm{d}x. We then have

\int \sin^2 x \cos x \;\mathrm{d}x = \int u^2 \;\mathrm{d}u = \frac{1}{3}u^3 = \frac{1}{3} \sin^3 x

We then have

(f, \sin x) = 2 \int_{-\pi}^{\pi} \sin^2 x \cos x \;\mathrm{d}x = 2 (\frac{1}{3} \sin^3 x) \;\big|_{-\pi}^{\pi}

= \frac{2}{3} \sin^3 \pi - \frac{2}{3} \sin^3 (-\pi) = \frac{2}{3} (0)^3 - \frac{2}{3} (0)^3

= 0 - 0 = 0

Since the numerator in the expression for b is zero, we have b = 0. (Again, we are guaranteed that the denominator is positive and the quotient defined.)

So the closest function a \cos x + b \sin x to f(x) = \sin 2x is 0 \cdot \cos x + 0 \cdot \sin x = 0.

To find the closest function c + dx to the function f(x) = \sin 2x we first project f onto the constant function with the value 1 on the given interval to obtain c, and then project f onto the function x to obtain d.

We project f onto the constant function with value 1 by taking the dot product of f with 1 and then normalizing by dividing by the dot product of 1 with itself:

c = (f, 1)/(1, 1)

The numerator is

(f, 1) = \int_{-\pi}^{\pi} f(x) \cdot 1 \;\mathrm{d}x = \int_{-\pi}^{\pi} \sin 2x \;\mathrm{d}x

To integrate we substitute the variable u = 2x so that \mathrm{d}u = 2 \;\mathrm{d}x. We then have

\int \sin 2x \;\mathrm{d}x = \int \frac{1}{2} \sin 2x \cdot 2 \;\mathrm{d}x

= \frac{1}{2} \int \sin u \;\mathrm{d}u = \frac{1}{2}(-\cos u) = -\frac{1}{2} \cos 2x

We then have

(f, 1) = \int_{-\pi}^{\pi} \sin 2x \;\mathrm{d}x = -\frac{1}{2} \cos 2x \;\big|_{-\pi}^{\pi}

= -\frac{1}{2} \cos 2\pi - (-\frac{1}{2} \cos (-2\pi) = -\frac{1}{2} (1)^3 - (-\frac{1}{2} (1)^3

= -\frac{1}{2} + \frac{1}{2}= 0

Since the numerator in the expression for c = (f, 1)/(1, 1) is zero we have c = 0. (Recall that the denominator is guaranteed to be positive.)

We project f onto the function x by taking the dot product of f with x and then normalizing by dividing by the dot product of x with itself:

d = (f, x)/(x, x)

The numerator is

(f, x) = \int_{-\pi}^{\pi} f(x) \cdot x \;\mathrm{d}x = \int_{-\pi}^{\pi} x \sin 2x \;\mathrm{d}x

To integrate this we use integration by parts, taking advantage of the formula \int u \;\mathrm{d}v = uv - \int v \;\mathrm{d}u. (The following is adapted from a post on socratic.org.) We let \mathrm{d}v = \sin 2x \;\mathrm{d}x and u = x. Then \mathrm{d}u is simply \mathrm{d}x, and v = -\frac{1}{2} \cos 2x (the integrand of \sin 2x, as discussed above).

We then have

\int x \sin x \;\mathrm{d}x = \int u \;\mathrm{d}v = uv - \int v \;\mathrm{d}u

= x (-\frac{1}{2} \cos 2x) - \int (-\frac{1}{2} \cos 2x) \;\mathrm{d}x

= -\frac{1}{2} x \cos 2x + \frac{1}{2} \int \cos 2x \;\mathrm{d}x

The second integral we can evaluate by substituting w = 2x and \mathrm{d}w = 2 \;\mathrm{d}x so that

\int \cos 2x \;\mathrm{d}x = \frac{1}{2} \int \cos w \;\mathrm{d}w = \frac{1}{2} \sin w = \frac{1}{2} \sin 2x

Substituting for the second integral above we then have

\int x \sin x \;\mathrm{d}x = -\frac{1}{2} x \cos 2x + \frac{1}{2} \int \cos 2x \;\mathrm{d}x = -\frac{1}{2} x \cos 2x + \frac{1}{2} (\frac{1}{2} \sin 2x)

= -\frac{1}{2} x \cos 2x + \frac{1}{4} \sin 2x

We then have

(f, x) = \int_{-\pi}^{\pi} x \sin 2x \;\mathrm{d}x = -\frac{1}{2} x \cos 2x \;\big|_{-\pi}^{\pi} + \frac{1}{4} \sin 2x \;\big|_{-\pi}^{\pi}

= -\frac{1}{2} \pi \cos 2\pi - (-\frac{1}{2} (-\pi) \cos (-2\pi) + \frac{1}{4} \sin 2\pi - \frac{1}{4} \sin 2(-\pi)

= -\frac{1}{2} \pi \cdot 1 + \frac{1}{2} (-\pi) \cdot 1 + \frac{1}{4} \cdot 0 - \frac{1}{4} \cdot 0 = -\frac{\pi}{2} - \frac{\pi}{2}= -\pi

The denominator in the expression for d is

(x, x) = \int_{-\pi}^{\pi} x^2 \;\mathrm{d}x = \frac{1}{3} x^3 \;\big|_{-\pi}^{\pi}

= \frac{1}{3} \pi^3 - \frac{1}{3} (-\pi)^3 = \frac{2}{3} \pi^3

We then have

d = (f, x)/(x, x) = -\pi / (\frac{2}{3} \pi^3) = -\frac{3}{2\pi^2}

The straight line c + dx closest to the function \sin 2x is thus the line -\frac{3}{2\pi^2} x.

ADDENDUM: Suppose that g is a continuous function defined on the interval [a, b] and g(t) \ne 0 for some a \le t \le b. Then we want to show that the inner product (g, g) > 0.

The basic idea of the proof is as follows: The function g^2 is always nonnegative, and thus its integral over the interval [a, b] is nonnegative as well. If g(t) is nonzero for some a \le t \le b then since g is continuous g will also be nonzero for some interval [c, d] that includes t, with a \le c < d \le b. This implies that the integral of g^2 over that subinterval [c, d] will be positive.

But we also have \int_a^b g(x)^2 \;\mathrm{d}x \ge \int_c^d g(x)^2 \;\mathrm{d}x since g(x)^2 \ge 0 and [c, d] is contained within [a, b]. So if \int_c^d g(x)^2 \;\mathrm{d}x > 0 then we also have \int_a^b g(x)^2 \;\mathrm{d}x > 0 and the inner product (g, g) is positive.

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.4.20

Exercise 3.4.20. Given the vector v = (\frac{1}{\sqrt{2}}, \frac{1}{\sqrt{4}}, \frac{1}{\sqrt{8}}, \ldots) what is the length \|v\|? Given the function f(x) = e^x for 0 \le x \le 1 what is the length of the function over the interval? Given the function g(x) = e^{-x} for 0 \le x \le 1 what is the inner product of f(x) and g(x)?

Answer: We have

\|v\|^2 = v^Tv = (\frac{1}{\sqrt{2}})^2 + (\frac{1}{\sqrt{4}})^2 + (\frac{1}{\sqrt{8}})^2 + \ldots

= \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \ldots = 1

so that \|v\| = \sqrt{1} = 1.

We have

\|f\|^2 = \int_0^1 f(x)^2 \mathrm{d}x = \int_0^1 (e^x)^2 \mathrm{d}x = \int_0^1 e^{2x} \mathrm{d}x

= \frac{e^{2x}}{2} \big|_0^1 = \frac{e^2}{2} - \frac{e^0}{2} = \frac{e^2 - 1}{2}

so that \|f\| = \sqrt{\frac{e^2 - 1}{2}}.

Finally, the inner product of f(x) and g(x) is

\int_0^1 f(x)g(x) \mathrm{d}x = \int_0^1 e^x e^{-x} \mathrm{d}x = \int_0^1 e^0 \mathrm{d}x = \int_0^1 1 \mathrm{d}x = 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.4.19

Exercise 3.4.19. When doing Gram-Schmidt orthogonalization, an alternative approach to computing c' = c - (q_1^Tc)q_1 - (q_2^Tc)q_2 (equation 7 on page 173) is to instead compute c' in two separate steps:

c'' = c - (q_1^Tc)q_1 \qquad c' = c'' - (q_2^Tc'')q_2

Show that the second method is equivalent to the first.

Answer: We substitute the expression for c'' from the first equation into the second equation:

c' = c'' - (q_2^Tc'')q_2 = [c - (q_1^Tc)q_1] - \left[q_2^T\left[c - (q_1^Tc)q_1\right]\right]q_2

= c - (q_1^Tc)q_1 - \left[q_2^Tc - q_2^T(q_1^Tc)q_1\right]q_2

= c - (q_1^Tc)q_1 - \left[q_2^Tc - (q_1^Tc)q_2^Tq_1\right]q_2

= c - (q_1^Tc)q_1 - \left[q_2^Tc - (q_1^Tc) \cdot 0\right]q_2

= c - (q_1^Tc)q_1 - (q_2^Tc)q_2

The resulting equation c' = c - (q_1^Tc)q_1 - (q_2^Tc)q_2 is the original calculation of c' from equation 7 on page 173. So the second method using c'' is equivalent to the first.

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.4.18

Exercise 3.4.18. If P is the projection matrix onto the column space of the matrix A and A = QR, what is a simple formula for P?

Answer: The projection matrix P onto the column space of A can be calculated as P = A(A^TA)^{-1}A^T.

Since the columns of Q are linear combinations of the columns of A the column space of Q is the same as the column space of A. Thus P is also the projection matrix onto the column space of Q, and we can alternatively calculate P as P = Q(Q^TQ)^{-1}Q^T.

But since Q has orthonormal columns we have Q^TQ = I so that P = QI^{-1}Q^T = QQ^T. Thus P = QQ^T is a simplified formula for calculating the projection matrix onto the column space of A = QR.

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.4.17

Exercise 3.4.17. Given the matrix

A = \begin{bmatrix} 1&1 \\ 2&3 \\ 2&1 \end{bmatrix}

from the previous exercise and the vector b = (1, 1, 1), solve Ax = b by least squares using the factorization A = QR.

Answer: From the previous exercise we have

Q = \begin{bmatrix} \frac{1}{3}&0 \\ \frac{2}{3}&\frac{1}{\sqrt{2}} \\ \frac{2}{3}&-\frac{1}{\sqrt{2}} \end{bmatrix}

R = \begin{bmatrix} 3&3 \\ 0&\sqrt{2} \end{bmatrix}

To find the least squares solution \bar{x} to Ax = b where b = (1, 1, 1), we take advantage of the fact that R\bar{x} = Q^Tb.

On the right side of the equation we have

Q^Tb = \begin{bmatrix} \frac{1}{3}&\frac{2}{3}&\frac{2}{3} \\ 0&\frac{1}{\sqrt{2}}&-\frac{1}{\sqrt{2}} \end{bmatrix} \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix} = \begin{bmatrix} \frac{5}{3} \\ 0 \end{bmatrix}

so that the system R\bar{x} = Q^Tb is then

\begin{bmatrix} 3&3 \\ 0&\sqrt{2} \end{bmatrix} \begin{bmatrix} \bar{x_1} \\ \bar{x_2} \end{bmatrix} = \begin{bmatrix} \frac{5}{3} \\ 0 \end{bmatrix}

From the second equation we have \bar{x_2} = 0. Substituting into the first equation we have 3\bar{x_1} + 3\bar{x_2} = 3\bar{x_1} + 3 \cdot 0 = \frac{5}{3} so that 3\bar{x_1} = \frac{5}{3} or \bar{x_1} = \frac{5}{9}.

The least squares solution to Ax = b with b = (1, 1, 1) is therefore \bar{x} = (\frac{5}{9}, 0).

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.4.16

Exercise 3.4.16. Given the matrix A whose columns are the following two vectors a_1 and a_3 [sic]:

a_1 = \begin{bmatrix} 1 \\ 2 \\ 2 \end{bmatrix} \quad a_3 = \begin{bmatrix} 1 \\ 3 \\ 1 \end{bmatrix}

factor A as A = QR. If there are n vectors a_j with m elements each, what are the dimensions of A, Q, and R?

Answer: With a_1 and a_3 as the two columns of A, we first choose a_1' = a_1 = (1, 2, 2). We then have

a_3' = a_3 - \frac{(a_1')^Ta_3}{(a_1')^Ta_1'}a_1' = a_3 - \frac{1 \cdot 1 + 2 \cdot 3 + 2 \cdot 1}{1^2 + 2^2  + 2^2}a_1' = a_3 - \frac{9}{9}a_1' = a_3 - a_1'

= \begin{bmatrix} 1 \\ 3 \\ 1 \end{bmatrix} - \begin{bmatrix} 1 \\ 2 \\ 2 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \\ -1 \end{bmatrix}

Now that we have calculated the orthogonal vectors a_1' and a_3' we can normalize them to create the orthonormal vectors q_1 and q_3. We have

\|a_1'\| = \sqrt{1^2 + 2^2 + 2^2} = \sqrt{9} = 3

\|a_3'\| = \sqrt{0^2 + 1^2 + (-1)^2} = \sqrt{2}

so that

q_1 = a_1' / \|a_1'\| = \frac{1}{3} \begin{bmatrix} 1 \\ 2 \\ 2 \end{bmatrix} = \begin{bmatrix} \frac{1}{3} \\ \frac{2}{3} \\ \frac{2}{3} \end{bmatrix}

q_3 = a_3' / \|a_3'\| = \frac{1}{\sqrt{2}} \begin{bmatrix} 0 \\ 1 \\ -1 \end{bmatrix} = \begin{bmatrix} 0 \\ \frac{1}{\sqrt{2}} \\ -\frac{1}{\sqrt{2}} \end{bmatrix}

The matrix Q is the 3 by 2 matrix with columns q_1 and q_3:

Q = \begin{bmatrix} \frac{1}{3}&0 \\ \frac{2}{3}&\frac{1}{\sqrt{2}} \\ \frac{2}{3}&-\frac{1}{\sqrt{2}} \end{bmatrix}

The matrix R is the 2 by 2 matrix calculated as follows:

R = \begin{bmatrix} q_1^Ta_1&q_1^Ta_3 \\ 0&q_3^Ta_3 \end{bmatrix} = \begin{bmatrix} \frac{1}{3} \cdot 1 + \frac{2}{3} \cdot 2 + \frac{2}{3} \cdot 2&\frac{1}{3} \cdot 1 + \frac{2}{3} \cdot 3 + \frac{2}{3} \cdot 1 \\ 0&0 \cdot 1 + \frac{1}{\sqrt{2}} \cdot 3 + (-\frac{1}{\sqrt{2}}) \cdot 1 \end{bmatrix}

= \begin{bmatrix} \frac{9}{3}&\frac{9}{3} \\ 0&\frac{2}{\sqrt{2}} \end{bmatrix} = \begin{bmatrix} 3&3 \\ 0&\sqrt{2} \end{bmatrix}

If there are n vectors a_j with m elements each, since they form the columns of A the shape of A will be m by n. The matrix Q contains one orthonormal column for each column in A, and its orthonormal columns have the same number of elements as the columns of A, so Q is also m by n. Finally, R is a square matrix with one column for each column of Q, so it is n by n.

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.4.15

Exercise 3.4.15. Given the matrix

A = \begin{bmatrix} 1&1 \\ 2&-1 \\ -2&4 \end{bmatrix}

find the orthonormal vectors q_1 and q_2 that span the column space of A. Next find the vector q_3 that completes the orthonormal set, and describe the subspace of A of which q_3 is an element. Finally, for b = (1, 2, 7) find the least squares solution \bar{x} to Ax = b.

Answer: With a and b as the columns of A, we first choose a' = a = (1, 2, -2). We then have

b' = b - \frac{(a')^Tb}{(a')^Ta'}a' = b - \frac{1 \cdot 1 + 2 \cdot (-1) + (-2) \cdot 4}{1^2 + 2^2  + (-2)^2}a' = b - \frac{-9}{9}a' = b + a'

= \begin{bmatrix} 1 \\ -1 \\ 4 \end{bmatrix} + \begin{bmatrix} 1 \\ 2 \\ -2 \end{bmatrix} = \begin{bmatrix} 2 \\ 1 \\ 2 \end{bmatrix}

Now that we have calculated the orthogonal vectors a' and b' we can normalize them to create the orthonormal vectors q_1 and q_2. We have

\|a'\| = \sqrt{1^2 + 2^2 + (-2)^2} = \sqrt{9} = 3

\|b'\| = \sqrt{2^2 + 1^2 + 2^2} = \sqrt{9} = 3

so that

q_1 = a' / \|a'\| = \frac{1}{3} \begin{bmatrix} 1 \\ 2 \\ -2 \end{bmatrix} = \begin{bmatrix} \frac{1}{3} \\ \frac{2}{3} \\ -\frac{2}{3} \end{bmatrix}

q_2 = b' / \|b'\| = \frac{1}{3} \begin{bmatrix} 2 \\ 1 \\ 2 \end{bmatrix} = \begin{bmatrix} \frac{2}{3} \\ \frac{1}{3} \\ \frac{2}{3} \end{bmatrix}

Since a and b span the column space of A, and the orthonormal vectors q_1 and q_2 are linear combinations of a and b, q_1 and q_2 also span the column space of A.

Next, we calculate q_3. We can do this by orthogonalizing any vector c that is linearly independent of a and b. For ease of calculation we start with c = (1, 0, 0). We then have

c' = c - \frac{(a')^Tc}{(a')^Ta'}a' - \frac{(b')^Tc}{(b')^Tb'}b' = c - \frac{1 \cdot 1 + 2 \cdot 0 + (-2) \cdot 0}{1^2 + 2^2  + (-2)^2}a' - \frac{2 \cdot 1 + 1 \cdot 0 + 2 \cdot 0}{1^2 + 2^2  + (-2)^2}b' = c - \frac{1}{9}a' - \frac{2}{9}b'

= \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} - \frac{1}{9} \begin{bmatrix} 1 \\ 2 \\ -2 \end{bmatrix} - \frac{2}{9} \begin{bmatrix} 2 \\ 1 \\ 2 \end{bmatrix} = \begin{bmatrix} \frac{4}{9} \\ -\frac{4}{9} \\ -\frac{2}{9} \end{bmatrix}

To normalize c' we divide by

\|c'\| = \sqrt{(-\frac{4}{9})^2 + (-\frac{4}{9})^2 + (-\frac{2}{9})^2} = \sqrt{\frac{36}{81}} = \frac{2}{3}

so that

q_3 = c' / \|c'\| = \frac{3}{2}  \begin{bmatrix} \frac{4}{9} \\ -\frac{4}{9} \\ -\frac{2}{9} \end{bmatrix} = \begin{bmatrix} \frac{2}{3} \\ -\frac{2}{3} \\ -\frac{1}{3} \end{bmatrix}

Of the four fundamental subspaces of A, the left nullspace \mathcal{N}(A^T) is orthogonal to the column space \mathcal{R}(A). Since q_1 and q_2 span the column space \mathcal{R}(A) and q_3 is orthogonal to q_1 and q_2, q_3 must be an element of the left nullspace \mathcal{N}(A^T).

Finally, to find the least squares solution \bar{x} to Ax = b where b = (1, 2, 7), we factor A = QR and take advantage of the fact that R\bar{x} = Q^Tb.

The matrix Q is simply the 3 by 2 matrix with columns q_1 and q_2:

Q = \begin{bmatrix} \frac{1}{3}&\frac{2}{3} \\ \frac{2}{3}&\frac{1}{3} \\ -\frac{2}{3}&\frac{2}{3} \end{bmatrix}

The upper triangular matrix R is a 2 by 2 matrix with

R = \begin{bmatrix} q_1^Ta&q_1^Tb \\ 0&q_2^Tb \end{bmatrix} = \begin{bmatrix} \frac{1}{3} \cdot 1 + \frac{2}{3} \cdot 2 + (-\frac{2}{3}) \cdot (-2)&\frac{1}{3} \cdot 1 + \frac{2}{3} \cdot (-1) + (-\frac{2}{3}) \cdot 4 \\ 0&\frac{2}{3} \cdot 1 + \frac{1}{3} \cdot (-1) + \frac{2}{3} \cdot 4 \end{bmatrix}

= \begin{bmatrix} 3&-3 \\ 0&3 \end{bmatrix}

On the right side of the equation R\bar{x} = Q^Tb we have

Q^Tb = \begin{bmatrix} \frac{1}{3}&\frac{2}{3}&-\frac{2}{3} \\ \frac{2}{3}&\frac{1}{3}&\frac{2}{3} \end{bmatrix} \begin{bmatrix} 1 \\ 2 \\ 7 \end{bmatrix} = \begin{bmatrix} -\frac{9}{3} \\ \frac{18}{3} \end{bmatrix} = \begin{bmatrix} -3 \\ 6 \end{bmatrix}

so that the entire system is then

\begin{bmatrix} 3&-3 \\ 0&3 \end{bmatrix} \begin{bmatrix} \bar{x_1} \\ \bar{x_2} \end{bmatrix} = \begin{bmatrix} -3 \\ 6 \end{bmatrix}

From the second equation we have 3\bar{x_2} = 6 or \bar{x_2} = 2. Substituting into the first equation we have 3\bar{x_1} - 3\bar{x_2} = 3\bar{x_1} - 3 \cdot 2 = 3 so that 3\bar{x_1} = 3 + 6 = 9 or \bar{x_1} = 3.

The least squares solution to Ax = b with b = (1, 2, 7) is therefore \bar{x} = (3, 2).

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