如何为以下二分法代码设置最大迭代 = 20?我应该只做 feval 还是其他什么?
rf.bisection <- function(f, lower, upper, tol=1e-4) {
flow <- f(lower)
fupper <- f(upper)
feval <- 2
if (flow * fupper > 0) stop("The given interval does not contain the root!
\n")
diff <- upper - lower
while (abs(diff) > tol) {
newpoint <- (lower + upper) / 2
newf <- f(newpoint)
if (abs(newf) <= tol) break
if (flow * newf < 0) upper <- newpoint
if (fupper * newf < 0) lower <- newpoint
diff <- upper - lower
feval <- feval + 1
}
list(x = newx, value = newf, fevals=feval)
}