Defining a Case Function in Mathematica: A Convenient Solution?

  • Context: Mathematica 
  • Thread starter Thread starter omri3012
  • Start date Start date
  • Tags Tags
    Function Mathematica
Click For Summary
SUMMARY

The discussion centers on defining a case function in Mathematica using the 'Piecewise' function. User Omri inquires about a convenient method to express a piecewise function, specifically for the function y(x) that returns x for positive values and -x for negative values. Another user confirms that the correct implementation is y[x_]:=Piecewise[{{x,x>0},{-x,x<0}}], which effectively addresses the query. This solution is confirmed as helpful for users seeking to implement conditional expressions in Mathematica.

PREREQUISITES
  • Familiarity with Mathematica syntax
  • Understanding of piecewise functions
  • Basic knowledge of conditional expressions
  • Experience with function definitions in Mathematica
NEXT STEPS
  • Explore advanced features of the 'Piecewise' function in Mathematica
  • Learn about conditional statements in Mathematica
  • Investigate function plotting techniques for piecewise functions
  • Study error handling in Mathematica when defining functions
USEFUL FOR

Mathematica users, mathematicians, and educators looking to implement and understand piecewise functions in their computations.

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 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K