I am trying to graph the following function:
f(x) = 0 if x is rational else 1 # so 1 if x is irrational
My plan is to use python and matplotlib. How do you generate random irrational numbers in Python?
This is called Dirichlet function, and it's example of function that nowhere continuous. It's a simple mathematical fact, between any pair of numbers, there is infinite number of rational and infinite irrational number.
Plotting this function in practice is equivalent to plotting f(x) = 0 and f(x) = 1, as you're plotting using discrete pixels.
There are two gotchas:
Either way, this kind of "problem" is not meant to be approached as strictly programming problem.
The answer is you can't.
What you can do is figure out some epsilon after which this number is considered irrational.
It will look the same.
consider this: square root of 2 is an irrational number.
wolframlpah gives you an approximation : 1.4142135623730950488016887242096980785696718753769480...
python only sees 1.4142135623730950488016887242096980785696718753769480 which means: 1+ 4142135623730950488016887242096980785696718753769480/ 10000000000000000000000000000000000000000000000000000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With