Re: Plotting Piecewise Functions with Discontinuites
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1949] Re: Plotting Piecewise Functions with Discontinuites
- From: wiener at finance.wharton.upenn.edu (Zvi Wiener)
- Date: Sat, 26 Aug 1995 00:09:25 -0400
- Organization: University of Pennsylvania
Paul J. Simonich (simonichpj%dfms%usafa at dfmail.usafa.af.mil) wrote:
: I'm trying to plot a piecewise function with a discontinuity at x=3:
: f[x_]:=Which[x<=-3,3,
: x>=-3 && x<=3, Abs[x],
: x>3,-3]
: Plot[f[x],{x,-7,7},AxesLabel->{x,y},PlotRange->All];
: Mathematica draws a veritcal line connecting the points of discontinuity.
: Is there a "simple way" to get Mathematica to not evaluate the function
: exactly at the point of discontinuity besides using Show[ ] with two
: separate plots?
: Thanks in Advance.
: Capt Paul Simonich
: Dept of Mathematical Sciences
: US Air Force Academy
(* Subject: Re: plotting graphs with asymptotes
Tom Wickham-Jones at Wolfram, solved this problem elegantly a few months ago
in response to a similar query. I made a nice NeXT notebook---mail me
if you can take NeXTMail. But here is Tom's code:
*)
Unprotect[Plot];
Plot[ f_, {x_, lims__ /; Length[ {lims}] > 2}, opts___] :=
Module[ (* Tom Wickham-Jones, WRI *)
{temp, eps = 10^-15, d},
temp =
Partition[{lims}, 2, 1]; (* make pairs offset by 1 *)
temp =
( d = (#[[2]] - #[[1]])*eps; (* get a delta *)
# + {d, -d} (* shrink both ends by delta *)
)& (* map over pairs to get shrunken pairs *)
/@ temp;
temp =
Plot[f, Evaluate[Prepend[#,x]], (* iter triplets *)
DisplayFunction -> Identity, opts
]& /@ temp;
Show[temp, DisplayFunction -> $DisplayFunction] ]
Protect[Plot];
(*
I call this "elegant" because you use this extended Plot in an already
existing Mma syntax (that of NIntegrate) by specifying extra internal
points at singularities:
Plot[Tan[x], {x, 0, Pi/2, 3Pi/2, 2Pi}]
*)
Zvi Wiener
Lehman Brothers, Inc.
zwiene at lehman.com