我写了一个函数,它应该计算斐波那契数到第 n ^ 步:
fibonnacciNumbers <- function(len) {
fibvals <- numeric(len)
fibvals[1] <- 1
fibvals[2] <- 1
for (i in 3:len) {
fibvals[i] <- fibvals[i-1]+fibvals[i-2]
}
return(fibvals)
}
(fibonnacciNumbers(100))
但是,我的输出如下所示:
[1] 1.000000e+00 1.000000e+00 2.000000e+00 3.000000e+00 5.000000e+00
[6] 8.000000e+00 1.300000e+01 2.100000e+01 3.400000e+01 5.500000e+01
[11] 8.900000e+01 1.440000e+02 2.330000e+02 3.770000e+02 6.100000e+02
[16] 9.870000e+02 1.597000e+03 2.584000e+03 4.181000e+03 6.765000e+03
[21] 1.094600e+04 1.771100e+04 2.865700e+04 4.636800e+04 7.502500e+04
[26] 1.213930e+05 1.964180e+05 3.178110e+05 5.142290e+05 8.320400e+05
[31] 1.346269e+06 2.178309e+06 3.524578e+06 5.702887e+06 9.227465e+06
[36] 1.493035e+07 2.415782e+07 3.908817e+07 6.324599e+07 1.023342e+08
[41] 1.655801e+08 2.679143e+08 4.334944e+08 7.014087e+08 1.134903e+09
[46] 1.836312e+09 2.971215e+09 4.807527e+09 7.778742e+09 1.258627e+10
[51] 2.036501e+10 3.295128e+10 5.331629e+10 8.626757e+10 1.395839e+11
[56] 2.258514e+11 3.654353e+11 5.912867e+11 9.567220e+11 1.548009e+12
[61] 2.504731e+12 4.052740e+12 6.557470e+12 1.061021e+13 1.716768e+13
为什么会有这些舍入误差?他们来自哪里?
我很感谢你的回答!!!