What software can I graph with $D(x) \cdot \sin(x)$?

Is there a software where I can graph $D(x) \cdot \sin(x)\ \vert \ D(x) \text{ Dirichlet's function}$?

The problem is that it's a known function, and I haven't seen in Wolfram|Alpha, Desmos and Geogebra that it's recognized, and I've also not seen there the option to define graph a function that's defined in cases.

• The Dirichlet function is not very drawable. Even if you can plot it, you will not get much information from that picture. Jun 30, 2017 at 11:51
• In all those software you can do it. I just did it in MatLab, which is the one I had at hand. Define the function D(x) to take a floating point number. Inside it convert the number into a fraction, return the reciprocal of the denominator (I did it for this version of the Dirichlet function because it is prettier). Then create a vector for the $x$ axis. For example the numbers between 0 and 1 picked at a fine enough step. Evaluate $D(x)*\sin(x)$ at the points in the vector to get your vector of $y$. Then plot $x$ against $y$. In Matlab [N,D]=rat(x) gives you the fraction, plot(x,y) the plot.
– OR.
Jun 30, 2017 at 12:07

In the same sense that the graph of Dirichlet's function looks like the lines $y = 0$ and $y = 1$, with holes at every rational location in the lower line and holes at every irrational location in the upper, the graph $$y = f(x) \chi_{\mathbf{Q}}(x)$$ looks like the graphs $y = 0$ and $y = f(x)$, with holes at every rational location in the line $y = 0$ and holes at every irrational location in the graph $y = f(x)$.
• I was able to imagine that it looks like that, but I was wanting to draw it with some software. Off topic: Is it possible in pgfplots/TikZ to draw this, defining the function by cases? And, what's that $\chi_{\mathbb{Q}}(x)$ there? Is Dirichlet's function a characteristic function of $\mathbb{Q}$ or something? Jun 30, 2017 at 11:53
• 1. The graphical point is, you may as well just make two plots, $y = 0$ and $y = f(x)$, and assert that each has "gaps", with the gaps of one graph vertically aligned with the points of the other. 2. I don't know about pgfplots. 3. If by "Dirichlet's function" you meant $D(x) = 1$ if $x$ is rational and $D(x) = 0$ otherwise, then by definition yes, $D$ is the characteristic function of the rationals. :) Jun 30, 2017 at 12:03