       Re: Plotting discontinuous functions

• To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Plotting discontinuous functions
• From: twj
• Date: Thu, 31 Dec 92 10:15:52 CST

```>I wonder whether there is a reasonably general way to plot functions

>y=f(x) which are discontinuous, for example, defined separately for

>different intervals of x, in such a way that no 'vertical' line is

>drawn at the points of discontinuity.

This is one possible way.

Plot is analogous to the function NIntegrate for which it is possible
to specify the points at which discontinuities occur by means of the

syntax:

NIntegrate[ f[x], {x, x0, x1, x2, x3, ... xk}]

Carrying this syntax over to Plot would be

Plot[ f[x], {x, x0, x1, x2, x3, ...xk}]

It is quite easy to make some code for Plot to break up its plot into
a number of sub-plots like so:

Unprotect[ Plot]

Plot[ f_, {x_, lims__ /; Length[ {lims}] > 2}, opts___] :=
Block[{new,fact = 10^-15,d},
new = Partition[{lims}, 2,1] ;
new = Map[ (d = (#[] - #[])*fact;

# + {d, -d})&, new] ;
new = Map[ Plot[ f, Evaluate[Prepend[ #,x]],

DisplayFunction -> Identity, opts]&, new] ;
Show[ new, DisplayFunction -> \$DisplayFunction]
]

and this can be used with something like:

Plot[ Tan[x], {x, 0, Pi/2, Pi, 3Pi/2, 2Pi}]

Tom Wickham-Jones
Wolfram Research

```

• Prev by Date: Plotting discontinuous functions
• Next by Date: What should Mma be?
• Previous by thread: Plotting discontinuous functions