Lab 10. Inner Products, Projections, QR, and Adjoints: Independent Study

This lab accompanies Chapter 10: Inner Product Spaces, Orthogonal Projection, QR Factorization, and Adjoints.

The goal is to connect geometry and computation:

  1. Inner products define length, angle, and orthogonality.
  2. Projection finds the closest point in a subspace.
  3. Gram–Schmidt turns an independent set into an orthonormal set.
  4. QR factorization packages Gram–Schmidt into matrix form.
  5. Least squares is projection onto a column space.
  6. Adjoints generalize transpose and conjugate transpose.

This is an independent-study lab. Each main question includes a worked solution and a similar practice question.

Python practice notebook

You may use the Jupyter notebook version for longer Python practice:

Interactive lab

Study guide and worked questions

Question 1. Compute an inner product and angle

Let

\[ u=\begin{bmatrix}1\\2\\-1\end{bmatrix}, \qquad v=\begin{bmatrix}3\\0\\4\end{bmatrix}. \]

Compute \(u\cdot v\), \(\|u\|\), \(\|v\|\), and the angle between \(u\) and \(v\).

Solution

\[ u\cdot v=1(3)+2(0)+(-1)(4)=-1. \]

Also,

\[ \|u\|=\sqrt{1^2+2^2+(-1)^2}=\sqrt6, \qquad \|v\|=\sqrt{3^2+0^2+4^2}=5. \]

Therefore

\[ \cos\theta=\frac{u\cdot v}{\|u\|\|v\|} =\frac{-1}{5\sqrt6}. \]

So

\[ \theta=\arccos\left(\frac{-1}{5\sqrt6}\right). \]

Similar practice

Let

\[ a=\begin{bmatrix}2\\-1\\2\end{bmatrix}, \qquad b=\begin{bmatrix}1\\3\\0\end{bmatrix}. \]

Compute \(a\cdot b\), \(\|a\|\), \(\|b\|\), and the angle between them.

Answer

\[ a\cdot b=2(1)+(-1)(3)+2(0)=-1. \]

\[ \|a\|=3, \qquad \|b\|=\sqrt{10}. \]

Thus

\[ \cos\theta=-\frac{1}{3\sqrt{10}}. \]

Question 2. Projection onto a line

Let

\[ y=\begin{bmatrix}4\\1\\2\end{bmatrix}, \qquad w=\begin{bmatrix}1\\2\\0\end{bmatrix}. \]

Find \(\operatorname{proj}_{\operatorname{span}\{w\}}(y)\) and the residual.

Solution

The projection formula is

\[ \operatorname{proj}_{\operatorname{span}\{w\}}(y) =\frac{y\cdot w}{w\cdot w}w. \]

Here

\[ y\cdot w=4(1)+1(2)+2(0)=6, \qquad w\cdot w=1^2+2^2=5. \]

Therefore

\[ \operatorname{proj}_{\operatorname{span}\{w\}}(y) =\frac65\begin{bmatrix}1\\2\\0\end{bmatrix} =\begin{bmatrix}6/5\\12/5\\0\end{bmatrix}. \]

The residual is

\[ r=y-\operatorname{proj}(y) =\begin{bmatrix}14/5\\-7/5\\2\end{bmatrix}. \]

Check:

\[ r\cdot w=\frac{14}{5}-\frac{14}{5}=0. \]

Similar practice

Let

\[ y=\begin{bmatrix}2\\3\\1\end{bmatrix}, \qquad w=\begin{bmatrix}1\\1\\0\end{bmatrix}. \]

Find the projection of \(y\) onto \(\operatorname{span}\{w\}\).

Answer

\[ y\cdot w=5, \qquad w\cdot w=2, \] so

\[ \operatorname{proj}(y)=\frac52\begin{bmatrix}1\\1\\0\end{bmatrix} =\begin{bmatrix}5/2\\5/2\\0\end{bmatrix}. \]

Question 3. Gram–Schmidt

Apply Gram–Schmidt to

\[ b_1=\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad b_2=\begin{bmatrix}1\\0\\1\end{bmatrix}. \]

Find an orthonormal basis for their span.

Solution

First,

\[ v_1=b_1=\begin{bmatrix}1\\1\\1\end{bmatrix}. \]

Next,

\[ v_2=b_2-\frac{b_2\cdot v_1}{v_1\cdot v_1}v_1. \]

Since

\[ b_2\cdot v_1=2, \qquad v_1\cdot v_1=3, \]

we get

