0

I want solve a root for this nonlinear function, and I input S, S2, S3 and S4 I calculated in advance. S2/(2*S) is the best estimator for the root; how can I set it as a starting point?

Does the code

interval = c(-1000,100)

contain the max & min of my roots so that I can omit the code f.lower?

R <- numeric(178)

for (i in (1:178)) {            
    f <- function(x){1 - exp(S[i]/x)+ (S2[i]/(2*(x^2)))- ((S2[i]^(3/2)*S3[i])/(6*(x^3))) + 
                       (((S2[i]^2)*S4[i])/(24*(x^4)))} 

  R[i] <- uniroot(f,interval = c(-1000,100), f.lower = S2[i]/(2*S[i]))$root
}

I have tried to Google it, but I didn't find any code to set a starting point. Thanks for all your suggestions.

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • You forgot to include the values of the data (`S2` etc). Please provide them so that there's a working reproducible example. – Hack-R Aug 19 '16 at 03:22
  • Your function seems to be discontinuous at `x = 0`. If so, how could it possibly make sense to use the bisection method on an interval which straddles 0? – John Coleman Aug 19 '16 at 03:29

0 Answers0