# Some simple ways to find closest point in $S$ at some given point

I am trying to solve following problem

Let $$S$$ be the subspace of $$\mathbb{R}^4$$ which is the intersection of two planes \begin{align} &H_1 = \{(x,y,z,w) | x+ 3y - 2z + w =0\} \\ &H_2 = \{(x,y,z,w)| 2x-2y + z-w =0 \} \end{align} Find an orthogonal basis of $$S$$ and find the point in $$S$$ which is closest to the point $$(1,2,2,1)$$ (with respect to the norm defined by the usual dot product.)

Based on my previous posts Finding basis from intersection of two planes , I know how to calculate orthogonal basis of $$S$$.

Finding a orthogonal basis is the finding nullspace of $$A$$ \begin{align} A = \begin{pmatrix} 1 & 3 & -2 & 1 \\ 2 & -2 & 1 & -1 \\ 0 & 0 & 0 & 0 \\ 0& 0 & 0 & 0 \end{pmatrix} \end{align} i.e. $$B_A = \{(1,-3,0,8)^T, (1,5,8,0)^T\}$$. Now perform Gram-Schmidt process, \begin{align} u_1 = (1, -3, 0, 8)^T \quad u_2 = v_2 - \frac{(u_1, v_2)}{(u_1, u_1)}u_1 = \left( \frac{44}{37}, \frac{164}{37}, 8, \frac{56}{37} \right)^T \end{align}

Now the problem is finding the point in $$S$$ which is closest to the point $$(1,2,2,1)$$.

The point in $$S$$ can be written as a linear combination of its basis, so $$s = a u_1 + b u_2$$, and then distance from $$(1,2,2,1)$$ is given as follows

\begin{align} l^2 =\left( a + \frac{44}{37} b -1 \right)^2 + \left( -3a + \frac{164}{37} b -2\right)^2 + \left( 8b - 2 \right)^2 + \left( 8a + \frac{56}{37}b - 1 \right)^2 \end{align}

then the length is described by two parameters $$a,b$$.

By using calculus[finding $$l_x=l_y=0$$ , I tried to obtain maximum length but the computation is not good.

Let $$f=l^2$$, then from $$\frac{\partial f}{\partial a} =0$$ we have $$a=\frac{3}{74}$$ and from $$\frac{\partial f}{\partial b} =0$$ we have $$b = \frac{255}{808}$$

Are there any other ways?

• You can solve this by the discrete least-square method. – Malkoun Feb 1 at 8:09

$$S$$ is a $$2$$-dimensional subspace $$W$$ of $$\mathbb{R}^4$$. Let us say you found a basis $$w_1$$ and $$w_2$$ of $$W$$ (not necessarily orthonormal). Let $$A = (w_1 w_2)$$ be the $$4$$ by $$2$$ matrix containing $$w_1$$ its first column and $$w_2$$ as its second. Let $$\mathbf{x} = (x_1,x_2)^T$$ denote the relevant unknown coefficients. Let $$\mathbf{b} = (1,2,2,1)^T$$.

The problem is equivalent to solving $$A\mathbf{x} = \mathbf{b}$$ in the least square sense. In other words, you want to find $$\mathbf{x}$$ such that

$$E(\mathbf{x}) = \|A\mathbf{x} - \mathbf{b}\|^2$$

is minimized. This is equivalent to solving

$$A^T A \mathbf{x} = A^T \mathbf{b},$$

which is a (non-singular) linear system of two equations and two unknowns. In order to convince you that this is true, an arbitrary point of $$W$$ is of the form $$A\mathbf{x}$$ for some $$\mathbf{x}$$. Geometrically, if $$\mathbf{x} = \mathbf{\hat{x}}$$ is the point at which the distance (or distance squared) is minimized, then it is clear geometrically that $$\mathbf{b} - A\mathbf{\hat{x}}$$ must be orthogonal to $$W$$, which is equivalent to requiring that it must be orthogonal to $$w_1$$ and $$w_2$$. In other words, we must have

$$A^T(\mathbf{b} - A \mathbf{\hat{x}}) = \mathbf{0},$$

which is equivalent to

$$A^T A \mathbf{\hat{x}} = A^T \mathbf{b}.$$

Edit $$1$$: taking

$$A = \left( \begin{array}{cc} 1 & 1 \\ -3 & 5 \\ 0 & 8 \\ 8 & 0 \end{array} \right)$$

we get

$$A^T A \mathbf{x} = A^T \mathbf{b}$$

which is equivalent to

$$\left( \begin{array}{cc} 74 & -14 \\ -14 & 90 \end{array} \right) \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) = \left( \begin{array}{c} 3 \\ 27 \end{array} \right)$$

whose solution is

$$\left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) = \left( \begin{array}{c} \frac{81}{202} \\ \frac{255}{202} \end{array} \right).$$

So the point on $$W$$ closest to $$\mathbf{b}$$ is thus

$$\frac{81}{202} w_1 + \frac{255}{202} w_2,$$

where $$w_1$$ and $$w_2$$ are the first and second columns of $$A$$.