Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 R 中,为什么对于 y > 2 这是错误的?
y <- c(1, 2, 3, 4, 5) x <- 2*y exp(log(x)) == exp(log(y)) * 2 [1] TRUE TRUE FALSE FALSE FALSE
数值精度。尝试计算差异:
exp(log(x)) - exp(log(y)) * 2
你可以使用类似的东西:
all.equal( exp(log(x)) , exp(log(y)) * 2 )
确切地说,数值精度是原因。试试这个,更简单的计算
1/2+1/3+1/6 #equal to 1 (1/2+1/3+1/6)-1 # should be 0 [1] -1.110223e-16