bracketing(fun, interval, ...,
lower = min(interval), upper = max(interval),
n = 20L,
method = c("loop", "vectorised", "multicore", "snow"),
mc.control = list(), cl = NULL)
fun(x, ...)
with
x
being a numeric vectorfun
interval
is specified.interval
is specified.fun
is evaluated only at the end-points); defaults to 20.loop
(the default), vectorised
, multicore
or snow
. See Details.mclapply
if
method
is multicore
. Must be a list of named
elements. See the documentation of mclapply
in package NULL
. If method
is snow
, this must be a
cluster object or an integer (the number of cores to be used). See the
documentation of package bracketing
evaluates fun
at equal-spaced values of x
between (and including) lower
and upper
. If the sign of
fun
changes between two consecutive x
-values,
bracketing
reports these two x
-values as containing (bracketing
will not narrow the chosen intervals.
The argument method
determines how fun
is
evaluated. Default is loop
. If method == "vectorised"
,
fun
must be written such that it can be evaluated for a vector
x
(see Examples). If method == "multicore"
, function
mclapply
from package mclapply
can be passed through the list
mc.control
. If multicore
is chosen but the package is
not available (eg, currently on Windows), then method
will be
set to loop
and a warning is issued. If method ==
"snow"
, function clusterApply
from package cl
must either be a cluster
object (see the documentation of clusterApply
) or an
integer. If an integer, a cluster will be set up via
makeCluster(c(rep("localhost", cl)), type = "SOCK")
, and
stopCluster
is called when the function is exited. If
snow
is chosen but the package is not available or cl
is
not specified, then method
will be set to loop
and a
warning is issued. In case that cl
is a cluster object,
stopCluster
will not be called automatically.uniroot
(in package ## Gilli/Maringer/Schumann (2011), p. 290
testFun <- function(x) cos(1/x^2)
bracketing(testFun, interval = c(0.3, 0.9), n = 26L)
bracketing(testFun, interval = c(0.3, 0.9), n = 26L, method = "vectorised")
Run the code above in your browser using DataLab