# find minimum of a function with abs and squares analytically

maybe someone here can help me. I want to find the analytical minimum '$x_\mathrm{opt} = \arg\min f(x)$' of the following function: $$f(x) = \alpha |c + x| + \beta x^2$$ where $x$ is a real number ($x$ is_element_of $\mathbb{R}$), $c$ is a real constant ($c$ is_element_of $\mathbb{R}$), $\alpha$ and $\beta$ are positive real constants ($\alpha$ is_element_of $\mathbb{R}^+$, $\beta$ is_element_of $\mathbb{R}^+$) and $|\cdot|$ is the absolute value function.

Looks simple, but the absolute value function makes it tricky (at least for me...). As already mentioned, i want to find the solution to this minimization problem analytically, not numerically.

-
Consider the three cases $x<-c$, $x=-c$, $x>-c$ separately. – Eckhard Dec 23 '12 at 12:08
thx for the comment, was very helpful... For the three cases i have now the solutions – Richard Hoepfelsson Dec 23 '12 at 13:08
thx for the comment, was very helpful ! For the three cases I have now the solutions x_opt = alpha/(2*beta) [for x < -c], x_opt = -c [for x = -c], and x_opt = -alpha/(2*beta) [for x > -c]. But how to 'combine' these solutions now to get the solution 'x_opt' (as a function of 'x') ? – Richard Hoepfelsson Dec 23 '12 at 13:16

As in @coffeemath's answer, there are three points where the minimum can occur: \begin{align} x_1 &= \frac\alpha{2\beta} & \text{for} & x<-c, \\ x_2 &= -c & \text{for} & x=-c, \\ x_3 &= \frac{-\alpha}{2\beta} & \text{for} & x>-c. \\ \end{align}

However, $x_1$ is a minimum only if it lies in its domain $x<-c$, that is, if $-c>\frac\alpha{2\beta}$. Similarly, $x_2$ counts only if $-c<-\frac\alpha{2\beta}$. Also, $f$ is convex on $x\le-c$, so if $x_1$ is a minimum, then $x_2=c$ cannot be; the same goes for $x_3$ vs. $x_2$ over $x\ge-c$. So we get three disjoint cases depending on the value of $-c$ with respect to $\pm\frac\alpha{2\beta}$, and we can write out the solution explicitly: $$x_\text{opt}=\begin{cases} \frac\alpha{2\beta} & \text{if }{-}c>\frac\alpha{2\beta}, \\ -c & \text{if }{-}\frac\alpha{2\beta}\le -c\le\frac\alpha{2\beta}, \\ -\frac\alpha{2\beta} & \text{if }{-}c<-\frac\alpha{2\beta}. \\ \end{cases}$$

It amuses me to observe that this can actually be written more compactly as $$x_{\text{opt}} = \operatorname{clamp}\left(-c, \left[-\frac\alpha{2\beta}, \frac\alpha{2\beta}\right]\right)$$ where $\operatorname{clamp}(t,[a,b]) = \min(\max(t,a),b)$ is the point closest to $t$ in the interval $[a,b]$.

-

The values of $x$ at the minimum in the three cases need to be put back into $f(x)$ in order to decide the minimum. These are

case $x<-c$ : $x=\alpha/(2 \beta)$ and then $$f(x)=-\alpha c - \frac{\alpha}{4 \beta ^2},$$

case $x=-c$ : $$f(x)=\beta c^2,$$

case $x>-c$ : $x=- \alpha/(2 \beta)$ and then $$f(x)= \alpha c - \frac{\alpha}{4 \beta ^2}.$$

Now the decision as to which if these three is the minimum value of $f(x)$ will depend on the values of $\alpha, \beta, c.$ It looks like, depending on these values, any one of the three possible optima might be the actual minimum.

-
thx for all answers, was very helpful ! btw I found a nice paper which solves a 'generalized' version of this problem. Paper is "a new median formula with applications to PDE based denosing" by Li & Osher. – Richard Hoepfelsson Jan 10 '13 at 19:45