## September 29, 2010

You can follow this conversation by subscribing to the comment feed for this post.

Very cool.

Here's an easy 3-liner that I'm sure could simply be wrapped into a function.

fv<-c(0,1)
sapply(3:20, function(i) fv[i]<<-fv[i-1]+fv[i-2])
fv[-1]/fv[-length(fv)

Which, oh, that could be compressed into 2 lines (you have to initialize the vector)

fv<-c()
sapply(1:20, function(i) if(i<3){fv[i] <<- 1}else{fv[i]<<-fv[i-1]+fv[i-2]})[-1]/fv[-length(fv)]

Via John Myles White, here's an amazingly elegant way of deriving the Golden Mean from its continued fraction representation using R's Reduce function:

```
> cfrac <- function(x) Reduce(function(u, v) u + 1 / v, x, right = TRUE)
> cfrac(rep(1,10))
[1] 1.618182
```

cfrac(rep(1,n)) better approximates the Golden Ratio as n gets larger.

It turns out that you can understand why the ratio is the golden mean if you cast the sequence in terms of iteration of a certain matrix:
http://blogs.sas.com/iml/index.php?/archives/22-Matrices,-Eigenvalues,-Fibonacci,-and-the-Golden-Ratio.html

This is very exciting and I like your template as well. Keep it up.

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

## Information

R for the Enterprise

Got comments or suggestions for the blog editor?
Email David Smith.