Mathematica Defining a Case Function in Mathematica: A Convenient Solution?

AI Thread Summary
A user inquired about defining a case function in Mathematica, specifically for a function y(x) that behaves differently based on the sign of x. The recommended solution is to use the 'Piecewise' function, structured as y[x_] := Piecewise[{{x, x > 0}, {-x, x < 0}}]. This approach effectively handles the conditional behavior of the function based on the value of x. The response was appreciated for its clarity and usefulness.
omri3012
Messages
60
Reaction score
0
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&gt;0 \\ x&lt;0\end{array}<br /> \right.
?

Thankes,
Omri
 
Physics news on Phys.org
You want to use 'Piecewise':

y[x_]:=Piecewise[{{x,x>0},{-x,x<0}}]
 
Thankes,
It's very helpful :)
 

Similar threads

Replies
3
Views
3K
Replies
1
Views
2K
Replies
1
Views
3K
Replies
13
Views
2K
Replies
7
Views
3K
Replies
5
Views
3K
Replies
4
Views
2K
Back
Top