How to represent sign function in range $[-1, 1]$

590 Views Asked by At

I have a function that is defined as follows:

$$f(x) = \begin{cases} 1 & \text{if $x \ge0$}, \\ -1 & \text{if $x<0$}. \end{cases}$$ I would like to represent the above function by the sign function. Could you help me represent it $$f(x)=\operatorname{sign}(x)...???$$

4

There are 4 best solutions below

3
On BEST ANSWER

You can try $$ f(x)=\mathrm{sgn}\!\left(\mathrm{sgn}(x)+\frac12\right) $$

16
On

Consider $$ f(x)=\operatorname{sign}(x)+g(x), $$ where $$ g(x)= \begin{cases} 1 & \text{if $x=0$},\\ 0 & \text{otherwise}. \end{cases} $$ Two common notations for such a $g$ are $\chi_{\{ 0 \}}$ or $1_{\{ 0 \}}$. The brackets, which might seem a bit superfluous, are there because the notation is read as "the indicator function of the set $\{ 0 \}$". (Sometimes we say "characteristic function" instead, though this term is taken by something else in certain other contexts.)

2
On

How about $$f(x) = \lim_{y \rightarrow x^+} \text{sign}(y)$$

0
On

First note that there are several possible definitions of the sign function (and some of them accept $\text{sign}(0)=1$). Actually to be consistent, one can take the $\text{sign}$ function to be the subgradient of $x\mapsto |x|$ and so you have the choice to define $\text{sign}(0)=\alpha$ for any $\alpha \in [-1,1]$ (the subgradient of $|x|$ at $0$ is $[-1,1]$).

Anyway for a matlab use, you can set

f = @(x) sign(x) + (x==0)

this matlab function satisfies your desired properties.