I looked at quite some different approaches to the Fibonacci function, and I start to wonder how the Fibonacci number develops with respect to its index. To look into this I want to make a 2D plot where the X-axis is the natural numbers and the Y-axis is the corresponding Fibonacci numbers.

To solve this problem I decided to use R. This is less of an obvious solution. Usually one would probably have gone for a spreadsheet, but already did that.

R is a good tool for doing numeric analysis and prototyping algorithms for machine learning. For that it provides good tools for visualizing data. This is what I am going to elaborate a bit on here.

# Day 8 - R

Usually I would have started implementing Fibonacci as a recursive function. This was also my first approach and it is certainly possible. It is, however, not the idiomatic way. R is an array oriented language and as such we work on arrays. Under this paradigm it is better to initialize an array, and then populate it with its elements.

The implementation takes offset in a function that takes n as input and returns a list of the n first Fibonacci numbers.

fibList <- function(n){  theList <- numeric(n)  theList <- 1  theList <- 1  for (i in 3:n) {    theList[i] <- theList[i-1] + theList[i-2]  }  return(theList);}# Calling the functionfibList(10)fibList(20)fibList(100)

It was run using the Rscript command