unirootDiscrete: Identify where a non-increasing function changes sign

Description Usage Arguments Details Value Author(s) Examples

Description

Let f be a non-increasing (or non-decreasing) function that changes sign within the interval specified. If 'pos.side'=TRUE (or FALSE) then unirootDiscrete finds the value x such that f(x) is closest to the sign change and is positive (or negative).

Usage

1
2
3
unirootDiscrete(f, interval, lower = min(interval), 
    upper = max(interval), tol = 10^-5, pos.side = FALSE,
    print.steps = FALSE, maxiter = 1000, ...)

Arguments

f

function for which a root is needed

interval

an interval giving minimum and maximum allowable values for root

lower

lower bound for root

upper

upper bound for root

tol

absolute tolerance, abs(true root-estimated root)<= tol

pos.side

if TRUE finds value x closest to the sign change in f, such that f(x)>0

print.steps

if true prints interations

maxiter

maximum number of iterations

...

additional arguments to f

Details

The algorithm evaluates f(x) iteratively, and the change in 'x' is halved each iteration until the change in 'x' is less than tol. Then the root is returned according to the pos.side parameter.

Value

A list with the folllowing elements,

iter

number of iterations (times f is evaluated)

f.root

value of f(x), where x is the root

root

the root x, where f(x)>=0 if pos.side=TRUE

...

Author(s)

M.P. Fay

Examples

1
2
test<-function(x,parm=10.987654321){ ifelse(x>=parm,1,-1) }
unirootDiscrete(test,lower=0,upper=100,tol=10^-4,pos.side=FALSE,print.steps=TRUE)


Search within the binseqtest package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.