Continuous function to approximate square root

I have the following function

$f(x) = \begin{cases} \sqrt{x} &\quad\forall \ x >= 0 \\ -\sqrt{-x} &\quad\forall \ x < 0 \end{cases}$

You can find a plot of the function here.

I'm using this function within an optimization problem. Since the "if" clause on the value of $x$ is necessary to determine which of the two functions needs to be applied, the problem becomes a binary optimization problem, which is computationally a lot more tedious to solve than a problem with continuous variables.

Therefore, I'd like to approximate the function with a continuous function. So far, I've played around with polynomial fits and Taylor functions, but nothing really approximated my function well, especially in the area around $x=0$.

Would anyone have a suggestion for me on how to tackle this problem? How can I find a continuous function, which is applicable for both positive and negative $x$, to approximate my function? Any suggestions would be appreciated!

Thanks.

• $f$ is a continuous function. – Lord Shark the Unknown Nov 8 '17 at 16:55
• Note that the function's derivative goes to infinity as $x$ approaches zero. – hardmath Nov 8 '17 at 17:02
• Ok, please let me rephrase that then: I'd like to approximate the aforementioned function without having any "cases", just one representation that applies for all x from minus infinity to plus infinity. Any suggestions? – P_E1 Nov 8 '17 at 17:11
• Perhaps $(x/|x|)\sqrt{|x|},$ with some care when evaluating exactly at $0$? – RideTheWavelet Nov 8 '17 at 17:48
• $sign(x) \sqrt{|x|}$ or $\frac{x}{\sqrt{|x|}}$ – MotiN Nov 8 '17 at 17:56