Twitter and the Fibonacci Sequence

1

This morning I read an interesting post about the design of the new Twitter Web page. The post included some R code to generate the ratio between adjacent terms in the Fibonacci seqence. The ratio converges to the "Golden Ratio": 1.61803399....

I'm sure that many R gurus will post simpler versions of the R code used in the post. In SAS, I would probably use the DATA step to generate the Fibonacci seqence and the ratio between adjacent terms, but since this is a blog about SAS/IML, here is some SAS/IML code:

proc iml;
n = 20;                        /* number of terms in the sequence */
fib = j(n,1);                  /* allocate; fill with 1's */
do i = 3 to n;
   fib[i] = sum(fib[i-1:i-2]); /* define sequence */
end;
/* compute ratio of adjacent terms */
idx = 1:n-1; 
ratio = fib[idx+1] / fib[idx] ; 
print ratio[format=8.6];
Share

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of PROC IML and SAS/IML Studio. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

Back to Top