minimizing squared distance for point to a set of lines I have this problem that I cannot figure out how to solve. It is from Szeliski's computer vision book (http://szeliski.org/Book/drafts/SzeliskiBook_20100903_draft.pdf) p.94 (electronic version) and is as follows:
If you are given more than two lines and want to find a point $\widetilde{x}$ that minimizes the sum of squared distances to each line,
$$
D = \sum_{i}(\widetilde{x} \cdot \widetilde{l}_i)^2
$$
how can you compute this quantity? (Hint: Write the dot product as $\widetilde{x}^T\widetilde{l_i}$ and turn the squared quantity into a quadratic form, $\widetilde{x}^TA\widetilde{x}$.)
The tilde sign is used to denote points in homogenous coordinates.
I have turned the expression into this expression, which is the authors hint:
$$
\sum_{i}(\widetilde{x}^T\widetilde{l_i})(\widetilde{x}^T\widetilde{l_i}) = \sum_{i}(\widetilde{x}^T\widetilde{l_i})(\widetilde{l_i}^T\widetilde{x}) = \sum_{i}\widetilde{x}^TA\widetilde{x}
$$
A is then: $\widetilde{l_i}\widetilde{l_i}^T$
How do I proceed from here? How does rewriting the sum to a sum of quadratic from help me? I can take the derivative and find a x that minimizes the squared sum?
The lines are in 2D expressed using homogenous coordinates resulting in 3D vectors. Does anyone know how to solve this using the quadratic form expression (using matrix stuff)
 A: I'll try to  keep it concrete, without matrix notation. For each line find  a vector $(a_i,b_i)$ of unit norm that is perpendicular to  it. (Take two points on the line, subtract to get a vector,  rotate by 90 degrees, and divide by the length.) The equation of the line is of the form $a_ix+b_iy+c_i=0$. Here  $a_ix+b_iy+c_i$ is the distance to the line, up to the sign. So, the sum of squared distances is 
$$
\sum_i (a_ix+b_iy+c_i)^2
$$
To minimize, take partial derivatives and set them to zero: 
$$
\sum_i 2a_i(a_ix+b_iy+c_i) =0,\qquad \sum_i 2b_i(a_ix+b_iy+c_i) =0
$$
This is a pretty simple system (2 equations, 2 unknowns), which can be written as 
$$ x\sum a_i^2 + y \sum a_i b_i + \sum a_i c_i=0, \qquad 
x\sum a_ib_i + y \sum  b_i^2 + \sum b_i c_i=0$$
The solution is unique, unless your lines are all parallel. 
A: Since the sum $\sum_i$ in $D(x)$ is over $i$ (not $x$), you can factor out $x$ to get the quadratic form: 
$$
D(x) = x^T (\sum_i l_i l_i^T) x = x^T A x.
$$
The rest is about minimizing quadratic forms. To prevent duplication, see [1] for how to minimize that.
[1] Minimization of a convex quadratic form
