未在 R 中发现符号更改错误,但未发现 excel

No sign change found error in R but not excel

只是想了解为什么当我在 excel 中找到以下等式的根时,我得到了一个值,但是在 R 中我得到了 "no sign change found error"

(-exp(-i*x))-x + 1 

在这种情况下我 = 1。

我正在绘制一个图表,其中 i 的值为 1:5。我在 excel 上手动完成此操作并在 i = 1 时得到 0.003 的值,这是 i 所有值的图表:image 1

当我尝试在 R 中查找当 i = 1 时的根时,尽管出现错误。

这是我用来查找根的代码:

func1 <- function(x) {

  (-exp(-1*x))-x+1 
}

root <- uniroot(func1, lower =0.5, upper = 1, extendInt = "yes")
print(root)
print(root$root)

}

当 i = 1 时绘制等式给出以下曲线:image 2

从曲线上看,f(x) 似乎没有穿过 0,这解释了错误,但是,我在 excel.

中得到了一个值

如有任何帮助,我们将不胜感激

谢谢

这是我能提供的最好的。它使用的是我在 http://rpubs.com/wkmor1/simple-derivatives-in-r 找到的一种导数方法。它将允许您从牛顿方法中获得根源。

options(scipen = 999)
f<-function(x) (-exp(-x)-x+1)
g<-function(x) { }
body(g)<-D(body(f),"x")
x <- 19
y<-vector()
y[1]<-x
for(i in 2:500) {
  y<-c(y, y[i-1] - (f(y[i-1])/g(y[i-1])))
  if(y[i]==y[i-1]) break
}
y

输出如下所示:

> y
 [1] 19.000000000000000  0.999999893546867  0.418023257075328  0.194491909332762
 [5]  0.094095681658666  0.046310116577025  0.022976345768161  0.011444180565743
 [9]  0.005711176200954  0.002852869974152  0.001425756748278  0.000712708975595
[13]  0.000356312158327  0.000178145499021  0.000089070105497  0.000044534390909
[17]  0.000022267031356  0.000011133470771  0.000005566723944  0.000002783342584
[21]  0.000001391644148  0.000000695821730  0.000000347990248  0.000000173795172
[25]  0.000000086916841  0.000000043487300  0.000000023063442  0.000000013435885
[29] -0.000000003090351 -0.000000003090351

希望对您有所帮助。