[R] what is the purpose of an error message in uniroot?

Matthew Keller mckellercran at gmail.com
Wed Jan 31 22:33:26 CET 2007


Hi all,

This is probably a blindingly obvious question: Why does it matter in
the uniroot function whether the f() values at the end points that you
supply are of the same sign?

For example:

f <- function(x,y) {y-x^2+1}

#this gives a warning
uniroot(f,interval=c(-5,5),y=0)
Error in uniroot(f, interval=c(-5, 5), y = 0) : f() values at end
points not of opposite sign

#this doesn't give a warning
uniroot(f,interval=c(.1,5),y=0)
$root
[1] 1

$f.root
[1] 1.054e-05

$iter
[1] 9

$estim.prec
[1] 6.104e-05

If I comment out the two lines of script in the uniroot function that
produce this warning and create a new function, call it uniroot2,
everything works as I'd like. But for didactic purposes, why did the
creators of uniroot want the f() values at endpoints to be of opposite
sign?

Thanks in advance,

Matt



More information about the R-help mailing list