A few comments related to the π Project

Recall that we can make lists with the Table function:

Table[ CatalanNumber[n], {n,1,10}]

Range gives a list of integers:

Range[10]

Range[4,10]

The Map function lets evaluate your own function on a list:

Map[CatalanNumber,{2,4,7}]

Map[CatalanNumber,Range[10]]

The Map function also has a shorthand notation:

CatalanNumber /@ {2,4,9}

ListPlot[ CatalanNumber/@Range[10]]

ListPlot[ {{1,2,3,4},{5,4,5,6}}]

Fibonacci Numbers

Use a recursive formula:

f[0]=0
f[1]=1
f[n_]:=f[n-1]+f[n-2]

Try it out:

f[6]

f/@Range[15]

f[50]

Check the runtime:

Timing[f[20]]

Timing[f[25]]

Make a function to extract the runtime from the pair returned by Timing:

fruntime[n_]:=Timing[f[n]][[1]]

fruntime[25]

Make a plot of Fibonacci runtimes:

ListPlot[ fruntime /@ Range[28]]

Fibonacci iterative approach

The following module will return the nth Fibonacci number:

computeFib[n_]:=Module[{acc0=0,acc1=1,next},
Do[
next=acc0+acc1;  (* compute the next value *)
acc0=acc1;               (* shift down *)
acc1=next,
{k,1,n}
];
acc0         (* return value *)
]

Try it out:

computeFib /@ Range[10]

computeFib[0]

computeFib[2]

Timing[computeFib[1000]]

Much faster than before!

Ratios of consecutive Fibonacci numbers

First, make a big list of Fibonacci numbers:

fibs=computeFib/@Range[100]

Select the first 99 numbers in the list:

fibA=fibs[[1;;99]];

Select the last 99 numbers in the list:

fibB=fibs[[2;;100]];

Compute 99 ratios :

ratios=fibB/fibA;
N[ratios]

N[ratios[[99]],50]