Re: How to plot discontinuous functions?

*To*: mathgroup at smc.vnet.net*Subject*: [mg90158] Re: [mg90135] How to plot discontinuous functions?*From*: Murray Eisenberg <murray at math.umass.edu>*Date*: Tue, 1 Jul 2008 06:58:05 -0400 (EDT)*Organization*: Mathematics & Statistics, Univ. of Mass./Amherst*References*: <200806300853.EAA09174@smc.vnet.net>*Reply-to*: murray at math.umass.edu

Here are two ways for your example -- first, build the function using Boole (much as one does when working with Laplace transforms); second, use the Exclusions option: Plot[1+Boole[x>1],{x,0,3},PlotRange->{{0,2},{0,3}}] f[x_]:=Piecewise[{{{1,1},x<1}},{2,2}]; Plot[f[x][[1]],{x,0,2},PlotRange->{0,3},Exclusions->1] f[x_]:=If[x<1,1,2]; Plot[f[x],{x,0,2},PlotRange->{0,3},Exclusions->1] Aaron Fude wrote: > Hi, > > If a function is defined via If, then when plotted it does not > acknowledge the discontinuity. E.g. > > f[x_] := If[x < 1, 1, 2]; > Plot[f[x], {x, 0, 2}, PlotRange -> {0, 3}] > > Defined via Piecewise, it does, but in my experience, not always: > f[x_] := Piecewise[{{{1, 1}, x < 1}}, {2, 2}]; > Plot[f[x][[1]], {x, 0, 2}, PlotRange -> {0, 3}] > > How do I make the Plot function try to acknowledge the discontuity by > not connecting the left limit and the right limit? > > Thanks, > > Aaron > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305