10

Let's say we have a function $f(x)=\dfrac{2^x-2}{x-1}$. The graph of the function in Mathematica looks like this:

plot of the function

The function in question is obviously not continuous at $x=1$, but that doesn't show in the plot.

Is there an option to make Mathematica draw a hole at those points where a function is discontinuous, and if so, can I make this the default option?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Cristopher
  • 387
  • 2
  • 11
  • 4
    If you define it to be equal to its limit, it is in fact continuous in 1. The left and right limits exist and are equal. – Szabolcs Jul 12 '15 at 21:22
  • 1
    You could tell MMA manually where it is also

    Plot[f[x], {x, -10, 10}, Exclusions -> {x == 1}, ExclusionsStyle -> {Disk[], PointSize -> 0.015}]

    – Julian Jul 12 '15 at 21:23
  • 1
    FunctionDomain can be useful to try to detect points like these. Generally, I don't think there's a good automatic and reliable way to detect such points though. – Szabolcs Jul 12 '15 at 21:26
  • @Julian Thanks. That works, I guess. Any possibility there is an automatic way to do this? – Cristopher Jul 12 '15 at 21:28
  • @Szabolcs Only if you define it that way. But f(1) is not defined and so it's not part of the domain. So technically the function is not continuous at x=1. – Cristopher Jul 12 '15 at 21:30
  • 3
    @Cristopher "But f(1) is not defined" <-- it is not a good idea to treat Mathematica as a mathematician. Computer algebra systems will readily simplify things such as ((x - 1) (x - 2))/(x - 1) and won't care about the fact that technically that function should be undefined at x==1. Trying to handle these details would make them much too impractical and probably slow. The conclusion is: it is up to you do decide whether you consider that function defined at x==1 or not, in the strict mathematical sense, and keep this in mind during symbolic manipulations. Mathematica will ignore ... – Szabolcs Jul 12 '15 at 22:02
  • ... that single point when it gets the chance to for the sake of practicality and simplicity. But for this specific (and similar) cases, did you look at FunctionDomain that I suggested? – Szabolcs Jul 12 '15 at 22:03
  • You could also use Solve[Denominator[f[x]] == 0, x] – Bob Hanlon Jul 12 '15 at 22:05
  • Closely related: http://mathematica.stackexchange.com/q/65624/12 – Szabolcs Jul 12 '15 at 22:05
  • @Szabolcs Yes I was aware of the existence of FunctionDomain . I was just wondering if there was an automatic way to do it but I've read your answer to the question in the link and it seems it's not possible. I now know there are practical reasons for that. Thank you for your comments and for the link. – Cristopher Jul 12 '15 at 22:16
  • @MichaelE2 Can your function be used to automatically mark the singularity that the OP describes? – Mr.Wizard Jul 13 '15 at 02:26
  • @Mr.Wizard It has some (perhaps typical symbolic-algebra) limitations, and you have to wrap the function in Piecewise, an oversight on my part. But it will handle the OP's example automatically (if wrapped in Piecewise): http://i.stack.imgur.com/BRhMD.png – Michael E2 Jul 13 '15 at 04:04
  • @MichaelE2 If you were to update your answer to handle this case natively without the manual addition of piecewise we might consider this question "already answered?" – Mr.Wizard Jul 13 '15 at 08:54
  • @Mr.Wizard OK, updated with this OP's example included. – Michael E2 Jul 13 '15 at 16:59
  • 1
    Related, possible duplicates: (6), (5770), (11361) – Michael E2 Jul 13 '15 at 17:11
  • @Mr.Wizard After some thought, I decide to vote to close as a duplicate of (39445). You may, if you feel it is appropriate and are able, add either of (6) or (5770), if you feel it's appropriate; (11361) seems not quite close enough. – Michael E2 Jul 14 '15 at 00:01
  • @MichaelE2 Looks like you forgot about the gold badge this time. No matter, it's a good close, and thanks for finding and linking the other posts. – Mr.Wizard Jul 14 '15 at 00:04
  • @Mr.Wizard No, I remembered, and that's why I left the message. I took your previous comment as an implicit agreement. But when I do use the gold badge, I like to leave a note in case someone wants to respond. I don't know -- can I reopen with one vote what I closed? – Michael E2 Jul 14 '15 at 00:09
  • @MichaelE2 Okay, I was confused because I missed "and are able" which I am not. I really wish there was a way to for moderators (and now gold badge holders) to mark more than one duplicate. Anyway yes, you had my agreement. I think you can reopen with one vote as well. – Mr.Wizard Jul 14 '15 at 00:38

1 Answers1

15

You can combine parts of @Julian comment and @Szabolcs comment in the original post to have it marked automatically.

f[x_] := (2^x - 2)/(x - 1)

Plot[f[x], {x, -10, 10}, 
 Exclusions -> {Reduce[! FunctionDomain[f[x], x]]}, 
 ExclusionsStyle -> {Disk[], PointSize -> 0.015`}]

enter image description here

The inequalities that are returned by FunctionDomain negated to get the region not in the function's domain. The Reduce is used to combine inequalities where needed. Exclusions prevents points in the region from being plotted and ExclusionsStyle marks the points.

Hope this helps.

Update

Try it with Manipulate.

Manipulate[
 Plot[h[x], {x, -10, 10}, 
  Exclusions -> {Quiet@Reduce[! FunctionDomain[h[x], x]]}, 
  ExclusionsStyle -> {Disk[], PointSize -> 0.015`}, 
  PlotRange -> {{-10, 10}, Automatic}],
 {{c, 1}, -9.5, 9.5},
 Initialization :> {h[x_] := (2^x - 2)/(x - c);},
 TrackedSymbols :> {c}]
Edmund
  • 42,267
  • 3
  • 51
  • 143
  • Nice! Thank you very much :) Thanks everyone who commented, too. – Cristopher Jul 13 '15 at 01:51
  • 2
    Just a comment on ExclusionsStyle -> {Disk[], PointSize -> 0.015}: Disk[] doesn't do anything here, this might as well be ExclusionsStyle -> {None, PointSize -> 0.015}. The first items sets the style of the inside of the exclusion and the second one sets the boundaries, check e.g. Plot[HeavisideTheta[x - 1], {x, 0, 2}, ExclusionsStyle -> {Green, Directive[Red, PointSize[0.02]]}]. Here the inside is infinitely small so it's not visible. – Szabolcs Jul 13 '15 at 06:10
  • Now tweak the style to draw a hollow circle in the same color as the graph, instead of a solid black dot, and you'll have a +1 from this Mathematica newbie. :) – Ilmari Karonen Jul 13 '15 at 08:47
  • @IlmariKaronen See the answer, http://mathematica.stackexchange.com/a/5779, by Jens for the solution you request. – Michael E2 Jul 13 '15 at 17:09