I have this formula
$$r(x) = \sqrt{x^2 + (Kx + M)^2}$$
Where $Kx + M$ is the straight line equation. My goal is to use the L2 norm to find the shortest distance beteen origo (0,0) and the straight line, by selecting $x$.
So I want to find the minimum $r$. Can this be done using an algorithm, or can I minimize this equation in an exact way?
An alternative to the other answer is to use calculus.
Minimizing $r(x)$ is the same as minimizing:
$$R(x)=[r(x)]^2=x^2+(Kx+M)^2$$
The first-order condition is
$$R'(x)=2x+2K(Kx+M)=2(1+K^2)x+2KM=0$$
The solution to the first-order condition is
$$x^*=-\frac{KM}{1+K^2}.$$
We also have for all $x$:
$$R''(x)=2(1+K^2)>0$$
so that $R$ is (strictly) convex. Thus $x^*$ is the unique minimizer of $R$ and hence of $r$.