Re: How to plot discontinuous functions?

*To*: mathgroup at smc.vnet.net*Subject*: [mg90149] Re: How to plot discontinuous functions?*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Tue, 1 Jul 2008 06:56:22 -0400 (EDT)*References*: <g4a6tv$8uh$1@smc.vnet.net>

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}] Generally, it is not possible to detect discontinuities numerically. (Is the function 1/(1 + Exp[10000 x]) continuous at 0?) Still, Mathematica does a pretty good job of finding them by analysing the expression the function is made of. When it fails to detect a discontinuity, you can specify it manually: Plot[f[x], {x, 0, 2}, PlotRange -> {0, 3}, Exclusions -> {1}] (Look up Exclusions) > > 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 >