Board logo

Subject: 费氏级数(Fibonacci)的学习 [Print This Page]

Author: skyjacker    Time: 2007-5-31 16:34     Subject: 费氏级数(Fibonacci)的学习

费氏级数(Fibonacci)的学习

Written by SkyJacker  2007-05-31
Http://www.cnpack.org

(1)费氏级数数值序列:0,1,1,2,3,5,8,13...
(2)表示式归纳:Fn = Fn-1 + Fn-2
(3)存储空间:用无符号 4 字节整数来表示,共有 48 个数据
(4)意义描述:一对刚生下来的兔子, 两个月之后会繁殖一对兔子,求 N 月之后共有多少对兔子。
(5)参考资料:
http://translate.google.com/translate?hl=zh-CN&sl=zh-TW&u=http://www.stat.nctu.edu.tw/MISG/SUmmer_Course/C_language/Cdatastru/DataFib.htm&sa=X&oi=translate&resnum=1&ct=result&prev=/search%3Fq%3D%25E8%25B4%25B9%25E6%25B0%258F%2B%25E7%25BA%25A7%25E6%2595%25B0%2B%25E5%2585%2594%25E5%25AD%2590%26hl%3Dzh-CN%26lr%3D%26newwindow%3D1%26sa%3DG
http://translate.google.com/translate?hl=zh-CN&sl=zh-TW&u=http://web.nlhs.tyc.edu.tw/~b305/fibonacci&sa=X&oi=translate&resnum=9&ct=result&prev=/search%3Fq%3D%25E8%25B4%25B9%25E6%25B0%258F%2B%25E7%25BA%25A7%25E6%2595%25B0%2B%25E5%2585%2594%25E5%25AD%2590%26start%3D10%26hl%3Dzh-CN%26lr%3D%26newwindow%3D1%26sa%3DN
(6)关键字:繁殖、一对兔子、两个月
(7)计算实例:
有繁殖能力的兔子|兔子总数| 月份
0                 1         1
1                 1         2
1                 2         3
2                 3         4
3                 5         5
5                 8         6
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
5702887
9227465
14930352
24157817
39088169
63245986
102334155
165580141
267914296
433494437
701408733
1134903170
1836311903
2971215073
}

//(8)函数实现:
// 费氏级数: 有繁殖能力的兔子数
function FeiShiJiShu(N: Integer): DWORD;
var
  Fn, Fn1, Fn2: DWORD;
  I: Integer;
begin
  Fn := 0;
  if n <=1 then
    Result := Fn
  else
  begin
    Fn2 := 0;  
    Fn1 := 1;
    Log(IntToStr(Fn2));
    Log(IntToStr(Fn1));
    for I:= 0 to N-3 do
    begin
      if Fn1 >= (High(Fn1) div 2) then // 防止溢出
        Break;
      Fn := Fn2 + Fn1;
      Log(IntToStr(Fn)); // 只须打印 Fn
      Fn2 := Fn1;
      Fn1 := Fn
    end;
    Result := Fn;
  end;
end;
{
(9)相关特性: 费氏级数与黄金分割点(fn/fn+1)

性质:
  0,1,1,2,3,5,8,13,21,34
  fn+2/fn+1 = 1 + fn/fn+1
  13/8 = 1 + 5/8

  h1 := 433494437  / 701408733  =
  h2 := 701408733  / 1134903170 =
  h3 := 1134903170 / 1836311903 =
  h4 := 1836311903 / 2971215073 =

计算实例:
0
1
0.000000000000000000
1.000000000000000000
0.500000000000000000
0.666666666666666667
0.600000000000000000
0.625000000000000000
0.615384615384615385
0.619047619047619048
0.617647058823529412
0.618181818181818182
0.617977528089887640
0.618055555555555556
0.618025751072961373
0.618037135278514589
0.618032786885245902
0.618034447821681864
0.618033813400125235
0.618034055727554180
0.618033963166706530
0.618033998521803400
0.618033985017357939
0.618033990175597087
0.618033988205325051
0.618033988957902001
0.618033988670443186
0.618033988780242683
0.618033988738303007
0.618033988754322538
0.618033988748203621
0.618033988750540839
0.618033988749648102
0.618033988749989097
0.618033988749858848
0.618033988749908599
0.618033988749889596
0.618033988749896854
0.618033988749894082
0.618033988749895141
0.618033988749894736
0.618033988749894891
0.618033988749894832
0.618033988749894854
0.618033988749894846
0.618033988749894849
0.618033988749894848
0.618033988749894848
}
function FeiShiJiShu_HuangJin(N: Integer): DWORD;
const
  cnF18 = '%.18f';
var
  Fn, Fn1, Fn2: DWORD;
  a1, a2: Double;
  I: Integer;
begin
  Fn := 0;
  if n <=1 then
    Result := Fn
  else
  begin
    Fn2 := 0;  
    Fn1 := 1;
    Log(IntToStr(Fn2));
    Log(IntToStr(Fn1));
    for I:= 0 to N-3 do
    begin
      if Fn1 >= (High(Fn1) div 2) then // 防止溢出
        Break;
      Fn := Fn2 + Fn1;
      a1 := Fn1;
      a2 := Fn2;
      Log(Format(cnF18, [a2 / a1]));
      Fn2 := Fn1;
      Fn1 := Fn
    end;
    Result := Fn;
  end;
end;
Author: Passion    Time: 2007-5-31 17:10

写的出Fibonacci级数的通项公式不?不许google嘿嘿。
Author: zzzl    Time: 2007-6-3 00:51

意义描述:一对刚生下来的兔子, 两个月之后会繁殖一对兔子,求 N 月之后共有多少对兔子。

好怀念的题目。。
Author: Passion    Time: 2007-6-10 19:31

居然没人写通项公式?其实这个公式挺奇妙……
Author: skyjacker    Time: 2007-6-11 12:45

偶正在复习如何推演出某个通项公式  

奇妙的公式很有难度阿
Author: Passion    Time: 2007-6-11 15:03

我是高考复习时从别的地方看来的。
做个假设,解个方程,然后假设合理,就OK了。




Welcome to CnPack Forum (http://bbs.cnpack.org/) Powered by Discuz! 5.0.0