RE: piecewise definition of a function
- To: mathgroup at smc.vnet.net
- Subject: [mg43896] RE: [mg43870] piecewise definition of a function
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 10 Oct 2003 03:06:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Nathan,
You want to use the UnitStep function. Unfortunately, UnitStep was only
added to the main part of Mathematica in Version 4. Because of that, it is
not reflected in the earlier parts of the book, although it is now discussed
in Part III. UnitStep is the best and preferred method for writing piecewise
function as the calculus routines handle it properly.
f[x_] := UnitStep[x] - UnitStep[x - 1]
fintg[x_] = Integrate[f[x], x]
(1 - x) UnitStep[-1 + x] + x UnitStep[x]
Needs["Graphics`Colors`"]
Plot[{f[x], fintg[x]}, {x, -1, 2},
PlotStyle -> {Red, Blue},
Frame -> True];
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Nathan Moore [mailto:nmoore at physics.umn.edu]
To: mathgroup at smc.vnet.net
I'd like to define a function in a piecewise manner. As of yet I've
been unsuccessful with even the simplest example. Consider the
following:
first define a 1-d bump,
f[x_] = If[x < 0, 0,If[x > 1, 0, 1]]
Mathematica doesn't seem to mind this, as f[0.1] evaluates 1 and
f[-23] evaluates 0.
The problem comes when I try to integrate the function. The
following command which should evaluate to 1 doesn't work AT ALL!
Integrate[f[x], {x, -50, 50}]
What is the proper technique here?
Nathan Moore
University of Minnesota Physics