## 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
 List (14 items) When $N=2$, $\phi \approx 1$ When $N=3$, $\phi \approx 2$ When $N=4$, $\phi \approx 1.5$ When $N=5$, $\phi \approx 1.66666666666667$ When $N=6$, $\phi \approx 1.6$ When $N=7$, $\phi \approx 1.625$ When $N=8$, $\phi \approx 1.61538461538462$ When $N=9$, $\phi \approx 1.61904761904762$ When $N=10$, $\phi \approx 1.61764705882353$ When $N=11$, $\phi \approx 1.61818181818182$ When $N=12$, $\phi \approx 1.61797752808989$ When $N=13$, $\phi \approx 1.61805555555556$ When $N=14$, $\phi \approx 1.61802575107296$ When $N=15$, $\phi \approx 1.61803713527851$