Thanks for your help ! I got another problem with my function : test <- function(x,bb0=-3,bb1=5,c0=2,r0=0) { ((exp(c0-r0)*(bb0+x)*(bb1-x))/((bb0+x+1)*(bb1-x-1))-1)}
With this : curve(test(x),from=-10,to=10) we can see that there are 2 roots : one in [3,4] and one in [5,10] > uniroot(test,c(5, 10))$root [1] 5.243265 > uniroot(test,c(3, 4))$root [1] 3.069772 Even this works : > uniroot(test,c(3, 10))$root [1] 5.243263 but it's unfortunate that : > uniroot(test3,c(-10, 10))$root *Erreur dans uniroot(test3, c(-10, 10)) : les valeurs de f() aux points extrêmes ne sont pas de signe opposé* doesn't work, because I have to find the root for c0 in [-10,10] but I can't change the range at each loop: I want to do something like this, do you have any ideas ? > for (i in -10:10) { + z <- uniroot(test,c(-10, 10), c0=i)$root + print(z)} Yann On Wed, Jun 10, 2009 at 2:33 AM, Ben Bolker <bol...@ufl.edu> wrote: > > > > Peter Alspach wrote: > > > > Tena koe Yann > > > > It may not be the only problem, but you are missing an operator between > > (bb0+x+1) and (bb1-x-1). > > > > > > And fixing that typo and viewing the function shows that it > is a bit problematic on this interval anyway ... (diverges > at x = 1, closer look shows it's pretty nasty -- I haven't stopped > to think about its behavior very carefully, but it will clearly > take some effort. If you're lucky there is a typo and the > real function is better behaved!) > > test <- function(x,bb0=-3,bb1=5,c0=2,r0=0) { > ((exp(c0-r0)*(bb0+x)*(bb1-x))/((bb0+x+1)*(bb1-x-1))-1)} > > > uniroot(test,c(-100,100))$root > curve(test(x),from=-100,to=100) > curve(test(x),from=1.00001,to=10) > abline(h=0,col=2) > -- > View this message in context: > http://www.nabble.com/Problem-%3A-solving-a-equation-with-R-%2C-fail-with-uniroot-function-tp23953174p23953614.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org 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. > [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org 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.