Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Case function in Mathematica

  1. Dec 24, 2011 #1
    Does anyone familiar with a convenient way in Mathematica to define a case function such as:

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

    Thankes,
    Omri
     
  2. jcsd
  3. Dec 24, 2011 #2

    phyzguy

    User Avatar
    Science Advisor

    You want to use 'Piecewise':

    y[x_]:=Piecewise[{{x,x>0},{-x,x<0}}]
     
  4. Dec 24, 2011 #3
    Thankes,
    It's very helpful :)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Case function in Mathematica
  1. Mathematica functions (Replies: 1)

Loading...