Maximize function involving $\textrm{erf}(\cdot)$ I want to maximize the following function in $x$ subject to $0<x<\sqrt{2}$:
$$f(x) = \frac{x^2}{2}\left[1 - \textrm{erf}\left(\frac{cx^2}{\sqrt{2}}\right)\right],$$
where $c$ is a constant.  Is there someway i can obtain an explicit or approximate solution to the problem in terms of $c$. I know that $\textrm{erf()}$ is not a convex function, so i don't know what to do in this case.
 A: $\newcommand{gae}[1]{\newcommand{#1}{\operatorname{#1}}}\gae{maximize}\gae{erf}\newcommand{subj}{\text{subject to}}\gae{erfc}$I'll call $\erfc(x)=1-\erf(x)$ to save notation length. If $c=0$, the maximum is clearly $1$. I agree with user MarkL.Stone that you should work with $0\le x\le \sqrt2$. If $c\ne0$, make the substitution $t=\frac{\lvert c\rvert x^2}{\sqrt 2}$, so that your original problem $(A_c)$ becomes equivalent to:

*

*if $c>0$,  \begin{align}\maximize&\quad  \frac{t}{\lvert c\rvert\sqrt2}\erfc (t)&(B_c)\\\subj&\quad0\le t\le \lvert c\rvert\sqrt2\end{align}


*if $c<0$,  \begin{align}\maximize&\quad  \frac{t}{\lvert c\rvert\sqrt2}\erfc (-t)&(D_c)\\\subj&\quad0\le t\le \lvert c\rvert\sqrt2\end{align}
Now, $(D_c)$ is easy to evaluate because $t\erfc(-t)$ is increasing on $[0,\infty)$ and therefore the maximum is for $t=\lvert c\rvert\sqrt2$. Hence the solution is $\erfc(-\lvert c\rvert\sqrt2)=\erfc(c\sqrt2)$.
$(B_c)$ is essentially an evaluation of what and where the maximum of $t\erfc( t)$ on $[0,\infty)$ is, and whether or not it is in the interval $[0,\lvert c\rvert\sqrt2]$. It turns out that the maximum of $t\erfc( t)$ is at $t=\alpha\approx 0.531597$ and that the value is $L=\alpha\erfc(\alpha)\approx 0.240376$: however, given the fact that $t\erfc( t)$ is $0$ in $t=0$, it increases for a while and then it decreases to $0$, approximating $\alpha$ and $L$ should not be a challenge. The bottom line is that the solution to $(B_c)$ ends up being $\erfc(c\sqrt 2)$ if $0<c\le\frac\alpha{\sqrt2}$, and $\frac{L}{c\sqrt2}$ if $c>\frac\alpha{\sqrt2}$.
Putting it all together the "exact" solution to $(A_c)$ is:

*

*$\erfc\left(c\sqrt 2\right)$ if $c\le\frac\alpha{\sqrt2}$; this maximum is attained at $x=\sqrt2$.


*$\frac{L}{c\sqrt2}$ if $c>\frac\alpha{\sqrt2}$; this maximum is attained at $x=\sqrt{\frac{\sqrt2\alpha}{c}}$.
Where $\alpha=\operatorname{argmax}_{x\ge0} x\erfc (x)$ and $L=\max_{x\ge 0}x\erfc (x)$.
