CnPack Forum


 
Subject: 费氏级数(Fibonacci)的学习
skyjacker
版主
Rank: 7Rank: 7Rank: 7
茶农


UID 2239
Digest Posts 9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
Post at 2007-5-31 16:34  Profile | Blog | P.M.  | QQ
费氏级数(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;




一壶清茶煮青春.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2007-5-31 17:10  Profile | Blog | P.M. 
写的出Fibonacci级数的通项公式不?不许google嘿嘿。
Top
zzzl (早安的空气)
版主
Rank: 7Rank: 7Rank: 7



UID 590
Digest Posts 0
Credits 399
Posts 199
点点分 399
Reading Access 100
Registered 2004-11-29
Status Offline
Post at 2007-6-3 00:51  Profile | Blog | P.M.  | QQ
意义描述:一对刚生下来的兔子, 两个月之后会繁殖一对兔子,求 N 月之后共有多少对兔子。

好怀念的题目。。
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2007-6-10 19:31  Profile | Blog | P.M. 
居然没人写通项公式?其实这个公式挺奇妙……
Top
skyjacker
版主
Rank: 7Rank: 7Rank: 7
茶农


UID 2239
Digest Posts 9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
Post at 2007-6-11 12:45  Profile | Blog | P.M.  | QQ
偶正在复习如何推演出某个通项公式  

奇妙的公式很有难度阿




一壶清茶煮青春.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2007-6-11 15:03  Profile | Blog | P.M. 
我是高考复习时从别的地方看来的。
做个假设,解个方程,然后假设合理,就OK了。
Top
 




All times are GMT++8, the time now is 2024-11-22 13:32

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.010607 second(s), 9 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP