<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ben Murrell &#187; maths</title>
	<atom:link href="http://www.benmurrell.com/tag/maths/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benmurrell.com</link>
	<description></description>
	<lastBuildDate>Thu, 01 Dec 2011 08:02:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Thoughts on Fibonacci Sequence Generation</title>
		<link>http://www.benmurrell.com/2009/03/thoughts-on-fibonacci-sequence-generation/</link>
		<comments>http://www.benmurrell.com/2009/03/thoughts-on-fibonacci-sequence-generation/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 06:46:20 +0000</pubDate>
		<dc:creator>benm</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[computers]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://www.benmurrell.com/?p=34</guid>
		<description><![CDATA[So, a common interview question I&#8217;ve been asked is to write a function that will return the nth number in the Fibonacci Sequence. I think the question is meant to test two things: first, have you retained enough math to know what the Fibonacci sequence is; and second, do you know how to write a [...]]]></description>
			<content:encoded><![CDATA[<p>So, a common interview question I&#8217;ve been asked is to write a function that will return the nth number in the Fibonacci Sequence. I think the question is meant to test two things: first, have you retained enough math to know what the Fibonacci sequence is; and second, do you know how to write a recursive function. Last week in my Combinatorics class (this is my Spring break, why am I writing this??), my professor introduced a closed form formula for calculating the nth number in the Fibonacci sequence. This is why I&#8217;m writing this now &#8211; when I saw the formula, I thought it&#8217;d be fun to memorize the formula, then whip it out in those interview questions. Not that I&#8217;ll ever get a chance now that I have a job lined up, but that&#8217;s another matter.</p>
<p>The formula goes like this:</p>
<p><a href="http://en.wikipedia.org/wiki/Fibonacci_number#Closed_form_expression"><img class="alignnone" title="Closed form Fibonacci" src="http://upload.wikimedia.org/math/9/6/8/968be88f42e32712cb10d89a765ce708.png" alt="" width="350" height="49" /></a> where<img src="file:///C:/DOCUME%7E1/BENMUR%7E1/LOCALS%7E1/Temp/moz-screenshot.jpg" alt="" /><img src="file:///C:/DOCUME%7E1/BENMUR%7E1/LOCALS%7E1/Temp/moz-screenshot-1.jpg" alt="" /> <img class="alignnone" title="golden ratio formula" src="http://upload.wikimedia.org/math/3/0/f/30ff36a6f91b36b0941d4ab16a627fee.png" alt="" width="270" height="44" /> (the golden ratio).</p>
<p>I haven&#8217;t spent much time reading over the Wikipedia page, and we didn&#8217;t spend any time in class on the derivation&#8230; but it&#8217;s interesting that given integer inputs, the function produces integer outputs even though the square root of 5 is used throughout.</p>
<p>I was thinking to myself, &#8220;What would make the most sense in a programming context?&#8221; The answer wasn&#8217;t (and still isn&#8217;t) immediately clear. In the future I intend to do an actual comparison of three different methods of generating the nth number in the Fibonacci sequence (Closed form, recursive, and non-recursive). At first glance, for very small n the recursive and non-recursive forms should beat the closed form. For large n, the closed form should dominate the other two methods with the non-recursive method being faster than the recursive method.</p>
<p>One downside I see to the closed form method is error propagation &#8211; even with integer inputs, I would still expect a need to round to the nearest integer due to the small roundoff error incurred by using floats/doubles for the golden ratio.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmurrell.com/2009/03/thoughts-on-fibonacci-sequence-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

