I Simulating irrational numbers

roam

Summary
Is there a way to generate two random numbers such that their ratio simulates the behavior of an irrational number?
I am trying to write an algorithm that generates two random numbers in a given interval such that their ratio is an irrational number. I understand that all numbers stored on a computer are rational, so it is not possible to have a truly irrational number in a simulation. So, instead I am looking for an algorithm that generates two numbers whose ratio simply has a very long repeat period (it appears to be irrational during the simulation). How would such an algorithm look like (e.g., in Matlab)?

Any suggestions would be greatly appreciated.

P.S. I am simulating a physical situation where the ratio of the period of two waves is not rational (or rather, it has a very long repeat period), hence the resultant wave does not appear to be periodic.

pbuk

Any two (pseudo) random numbers to a reasonable level of precision would do - what happens when you try?

• roam

roam

Hi @pbuk

I modified my code, so that one of the numbers is always a large prime, so that the ratio of the two numbers will have a very long repeat period. However, as a double precision number, the number will still only have 16 significant digits.

Also, I believe the problem with my simulation might be something else. The two numbers that I am generating must be close in range, e.g., if they are both primes we might get:

$x_1 = 2051587$
$x_2 = 2051773$

Note that $x_1$ and $x_2$ represent periods of waves that I am trying to combine.

So, the ratio of the above numbers will be either 1.000090661522032 or 0.999909346696735. I think, that means that the two waves will be effectively in phase, and you will only see aperiodic behavior if you plot for an extremely large number of cycles. Is that right?

Any explanation would be appreciated.

FactChecker

Gold Member
2018 Award
I suggest starting with a random number for the ratio and back-calculating one of the initial numbers that you talked about. That allows you to control the ratio and know that it is what you want (very long repeating period, magnitude, etc.)

roam

Hi @FactChecker

Do you think that would still be helpful if the ratio is of the order 1.00009?

If we have a ratio like that, doesn't it mean that the combined signal will still look periodic in the short range? I think one has to simulate over a very large number of periods to see any aperiodicity.

FactChecker

Gold Member
2018 Award
I don't know what your application is, but generating a random number in the range 0.999998 to 1.00009 is not difficult. Either approach should have a very long repetition period.

pbuk

So, the ratio of the above numbers will be either 1.000090661522032 or 0.999909346696735. I think, that means that the two waves will be effectively in phase, and you will only see aperiodic behavior if you plot for an extremely large number of cycles. Is that right?

Any explanation would be appreciated.
I'm not sure what aperiodic behaviour looks like, but if you mean that the combination of two waves with similar frequencies is a waveform with a pattern that only changes very slowly then that is correct. What did you expect? I think you need to look at why you are doing what you are doing because you seem to be focussing on unimportant or even meaningless things and ignoring the big picture.

• roam

"Simulating irrational numbers"

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving