Equazioni alle differenze finite (Difference equations / Recurrence relations)

<<discrete/rsolve.m

Numeri naturali

r=RSolve[{a[n]==a[n-1]+1,a[0]==0},a[n],n]

f[n_]:=Evaluate[a[n] /. r [[1]]]

f[10]

Successione di Fibonacci

rfib=RSolve[{fib[n]==fib[n-1]+fib[n-2],
             fib[0]==1,fib[1]==1},fib[n],n]

fibonacci=Simplify[fib[n] /. rfib[[1]] ];

fibonacci

Fibon[n_]:=Evaluate[fibonacci //N]

Fibon[20]