Re: Fibonacci
- To: mathgroup at smc.vnet.net
- Subject: [mg27645] Re: [mg27591] Fibonacci
- From: BobHanlon at aol.com
- Date: Fri, 9 Mar 2001 02:36:02 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
The Fibonacci numbers are built-in. Check your results with them.
soln1 = Fibonacci /@ Range[-12, 12]
{-144, 89, -55, 34, -21, 13, -8, 5, -3, 2, -1, 1, 0, 1, 1,
2, 3, 5, 8, 13, 21, 34, 55, 89, 144}
f1[n_Integer?Positive] := f1[n] = f1[n-1] + f1[n-2];
f1[1] = f1[2] = 1;
f1[n_Integer?NonPositive] := f1[n] = f1[n+2] - f1[n+1];
(f1 /@ Range[-12, 12]) == soln1
True
Needs["DiscreteMath`RSolve`"];
f2[n_] := Evaluate[
a[n] /. RSolve[{a[n] == a[n-1] + a[n-2], a[1] == a[2] == 1}, a[n],
n][[1]]]
f2[n]
(-((1/2)*(1 - Sqrt[5]))^n + ((1/2)*(1 + Sqrt[5]))^n)/Sqrt[5]
Simplify[f2 /@ Range[-12, 12]] == soln1
True
$RecursionLimit = 500;
Fibonacci[500] == f1[500] == Expand[f2[500]]
True
Fibonacci[-500] == f1[-500] == ExpandAll[Together[f2[-500]]]
True
$RecursionLimit = 256;
Bob Hanlon
In a message dated 2001/3/7 11:44:39 PM, cnelson9 at gte.net writes:
>I get the nth Fibonacci number in this Mathematica
>notebook, but it gives different answers than I expected
>when n is negative. Are they wrong?
>
>The square root of five has rational coordinates with B_5
>numbers, so the powers of Phi and phi and division by
>Sqrt[5] are all computed with exact rational arithmetic.
>
>The package RBFields.m is on MathSource linked to at:
>
>http://forum.swarthmore.edu/epigone/geometry-research/brydilyum
>
>Are any of the answers to fib[n] in this notebook wrong?
>