|
[Date Index]
[Thread Index]
[Author Index]
Re: Piecewise functions
- To: mathgroup at smc.vnet.net
- Subject: [mg8953] Re: [mg8876] Piecewise functions
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Mon, 6 Oct 1997 01:59:21 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Venkateswara Rao Ayyadevara <va2a+ at andrew.cmu.edu>
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.
Venkat,
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
"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
g[x_]:=-x/;x\[LessEqual]0
g[x_]:=x/;x\[GreaterEqual]0
Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/training.html
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
|