Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Piecewise functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23196] Re: [mg23119] Piecewise functions
  • From: Matt.Johnson at autolivasp.com
  • Date: Mon, 24 Apr 2000 01:12:05 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com


An-

You can define a piecewise function by use of UnitStep[x]...

Suppose I have 3 functions:

x^2 for x<=0
x for 0<=x<=10
-x+20 for x>=10

Then they can be defined with UnitStep[]:

fun1[x_] := x^2*UnitStep[-x];
fun2[x_] := x*(UnitStep[x] - UnitStep[x - 10]);
fun3[x_] := (-x+20)*UnitStep[x - 10];

Then, we can combine these into one function and plot to check it:

fun[x_] := fun1[x] + fun2[x] + fun3[x];
Plot[fun[x], {x, \(-10\), 20}];

The UnitStep function also allows integration:

In[31]:=
Integrate[fun[x], x]

Out[31]=
x^3/3 + 20(-10 + x) UnitStep[-10 + x] -
    2(-50 + x^2/2) UnitStep[-10 + x] +
    1/2 x^2 UnitStep[x] - 1/3 x^3 UnitStep[x]

-matt





An Le <an_le at brown.edu> on 04/19/2000 12:30:49 AM

Subject: [mg23196]  [mg23119] Piecewise functions




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...








  • Prev by Date: Re: Help, my MathLink Examples segfault.
  • Next by Date: how to XY plot a list of complex numbers?
  • Previous by thread: RE: Piecewise functions
  • Next by thread: Re: Piecewise functions