8 Orthogonality And Least Squares

Mathematics II Ā· Unit 8 Ā· 5 hrs

Orthogonality and Least Squares

Exam-focused notes for Orthogonality and Least Squares (Mathematics II, MTH168): what the TU syllabus asks and how it has actually been tested, with 14 solved past questions from this unit.

Orthogonality and Least Squares in short

This chapter adds geometry, length, angle, and perpendicularity, to the algebra of vectors, and uses it to solve the practical problem of finding the "best" approximate solution when a linear system $A\mathbf{x} = \mathbf{b}$ has no exact solution.

Orthogonality and Least Squares: notes

Inner product, length, and orthogonality

For $\mathbf{u} = (u_1, \ldots, u_n)$ and $\mathbf{v} = (v_1, \ldots, v_n)$ in $\mathbb{R}^n$, the inner (or dot) product is $\mathbf{u}\cdot\mathbf{v} = u_1v_1 + \cdots + u_nv_n$, satisfying $\mathbf{u}\cdot\mathbf{v} = \mathbf{v}\cdot\mathbf{u}$, distributivity over addition, $(c\mathbf{u})\cdot\mathbf{v} = c(\mathbf{u}\cdot\mathbf{v})$, and $\mathbf{u}\cdot\mathbf{u} \geq 0$ with equality only when $\mathbf{u} = \mathbf{0}$. The length (norm) of $\mathbf{v}$ is $|\mathbf{v}| = \sqrt{\mathbf{v}\cdot\mathbf{v}}$, and a vector of length $1$ is a unit vector; dividing any nonzero $\mathbf{v}$ by $|\mathbf{v}|$ normalizes it. The distance between $\mathbf{u}$ and $\mathbf{v}$ is $\operatorname{dist}(\mathbf{u},\mathbf{v}) = |\mathbf{u}-\mathbf{v}|$. Two vectors are orthogonal if $\mathbf{u}\cdot\mathbf{v} = 0$, and the angle $\theta$ between nonzero vectors in $\mathbb{R}^2$ or $\mathbb{R}^3$ satisfies $\cos\theta = \dfrac{\mathbf{u}\cdot\mathbf{v}}{|\mathbf{u}||\mathbf{v}|}$.

Worked example. For $\mathbf{u} = (2,3)$ and $\mathbf{v} = (3,-1)$, $\mathbf{u}-\mathbf{v} = (-1,4)$, so $\operatorname{dist}(\mathbf{u},\mathbf{v}) = \sqrt{(-1)^2+4^2} = \sqrt{17}$. Also, $\mathbf{u}=(2,-3,3)$ and $\mathbf{w}=(12,3,-5)$ satisfy $\mathbf{u}\cdot\mathbf{w} = 24 - 9 - 15 = 0$, so they are orthogonal, and for $\mathbf{p}=(1,0,-1)$, $\mathbf{q}=(-1,1,-1)$, $\mathbf{p}\cdot\mathbf{q} = -1+0+1 = 0$, so the angle between them is $\theta = \cos^{-1}(0) = 90^\circ$.

Orthogonal sets

A set ${\mathbf{u}_1, \ldots, \mathbf{u}_p}$ is an orthogonal set if $\mathbf{u}_i \cdot \mathbf{u}_j = 0$ whenever $i \neq j$. Every orthogonal set of nonzero vectors is automatically linearly independent, so an orthogonal set of $n$ nonzero vectors in an $n$-dimensional space is automatically a basis, called an orthogonal basis. An orthonormal set is an orthogonal set of unit vectors; an $m \times n$ matrix $U$ has orthonormal columns exactly when $U^TU = I_n$.

Worked example. The vectors $(1,1,1)$, $(1,-1,0)$, $(1,1,-2)$ are pairwise orthogonal: $(1,1,1)\cdot(1,-1,0) = 0$, $(1,1,1)\cdot(1,1,-2) = 0$, and $(1,-1,0)\cdot(1,1,-2) = 0$. Since all three are nonzero and pairwise orthogonal, they are linearly independent, and being three vectors in $\mathbb{R}^3$, they form an orthogonal basis for $\mathbb{R}^3$.

What this unit covers

  • Inner product, Length, and orthoganility
  • Orthogonal sets
  • Orthogonal projections
  • The Gram-Schmidt process
  • Least squares problems
  • Application to linear models
  • Inner product spaces
  • Applications of inner product spaces

