Simulation of irrational numbers
Show older comments
I am trying to generate two random numbers
and
such that their ratio
is an irrational number. I understand that all numbers stored on a computer are rational, so one cannot have a truly irrational number in a simulation/experiment. So, is there any way of simulating the situation where the ratio of the two numbers has a very long repeat period?
and
such that their ratio 3 Comments
Walter Roberson
on 31 May 2019
Irrational numbers are irrational in all numeric bases.
Floating point numbers are stored as the ratio of two integers. The ratio of two floating point numbers is again the ratio of two integers. No matter what the denominator is, you can select a base in which the value was an integer together with at most one digit after the point.
Therefore you cannot force a "very long repeat period" unless you define a representation base.
John D'Errico
on 31 May 2019
Edited: John D'Errico
on 31 May 2019
Anyway, I'm a bit confused.
"...generate two random numbers x1 and x2 such that their ratio x1/x2 is an irrational number."
By definition, the ratio of two numbers is never irrational, unless one of the numbers themselves was already irrational.
As the answers have said, you can generate any arbitrary sequence of digits of any length. That can be viewed as a decimal number, but what does that get you?
x = 0.45623626246273674527567786785685795686969679757080978965456345354854564
x =
0.456236262462737
So, MATLAB stores the number as a double, which can then be shown to be represented as:
sum(2 .^ [-2 -3 -4 -6 -9 -10 -13 -15 -16 -17 -18 -19 -22 -23 -26 -28 -31 -33 -38 -39 -41 -42 -44 -46 -47 -48 -49 -52])
ans =
0.456236262462737
As a sum of fractions (that is, negative powers of 2), it is clearly a rational number. Or, we can write that as the fraction:
2054705461620089/4503599627370496
ans =
0.456236262462737
2054705461620089/4503599627370496 == x
ans =
logical
1
That reproduces the double precision number, and does so exactly. But no matter what I do with a double precision number, it is not the original very long decimal number I typed in. At best, it would seem you could use a symbolic form.
But where are you going with this? You cannot easily recover the original numbers that formed the fractional approximation. And as a random string of digits, what use are they?
Sordin
on 31 May 2019
Accepted Answer
More Answers (1)
James Tursa
on 31 May 2019
0 votes
The random number generators that come with MATLAB have very long periods. You can simply use them to form your ratio and it will also have a very long period.
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
