# Graphing a function with specified input domains

My goal is to plot the function $f(x)=x^2-2$ where $x$ is a positive rational. It seems Mathematica assumes one always wants to plot a function for real inputs (and correspondent restrictions on the reals), but I do not see any way to "force" Mathematica to only accept rational inputs, specifically positive rational inputs. My goal is to have a nice plot that, more or less, illustrates the irrationality of $\sqrt{2}$, and I thought this could be a nice way to do it. Is there a way to execute my plan? I imagine this is likely a duplicate, but I could not find anything suitable.

• Isn't it true that near any irrational number there is rational one as close as you want? How do you expect to see the difference on a plot? May 25 '15 at 8:23
• @chris Right. Maybe it would help if I elaborated on my idea slightly (and maybe it really isn't the best idea to begin with)--my goal was to have the function plotted as a bunch of "dots" or "bubbles," where the idea was, just as you pointed out, that you could keep on zooming in but you could basically keep adding bubble after bubble; nonetheless, there are actual gaps as is evident by the fact that there is no bubble that lies on the $x$-axis. I don't know if that made a great deal of sense, but maybe it will clarify what I am after. May 25 '15 at 8:30
• FWIW: in inexact arithmetic (which Plot[] happens to use), all numbers are rational numbers. May 25 '15 at 9:19

f[x_?NumericQ] := Rationalize[x, 0.1]^2 - 2

However I suspect you probably want something else. Have you looked at Convergents?
• Thanks for answering. The more I think about it, the more I am convinced that no Mathematica graph will really do. It seems the only satisfactory approach is to simply give an explanation similar as I have done in response to Chris's comment. If I can think of a better / clearer way to phrase my question, then I will edit it. May 25 '15 at 14:05