Faster Lucas Number Function in Excel
In mathematics, the sequence of number 2,1,3,4,7,11,18,29,47,76.... is known as the Lucas numbers or sequence. Read More Here
I would like to show you how to write faster Fibonacci generating function in excel
Open your visual basic editor and enter the following code. Visit this post to learn how to enable developer options in Excel
Learn how to create your own Excel Functions HERE
Option Explicit
' This set a maximum number for the sequence.
' You can change it but use the right datatype
' learn Excel DataTypes HERE
Dim l(500) As Double
Function Lucas(n As Double) As Double
If n = 1 Then
Lucas = 2
ElseIf n = 2 Then
Lucas = 1
ElseIf l(n) > 0 Then
Lucas = l(n)
Else
l(n) = Lucas(n - 1) + Lucas(n - 2)
Lucas = l(n)
End If
End Function
No comments :
Post a Comment