Description Usage Arguments Value Author(s) Examples
Takes in an integer (n) and returns a vector containing the first n terms of the fibonacci sequence
1 | fibonacci(n)
|
n |
Number of terms of sequence to be returned in the vector |
Returns a vector containing the first n terms of the sequence specified by the input
Matt Heffernan, University of Illinois at Chicago
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | fibonacci(8)
Returns a vector of length 8 containing the first 8 terms of the fibonacci sequence (ie. 0, 1, 1, 2, 3, 5, 8, 13)
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
fibonacci <- function(n){
a = 0
b = 1
count = 0
sequence <- c()
while(count < n)
{
sequence <- append(sequence, a)
temp <- a
a <- b
b <- temp + b
count <- count + 1
}
return(sequence)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.