I don't see the problem, except that you might want to think about
what the error message is telling you.

A little exploration of your function always helps, too.

 > ss <- seq(-2, 2, len = 100)
 > plot(ss, fn(ss), type = "l")
 > uniroot(fn, c(-1, 1))
Erreur dans uniroot(fn, c(-1, 1)) : f() values at end points not of 
opposite sign


 > fn(-1)
[1] 3.330833
 > fn(0)
[1] -0.0025
 > fn(1)
[1] 0.5857353
 > uniroot(fn, c(-1, 0))
$root
[1] -0.6999466

$f.root
[1] -13118.83

$iter
[1] 18

$estim.prec
[1] 7.70751e-05

 > uniroot(fn, c(0, 1))
$root
[1] 0.001760625

$f.root
[1] 8.86832e-06

$iter
[1] 3

$estim.prec
[1] 6.103516e-05


> This below is not solvable with uniroot to find "a":
> fn=function(a){
> b=(0.7/a)-a
> (1/(a+b+1))-0.0025
> }
> uniroot(fn,c(-500,500))  gives
> "Error in uniroot(fn, c(-500, 500)) : f() values at end points not of
> opposite sign"
>
> I read R-help posts and someone wrote a function:
> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/92407.html
> but it is not very precise. Is there any '"standard" function in R 
> that can
> solve this? thanks.

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to