Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Re: Plotting Piecewise Functions with Discontinuites

  • To: mathgroup at
  • Subject: [mg1949] Re: Plotting Piecewise Functions with Discontinuites
  • From: wiener at (Zvi Wiener)
  • Date: Sat, 26 Aug 1995 00:09:25 -0400
  • Organization: University of Pennsylvania

Paul J. Simonich (simonichpj%dfms%usafa at 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:

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

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

  • Prev by Date: Re: question about nest
  • Next by Date: Re: question about nest
  • Previous by thread: Plotting Piecewise Functions with Discontinuites
  • Next by thread: Re: Plotting Piecewise Functions with Discontinuites