FIBONACCI
=FIBONACCI(n, [sequence_tf])
Argument | Description | Example |
---|---|---|
n | The number of values to return from the Fibonacci sequence | 10 |
sequence_tf | (default=TRUE) If FALSE, returns only the n-th value from the series (F0=0) | 10 |
In the template file, navigate to the Sequences worksheet to see the FIBONACCI function in action.
Description
The Fibonacci sequence is fun, cool, and fascinating. Beginning with 0, then 1, the next value in the sequence is the sum of the previous two values, so Fn = Fn-2 + Fn-1.
The function FIBONACCI returns the first N values of the Fibonacci Sequence, using recursion via the REDUCE function.
=FIBONACCI(15) Result: {0;1;1;2;3;5;8;13;21;34;55;89;144;233;377}
The Golden Ratio
One of the most fascinating aspects of the Fibonacci sequence is the Golden Ratio, φ=(1+SQRT(5))/2 ≈ 1.61803. As the sequence approaches infinity, the ratio Fn/Fn-1 converges to the Golden Ratio. This special ratio is found in many different places in nature and tends to represent beauty, growth or perfection. Classic examples are the spiral of the nautilus shell and various human proportions. You might say that the Golden Ratio is actually closer to the answer to "Life, the Universe, and Everything" than the number 42.
Binet's Formula
To return just a single value from the set of Fibonacci numbers, the function uses Binet's Formula described in the example below. If you set the sequence parameter to FALSE, FIBONACCI(n,FALSE) will return just the n-th Fibonacci number from the series, Fn (starting at F0=0).
Lambda Formula
This code for using FIBONACCI in Excel is provided under the License as part of the LAMBDA Library, but to use just this function, you may copy the following code directly into your spreadsheet.
Code for AFE Workbook Module (Excel Labs Add-in)
/** * Returns the first N values in the Fibonacci Sequence */ FIBONACCI = LAMBDA(n,[sequence_tf], IF(OR(ROWS(n)>1,COLUMNS(n)>1,n<1,n<>INT(n)),"Error: n should be an integer > 0", LET(doc,"https://www.vertex42.com/lambda/fibonacci.html", sequence_tf,IF(ISBLANK(sequence_tf),TRUE,sequence_tf), IF(sequence_tf=TRUE, IF(n=1,0,IF(n=2,{0;1}, REDUCE({0;1},SEQUENCE(n-2,1,3,1),LAMBDA(acc,i, VSTACK(acc,INDEX(acc,i-2)+INDEX(acc,i-1)) )) )), LET( phi, (1+SQRT(5))/2, psi, (1-SQRT(5))/2, (phi^n-psi^n)/(phi-psi) ) ) )));
Named Function for Google Sheets
Name: FIBONACCI Description: Return the first N values in the Fibonacci Sequence Arguments: n, sequence_tf Function: [same as the Excel version]
FIBONACCI Examples
Test: Copy and Paste this LET function into a cell =LET( phi, (1 + SQRT(5)) / 2, psi, (1 - SQRT(5)) / 2, n, 42, (phi^n - psi^n) / (phi - psi) ) =BINET(42) Result: 267914296
Test: Copy and Paste this LET function into a cell =LET( fib, DROP(FIBONACCI(15),2), DROP(fib,1)/DROP(fib,-1) ) Result: 2 1.5 1.6666667 1.6 1.625 1.6153846 1.6190476 1.6176471 1.6181818 1.6179775 1.6180556 1.6180257The answer is that by n=10, we already have φ rounding to 1.618. The limit of the precision in Excel to display φ is 1.61803398874989. To achieve this level of accuracy, we only need the 24th and 25th values in the Fibonacci sequence:
=BINET(25)/BINET(24) =75025/46368 Result: 1.61803398874989