Least squares problems

2080 Ā· 10 marks

Find the least square solution of $Ax = c$ where

$$A = \begin{bmatrix} 1 & -3 & 3 \ 1 & 5 & 1 \ 1 & 7 & 2 \end{bmatrix}, \quad c = \begin{bmatrix} 5 \ -3 \ 5 \end{bmatrix}$$

and compute the associated least square error. [10+0]

$$A = \begin{bmatrix} 1 & -3 & 3 \ 1 & 5 & 1 \ 1 & 7 & 2 \end{bmatrix}, \quad c = \begin{bmatrix} 5 \ -3 \ 5 \end{bmatrix}$$ We solve the normal equations $A^TA\hat{x} = A^Tc$. --- $$A^T = \begin{bmatrix} 1 & 1 & 1 \ -3 & 5 & 7 \ 3 & 1 & 2 \end{bmatrix}$$ $$A^TA = \begin{bmatrix} 3 & 9 & 6 ...

Open this answer on its own page →

2080 Ā· 5 marks

Find the equation $y = a_0 + a_1 x$ of the least squares line that best fits the data points (2,1), (5,2), (7,3), (8,3). [5]

Show solved answer

Least Squares Line: $y = a_0 + a_1x$

Given data

Points: $(2,1), (5,2), (7,3), (8,3)$, with $n = 4$.

Normal Equations

$$\sum y = na_0 + a_1\sum x$$ $$\sum xy = a_0\sum x + a_1\sum x^2$$

Computing Sums

$x$$y$$x^2$$xy$
2142
522510
734921
836424
$\sum x=22$$\sum y=9$$\sum x^2=142$$\sum xy=57$

Substituting

$$9 = 4a_0 + 22a_1 \quad (1)$$ $$57 = 22a_0 + 142a_1 \quad (2)$$

Solving

Multiply (1) by 22, (2) by 4:

$$198 = 88a_0 + 484a_1 \quad (3)$$ $$228 = 88a_0 + 568a_1 \quad (4)$$

Subtract (3) from (4):

$$30 = 84a_1 \implies a_1 = \frac{30}{84} = \frac{5}{14} \approx 0.357$$

Substitute into (1):

$$9 = 4a_0 + 22\cdot\frac{5}{14} = 4a_0 + \frac{55}{7}$$ $$4a_0 = 9 - \frac{55}{7} = \frac{8}{7} \implies a_0 = \frac{2}{7} \approx 0.286$$

Result

$$\boxed{y = \frac{2}{7} + \frac{5}{14}x \approx 0.286 + 0.357x}$$

Open this answer on its own page →

2079 Ā· 10 marks

Find the equation $y = a_0 + a_1 x$ of the least square line that best fits the data points (0, 1), (1, 1), (1, 1), (2, 2), (3, 2).[10]

Data points to fit with $y = a0 + a1 x$: $x$ $y$ ---------- 0 1 1 1 1 1 2 2 3 2 Number of data points: $n = 5$ (the point $(1,1)$ appears twice; both are used). $x$ $y$ $x^2$ $xy$ ----------------------- 0 1 0 0 1 1 1 1 1 1 1 1 2 2 4 4 3 2 9 6 $$\sum x = 7,\quad \sum y = 7,\quad \sum x^2 = 15,\qu...

Open this answer on its own page →

2078 Ā· 10 marks

Find a least square solution of the inconsistent system $Ax=b$ for

$$A = \begin{bmatrix} -1 & 2 \ 2 & -3 \ -1 & 3 \end{bmatrix}, \quad b = \begin{bmatrix} 4 \ 2 \ 1 \end{bmatrix}$$

[10]

$$A = \begin{bmatrix} -1 & 2 \ 2 & -3 \ -1 & 3 \end{bmatrix}, \qquad b = \begin{bmatrix} 4 \ 2 \ 1 \end{bmatrix}$$ Unknown: $\hat{x} = \begin{bmatrix} x1 \ x2 \end{bmatrix}$ The least square solution satisfies the normal equations: $$A^T A ,\hat{x} = A^T b$$ $$A^T = \begin{bmatrix} -1 & 2 &...

Open this answer on its own page →

2076 Ā· 10 marks

Find the least-square solution of $Ax = b$ for

