2

I have a vector $x$, which I wish to transform according the the following computer code

xstar = sign(x) * x^2

with $x^*$ preserving the positiveness or negativeness of $x$.

How would I write this in proper mathematics? Obviously $x^2$ is incorrect, and $$x^*=\begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases}$$ is very clunky. Surely there must be something...

2 Answers2

8

How about $x\cdot|x|$? That avoids the need for piecewise definition. And if $|x|$ is defined piecewise for you, then you can use $x\sqrt{x^2},$ instead.

Cameron Buie
  • 102,994
2

You could just write $\mathrm{sgn}(x)\cdot x^2$. There's nothing "improper" about it! You could even write $\mathrm{sgn}(x)\cdot |x|^2$, which has the advantage that you can read off the sign and the magnitude individually. This is probably the clearest representation of your design intent, which is important for readability.

(I'm assuming that $x$ is a real number. If $x$ is complex, then the above expressions aren't equivalent, so it depends on your desired behavior. If $x$ is a vector, then again, it depends on what you want to do.)

Chris Culter
  • 26,806