« Google Summer of Code advances R | Main | Mandelbrot Set, evolved »

September 29, 2010


Feed 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.

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

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

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:

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

The comments to this entry are closed.

Search Revolutions Blog

Got comments or suggestions for the blog editor?
Email David Smith.
Follow revodavid on Twitter Follow David on Twitter: @revodavid
Get this blog via email with Blogtrottr