R程序中约df中的舍入逻辑误差

问题描述 投票:0回答:1

我正在尝试解决问题。当我运行此代码时,我实现了想要的功能。(。8372e-03 1.8372e-06 1.8372e-09)

truncation.error <- function(f, x) {
  steps <- c(0.1, 0.01, 0.001)
  n <- length(steps)
  fdx1 <- vector(length = n)
  for (h in 1:n) {
    fdx1[h] <- exp(2.4)*steps[h]^3/6
  }
  return(fdx1)
}
for (i in 2.4) {
  print(truncation.error(f, x))}

但是,当我以data.frame格式编写时,截断错误的输出为0-0-0。为什么输出改变了?任何的想法?以及如何解决此问题。我想看到上面我实现的真实答案。;

colnames(approx.df) <- c('Actual Values', 'Central Difference Approx', 'Central Differences Error', "truncation error")

approx.df```



Original question is [ [1]: https://i.stack.imgur.com/hmO3I.png][1]


How can I solve this problem or where am I making mistake? Thanks a lot.


 [1]: https://i.stack.imgur.com/hmO3I.png

r numeric linear-programming numerical-methods numerical-analysis
1个回答
0
投票

change f <- expression(exp(x)) it to f <- as.expression(exp(x))。您的错误将消失和您正在做的错误是您没有在实际中定义这些东西,central.approx,实际-central.approx这些变量在代码中保存或定义的位置?

© www.soinside.com 2019 - 2024. All rights reserved.