powered by
Find the root of a monotone function on a discrete grid of value using dichotomic search
discreteRoot(fn, grid, increasing = TRUE, check = TRUE, tol = .Machine$double.eps^0.5)
[function] objective function to minimize in absolute value.
[vector] possible minimizers.
[logical] is the function fn increasing?
[logical] should the program check that fn takes a different sign for the first vs. the last value of the grid?
[numeric] the absolute convergence tolerance.
# NOT RUN { ### find the position of a value in a vector f <- function(x){abs(vec[x]-1)} discreteRoot(function(x){x},grid = seq(-20,10,1)) # }
Run the code above in your browser using DataLab