fabonacci equotion
fabonacci的通项公式:
var fabonacci = function(n){
return Math.round((Math.pow((1+Math.sqrt(5)),n+1) - Math.pow((1-Math.sqrt(5)),n+1))/(Math.pow(2,n+1)*Math.sqrt(5)));
}
公式是从组合数学的课本上抄过来的,数学真是一个比较好玩的东西,很多东西可以通过它的处理就可以变得的简单.
不过JavaScript真的是不适合作精确计算,这样的计算就要用Math.round来调整
var fabonacci = function(n){
return Math.round((Math.pow((1+Math.sqrt(5)),n+1) - Math.pow((1-Math.sqrt(5)),n+1))/(Math.pow(2,n+1)*Math.sqrt(5)));
}
公式是从组合数学的课本上抄过来的,数学真是一个比较好玩的东西,很多东西可以通过它的处理就可以变得的简单.
不过JavaScript真的是不适合作精确计算,这样的计算就要用Math.round来调整


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home