SChan
Aug 8,2015
The Fibonacci Sequence is the series of numbers:
1, 1, 2, 3, 5, 8, 13, 21, 34, …
The next number is found by adding up the two numbers before it.
The 2 is found by adding the two numbers before it (1+1). Similarly, the 3 is found by adding the two numbers before it (1+2).
We can use the Fibonacci numbers to create a spiral on a Cartesian plane. First, we can use sapply function over a sequence of numbers starting from 1 to create a Fibonacci series.Then we choose the numbers with odd indices to be the x-coordinates and those with even indices to be the y-coordinates.
library(UsingR)
library(numbers)
n<-20
s <- seq(1:n)
fib <- as.integer(sapply(s, fibonacci))
x1<- ifelse(seq(1:n)%%2 ==1, fib, 0)
y1<- ifelse(seq(1:n)%%2 ==0, fib, 0)
Next, for both series, we alternate the signs, take the log of the absolute value of the non-zero coordinates while keeping their original signs. We then connect the points.
x2 <-ifelse(seq(1:n)%%4==1, x1,-x1)
y2 <-ifelse(seq(1:n)%%4==2, y1,-y1)
x <- ifelse(x2 >0, log(x2), ifelse(x2<0, -log(-x2),0))
y <- ifelse(y2 >0, log(y2), ifelse(y2<0, -log(-y2),0))
plot(x,y)
lines(x,y, col="red")