I am using Piecewise with conditions based on whether x is a rational number or not. The function assignment seems to work. But when I plot it, an empty plot shows up (though the PlotLabel looks nice).
Clear[f];
f[x_] := Piecewise[{{x,
Element[x, Rationals]}, {-x, ! Element[x, Rationals]}}]; Plot[
f[x], {x, -5, 5},
PlotLabel -> "f(x)=" <> ToString[TraditionalForm[f[x]]]]
What's wrong? I tried using different options with PlotRange and Mesh, thinking that I Plot needed to sample some x values that fell into the rational category. No luck yet.
Here is another example with the same result: an empty plot but the function assignment works.
Clear[f];
f[x_] := Piecewise[{{1, Element[x, Integers]}, {0,
Element[x, Reals]}}]; Plot[f[x], {x, -3, 3},
PlotLabel -> "f(x)=" <> ToString[TraditionalForm[f[x]]]]
Any insight is much appreciated!