2
$\begingroup$

I'm trying to come up with a way to solve this problem:

Assume x and y are rational numbers in the range (0, 1].
Given x, what is the nearest y to x such that yn=1 for some integer n?

Or put another way,

Round x to the nearest 1/n.

What I'm trying to do is find a good interval for a table I'm creating. I've computed the optimal interval, x, but I also want the table to land on every whole integer as well.

I'm trying to find the function that performs this transformation.

Examples:

f(x) = y f(0.3168705857) = 1/3 f(0.2141233120) = 1/5 f(0.9583990664) = 1 f(0.2426311964) = 1/4 f(0.8125500321) = 1 f(0.3569497599) = 1/3 f(0.0539263572) = 1/19

  • 0
    "What I'm trying to do is find a good interval for a table I'm creating." Could you elaborate on this?2017-01-13
  • 0
    Not sure how to describe it succinctly. But the above function will compute the column headers I'll use for the table. I them to always to contain 1, 2, 3, etc.. when it crosses over them but if the values are small I want the columns to be 1, 1.5, 2, etc or 1, 1.2, 1.4, 1.6, 1.8, 2, etc. If I don't compute this function I could end up with ex 1, 1.4, 1.8, 2.2, 2.6, etc (it skips "2" so I would want to round the 0.4 x to 0.5 instead)2017-01-13

1 Answers 1

2

$0 < x \le 1$ so

$1 \le \frac 1x$ so

$n \le \frac 1x \le n + 1$ for some integer $n \ge 1$. $n = \lfloor \frac 1x \rfloor$. $n + 1 = \lceil \frac 1x \rceil$. So

$\frac 1{\lceil 1/x \rceil} \le x \le \frac 1{\lfloor 1/x \rfloor}$.

Example: if $x = e^{-3} = 0.04978706836786394297934241565006$

Then $\frac 1x = 20.085536923187667740928529654582$ and

$\frac 1{21} < x < \frac 1{20}$

$\frac 1{20} - x =0.000212931632136057020657584349938$

and $x - \frac 1{21} = 0.00216802074881632393172336803101$

so closest is $\frac 1{20}$.