$$A = \begin{bmatrix} 1 & -6 \ 1 & -2 \ 1 & 1 \ 1 & 7 \end{bmatrix} \text{ and } b = \begin{bmatrix} -1 \ 2 \ 1 \ 6 \end{bmatrix}$$

[10]

$$A = \begin{bmatrix} 1 & -6 \ 1 & -2 \ 1 & 1 \ 1 & 7 \end{bmatrix}, \quad b = \begin{bmatrix} -1 \ 2 \ 1 \ 6 \end{bmatrix}$$ The least-square solution solves the normal equations: $$A^T A \hat{x} = A^T b$$ --- $$A^T = \begin{bmatrix} 1 & 1 & 1 & 1 \ -6 & -2 & 1 & 7 \end{bmatrix}$$ -

Open this answer on its own page →

2075 Ā· 10 marks

Find the least-square solution of $Ax = b$ for

$$A = \begin{bmatrix} 1 & 3 & 5 \ 1 & 1 & 0 \ 1 & 1 & 2 \ 1 & 3 & 3 \end{bmatrix}, \quad b = \begin{pmatrix} 3 \ 5 \ 7 \ 3 \end{pmatrix}$$

[10]

$$A = \begin{bmatrix} 1 & 3 & 5 \ 1 & 1 & 0 \ 1 & 1 & 2 \ 1 & 3 & 3 \end{bmatrix}, \qquad b = \begin{pmatrix} 3 \ 5 \ 7 \ 3 \end{pmatrix}$$ The least-square solution $\hat{x}$ solves the normal equations: $$A^T A \hat{x} = A^T b$$ $$A^T = \begin{bmatrix} 1 & 1 & 1 & 1 \ 3 & 1 & 1 & 3 \ 5 ...

Open this answer on its own page →

2080.1 Ā· 10 marks

Find the least square solution of $Ax = b$ where and compute the associated least square error.

$$A = \begin{bmatrix} 1 & -3 & -3 \ 1 & 5 & 1 \ 1 & 7 & 2 \end{bmatrix}, \quad b = \begin{bmatrix} 5 \ -3 \ -5 \end{bmatrix}$$

[10]

$$A = \begin{bmatrix} 1 & -3 & -3 \ 1 & 5 & 1 \ 1 & 7 & 2 \end{bmatrix}, \quad b = \begin{bmatrix} 5 \ -3 \ -5 \end{bmatrix}$$ The least square solution solves the normal equation $A^TA\hat{x} = A^Tb$. --- $$A^T = \begin{bmatrix} 1 & 1 & 1 \ -3 & 5 & 7 \ -3 & 1 & 2 \end{bmatrix}$$ $$A^TA = ...

Open this answer on its own page →

Inner product, Length, and orthoganility

2080 Ā· 5 marks

Prove that the two vectors u and v are perpendicular to each other if and only if the line through u is perpendicular bisector of the line segment from -u to v. [5]

The line through u means the line passing through the origin in the direction of u, i.e., the set {tu : t ∈ ā„}. The line segment from -v to v has its midpoint at the origin (since (-v + v)/2 = 0). The line through u is the perpendicular bisector of the segment from -v to v if and only if: 1. The ...

Open this answer on its own page →

2079 Ā· 5 marks

Define unit vector. Find a unit vector of u = (0, -2, 2, -3) in the direction of u. [5]

Show solved answer

Given

  • Vector $\mathbf{u} = (0, -2, 2, -3)$ in $\mathbb{R}^4$
  • Task: Define unit vector; find unit vector in the direction of $\mathbf{u}$.

Solution

Definition of Unit Vector

A unit vector is a vector whose length (norm) is equal to $1$. For any nonzero vector $\mathbf{v} \in \mathbb{R}^n$, the unit vector in its direction is obtained by dividing the vector by its norm:

$$\hat{v} = \frac{\mathbf{v}}{|\mathbf{v}|}, \qquad |\mathbf{v}| = \sqrt{v_1^2 + v_2^2 + \cdots + v_n^2}$$

Finding the Unit Vector of $\mathbf{u} = (0, -2, 2, -3)$

Step 1: Compute the norm

$$|\mathbf{u}| = \sqrt{(0)^2 + (-2)^2 + (2)^2 + (-3)^2} = \sqrt{0 + 4 + 4 + 9} = \sqrt{17}$$

