Case function in Mathematica

1. Dec 24, 2011

omri3012

Does anyone familiar with a convenient way in Mathematica to define a case function such as:

$y(x)=\left\{\begin{array}{c} x \\ -x\end{array}\begin{array}{c} x>0 \\ x<0\end{array} \right.$
?

Thankes,
Omri

2. Dec 24, 2011

phyzguy

You want to use 'Piecewise':

y[x_]:=Piecewise[{{x,x>0},{-x,x<0}}]

3. Dec 24, 2011

omri3012

Thankes,
It's very helpful :)