[R] Uniroot - error

CarJabo carly_tse at hellokitty.com
Fri May 6 15:00:11 CEST 2011


Hi,

I have tried to use uniroot to solve a value (value a in my function) that
gives f=0, and I repeat this process for 10000 times(stimulations). However
error occures from the 4625th stimulation - Error in uniroot(f, c(0, 2),
maxiter = 1000, tol = 0.001) : 
  f() values at end points not of opposite sign

I have also tried interval of (lower=min(U), upper=max(U)) and it won't work
as well.

Can anyone help me as I have struggled for few days already and I have to
finish it soon. Thanks.


numsim=10000

set.seed(12345)

P = c()
for (m in 1:numsim) {

Y = rnorm(140,0.0125,(0.005^(1/2)))
U = exp(X1)
.............
.............(sorry i have to skip the code in between otherwise
..............my assignment will get penalty for plagarism according to
those screening sotware)
............
S = sum(.....)

f = function(a){sum(F*(answer^(910:1))) - S}

answer = uniroot(f, c(0,2), maxiter=1000,tol=0.001)$root
P[m] = answer^26 - 1
}

all the vectors are correct; it works without stimulation; it also works for
loop(1:4624) but after 4625 there's error.

--
View this message in context: http://r.789695.n4.nabble.com/Uniroot-error-tp3502628p3502628.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list