Step 2: Divide by the norm

$$\hat{u} = \frac{\mathbf{u}}{|\mathbf{u}|} = \frac{1}{\sqrt{17}}(0, -2, 2, -3)$$

$$\boxed{\hat{u} = \left(0,\ \frac{-2}{\sqrt{17}},\ \frac{2}{\sqrt{17}},\ \frac{-3}{\sqrt{17}}\right)}$$

Step 3: Verification

$$|\hat{u}| = \sqrt{0 + \frac{4}{17} + \frac{4}{17} + \frac{9}{17}} = \sqrt{\frac{17}{17}} = 1 \checkmark$$

The vector $\hat{u}$ has norm $1$ and points in the direction of $\mathbf{u}$, so it is the required unit vector.

Open this answer on its own page →

2078 Ā· 5 marks

Find a unit vector $v$ of $u = (1, -2, 2, 3)$ in the direction of $u$. [5]

Show solved answer

Unit Vector of u = (1, āˆ’2, 2, 3)

Given

$$u = (1,\ -2,\ 2,\ 3)$$

Step 2: Definition

The unit vector in the direction of $u$ is:

$$\hat{u} = \frac{u}{|u|}, \qquad |u| = \sqrt{u_1^2 + u_2^2 + u_3^2 + u_4^2}$$

Step 3: Compute the norm

$$|u| = \sqrt{(1)^2 + (-2)^2 + (2)^2 + (3)^2} = \sqrt{1 + 4 + 4 + 9} = \sqrt{18} = 3\sqrt{2}$$

Step 4: Compute the unit vector

$$\hat{u} = \frac{1}{3\sqrt{2}}(1,\ -2,\ 2,\ 3) = \left(\frac{1}{3\sqrt{2}},\ \frac{-2}{3\sqrt{2}},\ \frac{2}{3\sqrt{2}},\ \frac{3}{3\sqrt{2}}\right)$$

Rationalizing:

$$\hat{u} = \left(\frac{\sqrt{2}}{6},\ \frac{-\sqrt{2}}{3},\ \frac{\sqrt{2}}{3},\ \frac{\sqrt{2}}{2}\right)$$

Check

$$|\hat{u}| = \sqrt{\frac{1}{18} + \frac{4}{18} + \frac{4}{18} + \frac{9}{18}} = \sqrt{\frac{18}{18}} = 1 \checkmark$$

Hence the unit vector is confirmed.

Open this answer on its own page →

2078 Ā· 5 marks

Prove that the two vectors uuu and vvv are perpendicular to each other if and only if the line through uuu is perpendicular bisector of the line segment from āˆ’u-uāˆ’u to vvv. [5]

The line segment runs from -u to v. Its midpoint is: $$M = \frac{-\mathbf{u} + \mathbf{v}}{2}$$ The line through u (passing through the origin in the direction of u) is the perpendicular bisector of the segment from -u to v if and only if two conditions hold simultaneously: 1. u is equidistant fr...

Open this answer on its own page →

2075 Ā· 5 marks

State and prove the Pythagorean theorem of two vectors and verify this for u = (1, -1) and v = (1, 1). [5]

  • Vectors: $\mathbf{u} = (1, -1)$ and $\mathbf{v} = (1, 1)$ - Required: State and prove the Pythagorean theorem for vectors, then verify. --- If $\mathbf{u}$ and $\mathbf{v}$ are two vectors in an inner product space, then $\mathbf{u}$ and $\mathbf{v}$ are orthogonal if and only if $$\mathbf{u} ...
Open this answer on its own page →

2080.1 Ā· 5 marks

