0
$\begingroup$

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.

$\endgroup$
3
  • 1
    $\begingroup$ 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? $\endgroup$
    – chris
    May 25 '15 at 8:23
  • $\begingroup$ @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. $\endgroup$ May 25 '15 at 8:30
  • 2
    $\begingroup$ FWIW: in inexact arithmetic (which Plot[] happens to use), all numbers are rational numbers. $\endgroup$ May 25 '15 at 9:19
2
$\begingroup$

I find your question enigmatic but perhaps this is something useful:

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

Plot[f[x], {x, -2, 2}]

enter image description here

However I suspect you probably want something else. Have you looked at Convergents?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ May 25 '15 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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