The Golden Ratio and Fibonacci Numbers
Two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities.
Given \(a\) and \(b\) with \(a > b > 0\) we have
$${a + b \over a} = {a \over b} = \phi$$
We can solve for \(\phi\) to yield
$$\phi = {1 + \sqrt{5} \over 2}$$
It can be shown that the ratios of successive Fibonacci numbers converge to \(\phi\). Let’s quickly explore this statement with a simple C# program.
void Main()
{
// Start by calculating the approximate value of the golden ratio
var goldenRatio = (1 + Math.Sqrt(5)) / 2;
goldenRatio.Dump("The Golden Ratio");
// Get the first 15 Fibonacci numbers
var fibonacciSequence = GetFibonacciSequence(15);
// Compute successive ratios of Fibonacci numbers
var fibonacciRatios = fibonacciSequence
.Skip(1)
.Select((element, index) => new FibonacciRatio(index + 2, (double)element / fibonacciSequence.ElementAt(index)))
.ToList();
fibonacciRatios.Dump("Ratios of successive Fibonacci numbers");
}
GetFibonacciSequence
A simple method to compute the sequence of the first \(N\) Fibonacci numbers.
int[] GetFibonacciSequence(int numberOfElements)
{
var fibonacciSequence = Enumerable.Repeat(1, numberOfElements).ToArray();
for (var index = 2; index < numberOfElements; ++index)
{
fibonacciSequence[index] = fibonacciSequence[index - 1] + fibonacciSequence[index - 2];
}
return fibonacciSequence;
}
FibonacciRatio
The following class represents the ratio of the \(N\) and \(N-1\) Fibonacci numbers. Note that we can provide a custom ToDump
implementation for our class which results in LINQPad using that method to render the object.
class FibonacciRatio
{
public int SequenceIndex { get; private set; }
public double Ratio { get; private set; }
public FibonacciRatio(int sequenceIndex, double ratio)
{
SequenceIndex = sequenceIndex;
Ratio = ratio;
}
object ToDump() => $@"When \(N={SequenceIndex}\), \(\phi \approx {Ratio}\)";
}
The Golden Ratio |
---|
1.61803398874989 |
Ratios of successive Fibonacci numbers | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|