Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Piecewise functions

  • To: mathgroup at
  • Subject: [mg8953] Re: [mg8876] Piecewise functions
  • From: Allan Hayes <hay at>
  • Date: Mon, 6 Oct 1997 01:59:21 -0400
  • Sender: owner-wri-mathgroup at

Venkateswara Rao Ayyadevara <va2a+ at>
mg8876] Piecewise functions

> I would like to know how to represent piecewise linear functions in
> Mathematica.  I tried searching on-line help but could not find  
any > info regarding this.

In addition to the ways given by Stephen Luttrell in [mg8906] you  
might like to try the following.

f[x_] := Which[ x<=0,-x,True,x];

This can be extended:

"Which[test1, value1, test2, value2, ... ] evaluates each of the  
testi in  turn, returning the value of the valuei corresponding to  
the first one that yields True."

This and the Dirac function approach allow the function f to be  
differentiated by using f' or, for example, D[f[x],x]. This is not  
possible with case by case definition as


Allan Hayes
hay at
voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester,  UK

  • Prev by Date: Re: Subscripts??
  • Next by Date: Re: Sequence is funny !
  • Previous by thread: Re: Piecewise functions
  • Next by thread: Re: Absolute error calculation with math software