Finding index of closest Fibonacci Number to a given value

333 Views Asked by At

Here it is:

Find $n$, such that that $F(n)$ [Fibonacci function] is the closest possible Fibonacci number to $a$, or in other words, such that $\text{abs}(F(n)-a)$ is minimum.

I think there should be a way to implement an algorithm, but I'm rather looking for a mathematical proof. What I've tried so far is to take the generalized non-recursive form of the Fibonacci function, isolate the $n$ and then create a function $f(a, n)$ of the absolute value of $F(n) - a$, and then take the derivative with respect to $n$ and then set it to $0$, but i believe this is not quite the way to find maxima and minima of functions of several variables (I haven't gotten to that part of calculus yet). I'm looking for a clarification on the correct method of finding such value of $n$ for this function, or maybe even a completely different approach.

1

There are 1 best solutions below

0
On

It is known that $$ f_n=\frac{\varphi^n-\varepsilon^n}{\sqrt{5}}, $$ where $\varphi:=\frac{1}{2}(1+\sqrt{5})$ and $\varepsilon:=\frac{1}{2}(1-\sqrt{5})$. Note that $|\varepsilon|<1$, hence $$ f_n=\frac{\varphi^n}{\sqrt{5}}+o(1). $$ At this point, if you want to find the "closest" value to a positive real $a$, it is roughly sufficiently to minimize $$ \left|\frac{\varphi^n}{\sqrt{5}}-a\right|, $$ which is the closest integer to $$ \log_\varphi(\sqrt{5}a)=\frac{\frac{1}{2}\log 5 + \log a}{\log \varphi} \approx \frac{0.80472+\log a}{0.481212}. $$

Ps. Note the "closest" is not always well defined, indeed there are infinitely many consecutive odd Fibonacci numbers (so their average has the same distance from both of them). Lastly, the above approximation gives the correct answer with an error of at most $1$ (or $2$ for small values of $a$).