To plot a discontinuous function at rational numbers

106 Views Asked by At

Good day everyone !

I'm just curious on how to plot (preferable in matlab or mathematica) the following stepwise function.

$ f(x) := \begin{cases} \dfrac{1}{q}~~~:~x=\dfrac{p}{q} \in \mathbb{Q} ~~\text{(in reduced form)}\\ 0~~~:~x \not \in \mathbb{Q} \end{cases} $

to illustrate that it is continuous at every irrational in the interval $(0,1)$ but discontinuous at every rational in $(0,1)$. Thanks in advance.

2

There are 2 best solutions below

3
On

Plotting completely is not possible… How to represent an infinite number of discontinuity points?

Below is an approximate picture from my website.

enter image description here

0
On

Before giving an answer, I first define the term "plot". Given small $\epsilon >0$, the plot of a function $f : \mathcal{D} \to \mathbb{R}$ is the set $\mathcal{R}_f = \{ B_{\epsilon}\big((x,f(x))\big) \mid x \in \mathcal{D} \} \subset \mathbb{R}^2$ where $\mathcal{D} \subseteq \mathbb{R}$ is the domain of $f$. Using this definition, observe that the plot of the function $f(x) = 0$ if $x\in \mathbb{Q}$ and $f(x)=1$ if $x\in \mathbb{Q}^{c}$ will be two horizontal cylinders $\mathbb{R}\times (1-\epsilon,1+\epsilon)$ and $\mathbb{R}\times (-\epsilon,\epsilon)$. Therefore, as $\epsilon$ approaches zero, it represents the lines $y=1$ and $y=0$. Now try to plot your function using this idea.