[Math] Find the distance between a point and a hyperplane in $\mathbb{R}^n$

maxima-minimaoptimization

I was reading this thread and it uses minimization to derive the distance formula between a point and a line. I'm stuck on using minimization to derive the distance formula between a point and a hyperplane in $\mathbb{R}^n$. I know that the distance formula should be

$$\frac{|a_1x_0^{(1)} + a_2x_0^{{(2) }} + b|}{\sqrt{a_1^2 + \cdots + a_n^2}}$$

Assuming that the equation of the hyperplane is $a_1x_1 + \cdots + a_nx_n+b = 0.$

First of all, I'm not sure how I can use the substitution technique when I have $n$ variables. Depending on the answer to the first question, I'm not sure if the problem would become algebraically untractable since there are so many unknowns. Am I tackling this the wrong way?

Best Answer

You’ve got a good start. Letting the point be $\mathbf x = (x_1,\dots,x_n)$ and the equation of the plane $a_1y_1+\dots+a_ny_n+b=\mathbf a\cdot\mathbf y+b=0$, you can set up a Lagrange multiplier problem with objective function $f(\mathbf y) = \sum_{i=1}^n(y_i-x_i)^2$. Differentiating gives a system of linear equations of the form $$2\left(y_i-x_i\right)-a_i\lambda = 0,\tag{*}$$ so $$y_i-x_i = \frac12 a_i\lambda$$ and $$f(\mathbf y)=\frac14 \lambda^2 \sum_{i=1}^na_i^2,$$ therefore the minimal distance to the plane is $\frac12 |\lambda| \|\mathbf a\|$.

To find $\lambda$, add $-\frac12 a_i$ times each of the respective (*) equations to the equation of the plane, producing $$\frac12\lambda\sum_{i=1}^na_i^2+\sum_{i=1}^na_ix_i+b=0,$$ or $$\frac12\lambda\|\mathbf a\|^2 = -\mathbf a\cdot\mathbf x-b.$$ Combining this with the previously-derived expression for the distance to the plane gives $${|\mathbf a\cdot\mathbf x+b| \over \|\mathbf a\|}$$ for this distance, as required.

Related Question