≡ ▼
Work in Progress :: Please contact us to report errors, typos, etc.
=L_FIBONACCI(n, [sequence_tf])
ArgumentDescriptionExample
nThe number of values to return from the Fibonacci sequence10
sequence_tf(default=TRUE) If FALSE, returns only the n-th value from the series (F0=0)10

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 L_FIBONACCI returns the first N values of the Fibonacci Sequence, using recursion via the REDUCE function.

=L_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, L_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 L_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
*/
L_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: L_FIBONACCI
Description: Return the first N values in the Fibonacci Sequence
Arguments: n, sequence_tf
Function:
[same as the Excel version]

L_FIBONACCI Examples

Example 1: Binet's Formula
Binet's Formula is a method for calculating the nth value in the Fibonacci series. See the Wikipedia article in the references section below for more info.
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)
)
=L_BINET(42)

Result: 267914296
Example 2: How Close to Infinity?
How close to infinity do you need to get to approximate the Golden Ratio to 1.618? Let's divide the sequence by the previous value (dropping the first two values first) and see how quickly the ratio converges to 1.618.
Test: Copy and Paste this LET function into a cell
=LET(
    fib, DROP(L_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.6180257
The 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:
=L_BINET(25)/L_BINET(24)
=75025/46368

Result: 1.61803398874989
References & Resources
Disclaimer: This article is meant for educational purposes only. See the License regarding the LAMBDA code, and the site Terms of Use for the documentation.