How do I do a least squares fit of the line equation $a x + b y = 1$, so that the points are as close to the line as possible? (Not just vertically close)
If I use the matrices
$X = \left[\begin{matrix} x_{1} & y_{1} \\ x_{2} & y_{2} \\ \vdots & \vdots \\ x_{n} & y_{n} \end{matrix}\right]$
$Y = \left[\begin{matrix} 1 \\ 1 \\ \vdots \\ 1 \end{matrix} \right] $
and calculate
$\left[\begin{matrix} a \\ b \end{matrix}\right] = {\left(X^{\text{T}} \cdot X\right)}^{-1} \cdot X^{\text{T}} \cdot Y,$
I will minimize the expression $\sum_{i} {\left(x_{i} a + y_{i} b - 1\right)}^{2}.$ This will not give the desired result. It will minimize the distance between $a x + b y$ and $1$.
What I really want to minimize is the expression $\sum_{i} {\left(\frac{x_{i} a + y_{i} b - 1}{\sqrt{a^{2}+b^{2}}}\right)}^{2}.$ That is, the distance to the line.
Is this easily achievable with matrix equations? Or is there some other approach that would make it easier?