\[ v_2=\begin{bmatrix}1\\0\\1\end{bmatrix} -\frac23\begin{bmatrix}1\\1\\1\end{bmatrix} =\begin{bmatrix}1/3\\-2/3\\1/3\end{bmatrix}. \]

Normalize:

\[ u_1=\frac{1}{\sqrt3}\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad u_2=\frac{1}{\sqrt6}\begin{bmatrix}1\\-2\\1\end{bmatrix}. \]

Similar practice

Apply Gram–Schmidt to

\[ c_1=\begin{bmatrix}1\\1\\0\end{bmatrix}, \qquad c_2=\begin{bmatrix}1\\0\\1\end{bmatrix}. \]

Answer

An orthonormal basis is

\[ u_1=\frac{1}{\sqrt2}\begin{bmatrix}1\\1\\0\end{bmatrix}, \qquad u_2=\frac{1}{\sqrt6}\begin{bmatrix}1\\-1\\2\end{bmatrix}. \]

Question 4. QR factorization

Let

\[ A=\begin{bmatrix}1&1\\1&0\\1&1\end{bmatrix}. \]

Find a QR factorization using Gram–Schmidt.

Solution

The columns are

\[ b_1=\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad b_2=\begin{bmatrix}1\\0\\1\end{bmatrix}. \]

From Question 3,

\[ q_1=\frac{1}{\sqrt3}\begin{bmatrix}1\\1\\1\end{bmatrix}, \qquad q_2=\frac{1}{\sqrt6}\begin{bmatrix}1\\-2\\1\end{bmatrix}. \]

Thus

\[ Q=\begin{bmatrix} 1/\sqrt3&1/\sqrt6\\ 1/\sqrt3&-2/\sqrt6\\ 1/\sqrt3&1/\sqrt6 \end{bmatrix}. \]

The matrix \(R\) has entries

\[ r_{11}=\|b_1\|=\sqrt3, \qquad r_{12}=q_1\cdot b_2=\frac{2}{\sqrt3}, \qquad r_{22}=\frac{\sqrt6}{3}. \]

Therefore

\[ R=\begin{bmatrix} \sqrt3&2/\sqrt3\\ 0&\sqrt6/3 \end{bmatrix}. \]

Similar practice

Use Python to compute a QR factorization for

\[ B=\begin{bmatrix}1&0\\1&1\\0&1\end{bmatrix}. \]

Answer

Python’s QR may differ by signs, but it should satisfy

\[ B=QR, \qquad Q^TQ=I. \]

Question 5. Least squares by QR

Suppose

\[ A=\begin{bmatrix}1&1\\1&2\\1&3\\1&4\end{bmatrix}, \qquad b=\begin{bmatrix}1.1\\1.9\\3.2\\3.9\end{bmatrix}. \]

Explain how QR solves the least-squares problem.

Solution

If \(A=QR\) with \(Q^TQ=I\), then the least-squares solution satisfies

\[ R\widehat{x}=Q^Tb. \]

This avoids forming \(A^TA\) and is usually more stable than the normal equations.

Similar practice

For the same \(A\), replace \(b\) by

\[ b=\begin{bmatrix}2\\2.9\\4.1\\5.2\end{bmatrix}. \]

Compute the least-squares line using Python.

Answer

Use np.linalg.qr(A) and solve R @ x = Q.T @ b, or use np.linalg.lstsq(A,b,rcond=None).

Question 6. Adjoint matrix

Let

\[ A=\begin{bmatrix}1&i\\2&1-i\end{bmatrix}. \]

Compute \(A^*\).

Solution

Conjugate first:

\[ \overline A=\begin{bmatrix}1&-i\\2&1+i\end{bmatrix}. \]

Then transpose:

\[ A^*=\overline A^T=\begin{bmatrix}1&2\\-i&1+i\end{bmatrix}. \]

Similar practice

Compute the adjoint of

\[ B=\begin{bmatrix}2&3i\\1-i&4\end{bmatrix}. \]

Answer

\[ B^*=\begin{bmatrix}2&1+i\\-3i&4\end{bmatrix}. \]

Reflection questions

  1. Why is projection a best-approximation problem?
  2. Why does the residual in least squares have to be orthogonal to the column space?
  3. Why is QR more stable than normal equations?
  4. Why does complex linear algebra use conjugate transpose instead of ordinary transpose?

AI companion activities

Use an AI assistant to check your understanding:

  • Ask it to generate a new projection problem and solve it step by step.
  • Ask it to check a Gram–Schmidt computation for arithmetic errors.
  • Ask it to explain QR factorization geometrically.
  • Ask it to compare least squares by normal equations and by QR.
  • Ask it to explain adjoints in real and complex inner product spaces.