4
$\begingroup$

I guess this has already be answered.

Plot[1/(x^3 - 2 x^2), {x, -2, 4}, Exclusions -> True]

Plot[1/(x^3 - 2 x^2), {x, -2, 4}, Exclusions -> 2]

I cannot understand why I have to specify the position of discontinuity (2nd plot) in order to get rid of the vertical line at x=2 (which exists in the first plot). Exclusions->True is not for detect the position of discontinuities? The function is rather simple.

$\endgroup$
9
  • $\begingroup$ Does plotting $\frac1{x-2}$ have the same problem? $\endgroup$ May 18, 2015 at 14:34
  • $\begingroup$ So, this is is considered a "normal" behavior? $\endgroup$
    – Dimitris
    May 18, 2015 at 14:42
  • 2
    $\begingroup$ @Guesswhoitis., yes same problem with 1/(x-2). - dimitris, Here is the advice on how to do it from the docs (Plot > "Options" > "Exclusions"): Plot[1/(x^3 - x + 1), {x, -2, 2}, Exclusions -> {x^3 - x + 1 == 0}] $\endgroup$
    – Michael E2
    May 18, 2015 at 14:50
  • 1
    $\begingroup$ @dimitris I think it doesn't try. I also think x == 0 is not excluded per se -- the plot just goes beyond the PlotRange and re-enters on the same side. It would be nice if Exclusions -> All would call NSolve or do something extra. It does not seem to. $\endgroup$
    – Michael E2
    May 18, 2015 at 15:17
  • 1
    $\begingroup$ I think for Exclusions, the settings All and True are synonymous with Automatic. In the trace, foo = Trace[Plot[1/(x^3 - 2 x^2), {x, -2, 4}, Exclusions -> True], TraceInternal -> True];, this happens: If[Graphics`PerformanceTuningDump`exclusions === All || Graphics`PerformanceTuningDump`exclusions === True, Graphics`PerformanceTuningDump`exclusions = Automatic]. $\endgroup$
    – Michael E2
    May 18, 2015 at 15:40

1 Answer 1

9
$\begingroup$

Plot seems to only do exclusions automatically for certain functions, such as Piecewise and some functions with branch cuts. For algebraic functions it seems to require an equation be passed to the Exclusions options.

I suspect that Plot determines exclusions in the same way as mesh points, by tracking when a zero is crossed. It seems simple enough to make an equation that defines which points are to be excluded:

Plot[f, {x, a, b}, Exclusions -> {1/f == 0}]

If you like, you can put this in a wrapper:

ClearAll[addExcl];
SetAttributes[addExcl, HoldAll];
addExcl[Plot[f_, {x_, a_, b_}, opts___?OptionQ]] :=
  Plot[f, {x, a, b}, Exclusions -> Flatten@{Thread[1/f == 0]}, opts]

Examples:

addExcl@Plot[Tan[x]/(x^3 - 2 x^2), {x, -2, 4}]

Mathematica graphics

addExcl@Plot[{Tan[x]/(x^3 - 2 x^2), 1/(1 - Log[x])}, {x, -2, 4}]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ @dimitris You're welcome. :) $\endgroup$
    – Michael E2
    May 18, 2015 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.