Let u = (1, -2, 2, 0). Find a unit vector of v in the same direction of u. [5]

  • Vector: $u = (1, -2, 2, 0)$ $$\u\ = \sqrt{u1^2 + u2^2 + u3^2 + u4^2}$$ $$\u\ = \sqrt{(1)^2 + (-2)^2 + (2)^2 + (0)^2} = \sqrt{1 + 4 + 4 + 0} = \sqrt{9} = 3$$ The unit vector in the same direction as $u$ is: $$v = \frac{u}{\u} = \frac{1}{3}(1, -2, 2, 0)$$ $$\boxed{v = \left(\tfrac{1}{3},\ -\tfra...
Open this answer on its own page →

The Gram-Schmidt process

2076 Ā· 5 marks

Find the QR factorization of the matrix $\begin{bmatrix} 2 & 1 \ 3 & -1 \end{bmatrix}$ [5]

Show solved answer

QR Factorization of $A = \begin{bmatrix} 2 & 1 \ 3 & -1 \end{bmatrix}$

Given

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

Columns: $$\mathbf{a_1} = \begin{bmatrix} 2 \ 3 \end{bmatrix}, \qquad \mathbf{a_2} = \begin{bmatrix} 1 \ -1 \end{bmatrix}$$

Goal: find orthogonal $Q$ and upper-triangular $R$ with $A = QR$.

Solution

First orthogonal vector

$$\mathbf{u_1} = \mathbf{a_1} = \begin{bmatrix} 2 \ 3 \end{bmatrix}, \qquad |\mathbf{u_1}| = \sqrt{4+9} = \sqrt{13}$$

$$\mathbf{q_1} = \frac{1}{\sqrt{13}}\begin{bmatrix} 2 \ 3 \end{bmatrix}$$

Second orthogonal vector

$$\mathbf{a_2}\cdot\mathbf{u_1} = (1)(2)+(-1)(3) = -1, \qquad \mathbf{u_1}\cdot\mathbf{u_1} = 13$$

$$\mathbf{u_2} = \mathbf{a_2} - \frac{-1}{13}\mathbf{u_1} = \begin{bmatrix} 1 \ -1 \end{bmatrix} + \frac{1}{13}\begin{bmatrix} 2 \ 3 \end{bmatrix} = \begin{bmatrix} \tfrac{15}{13} \ -\tfrac{10}{13} \end{bmatrix}$$

$$|\mathbf{u_2}| = \frac{1}{13}\sqrt{225+100} = \frac{\sqrt{325}}{13} = \frac{5\sqrt{13}}{13} = \frac{5}{\sqrt{13}}$$

$$\mathbf{q_2} = \frac{\mathbf{u_2}}{|\mathbf{u_2}|} = \frac{1}{\sqrt{13}}\begin{bmatrix} 3 \ -2 \end{bmatrix}$$

Matrix Q

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

Matrix R

$$R = Q^{T}A = \frac{1}{\sqrt{13}}\begin{bmatrix} 2 & 3 \ 3 & -2 \end{bmatrix}\begin{bmatrix} 2 & 1 \ 3 & -1 \end{bmatrix}$$

Compute the entries:

  • $(1,1): \frac{1}{\sqrt{13}}(2\cdot2 + 3\cdot3) = \frac{13}{\sqrt{13}} = \sqrt{13}$
  • $(1,2): \frac{1}{\sqrt{13}}(2\cdot1 + 3\cdot(-1)) = \frac{-1}{\sqrt{13}}$
  • $(2,1): \frac{1}{\sqrt{13}}(3\cdot2 + (-2)\cdot3) = 0$
  • $(2,2): \frac{1}{\sqrt{13}}(3\cdot1 + (-2)(-1)) = \frac{5}{\sqrt{13}}$

$$\boxed{R = \begin{bmatrix} \sqrt{13} & -\dfrac{1}{\sqrt{13}} \[2mm] 0 & \dfrac{5}{\sqrt{13}} \end{bmatrix}}$$

Final Answer

$$Q = \frac{1}{\sqrt{13}}\begin{bmatrix} 2 & 3 \ 3 & -2 \end{bmatrix}, \qquad R = \begin{bmatrix} \sqrt{13} & -\tfrac{1}{\sqrt{13}} \ 0 & \tfrac{5}{\sqrt{13}} \end{bmatrix}$$

Verification

$$QR = \frac{1}{\sqrt{13}}\begin{bmatrix} 2 & 3 \ 3 & -2 \end{bmatrix}\cdot\frac{1}{\sqrt{13}}\begin{bmatrix} 13 & -1 \ 0 & 5 \end{bmatrix} = \frac{1}{13}\begin{bmatrix} 26 & 13 \ 39 & -13 \end{bmatrix} = \begin{bmatrix} 2 & 1 \ 3 & -1 \end{bmatrix} = A \checkmark$$

The completed values are $R_{11}=\sqrt{13}$, $R_{12}=-1/\sqrt{13}$, $R_{21}=0$ and $R_{22}=5/\sqrt{13}$.

Open this answer on its own page →