MathGroup Archive 2000

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

Search the Archive

RE: Piecewise functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23150] RE: [mg23119] Piecewise functions
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 20 Apr 2000 03:21:15 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

An Le asked:
>
> Can someone send me some notebook and package files to do piecewise
> functions? I can't seem to be able to do it with mathematica.
>
> The only thing i get close to is using the Which[] function, but I can't
> integrate with that function.
>
> Thanks...
>

An Le,

If you wish to integrate and differentiate, the best approach is to use the
UnitStep function. This defines a piecewise trapezoidal function.

f[x_] = x(UnitStep[x] - UnitStep[x - 1]) + UnitStep[x - 1] -
      UnitStep[x - 2] + (3 - x)(UnitStep[x - 2] - UnitStep[x - 3]) //
Simplify

(-3 + x) UnitStep[-3 + x] - (-2 + x) UnitStep[-2 + x] + UnitStep[-1 + x] -
  x UnitStep[-1 + x] + x UnitStep[x]

It can be directly plotted.

Plot[f[x], {x, 0, 3}];

It can also be directly integrated.

g[x_] = Integrate[f[x], x] // Simplify

1/2*((-3 + x)^2*UnitStep[-3 + x] - (-2 + x)^2*UnitStep[-2 + x] -
   UnitStep[-1 + x] + 2*x*UnitStep[-1 + x] - x^2*UnitStep[-1 + x] +
   x^2*UnitStep[x])

And the integral can be directly plotted.

Plot[g[x], {x, 0, 3}];


David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



  • Prev by Date: Re: how to rank a list of elements?
  • Next by Date: Re: Clear or remove definitions including Subscripts
  • Previous by thread: Re: Piecewise functions
  • Next by thread: Re: Piecewise functions