Re: A plot of Sign[x]
- To: mathgroup at smc.vnet.net
- Subject: [mg94169] Re: A plot of Sign[x]
- From: Xerxes <saul.cohen at gmail.com>
- Date: Sat, 6 Dec 2008 06:15:50 -0500 (EST)
- References: <gh8hjr$r0h$1@smc.vnet.net>
On Dec 4, 7:14 am, "Bert Aerts (rm X)" <bert.aer... at advalvas.beX>
wrote:
> I tried to plot the Sign function, making clear that Sign[0]=0 by typing
> Plot[Sign[x], {x, -5, 5}, Mesh -> 51, PlotRange -> All]
> Making Mesh an odd value shows x=0.
>
> But the point at x=0 is being plot as 0.5 in stead of zero.
>
> What am I doing wrong?
Nothing, apparently. One interesting thing to note here is that
the Mesh-generating process apparently does not ever call the
expression in the first argument of Plot. This can be checked
using the EvaluationMonitor option. Since the mesh-maker
doesn't know the value of the function at 0, it's not surprising
that it gets it wrong.
You could just put the point in by hand, but here's a more
general solution, a discontinuous-function plotter:
discplot[expr_, {var_, min_, vals___, max_},
opts : OptionsPattern[Plot]] :=
Block[{excl = Exclusions /. FilterRules[{opts}, Exclusions]},
Show[Plot[expr, {var, min, max},
Exclusions ->
If[excl === True, excl,
Join[Flatten[{excl}], var == # & /@ {vals}]],
Evaluate[Sequence @@ FilterRules[{opts}, Options[Plot]]]],
If[Length[{vals}] > 0,
ListPlot[Table[{var, expr}, {var, {vals}}],
Evaluate[Sequence @@ FilterRules[{opts}, Options[ListPlot]]]],
Sequence @@ {}]]]
Attributes[discplot] = Attributes[Plot];
Just specify the discontinuous points between your min
and max plot ranges:
discplot[Sign[x], {x, -1, 0, 1}, AxesOrigin -> {-1, -0.5}]
Hope that helps,
Saul Cohen