I'm trying to write a function in Workbench which will generate a Fibonacci sequence starting with F0 = 0 and F1 = 1. So far I have this written
fibonacciSequence[n_] :=
Module[{fPrev = 0, fNext = 1, i = 0},
While[i++ < n, {fPrev, fNext} = {fNext, fPrev + fNext}];
fNext]
How do I modify the function to make it print out a list like the one below when fibonacciSequence[15] is called?
{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610}
Sorry, but I am very new to Mathematica and my professor didn't give us much instructions or examples of similar functions.
Comments
Post a Comment