# First function work well, generate random numbers
n <-10
inv.f <- array(0, dim=c(n ,1))
for(i in 1:n){
u <- runif(1,0,1)
gexp.cdf <- function(x,beta=5.5){ (1-exp(-beta*x))-u }
inv.f[i,] <- uniroot(gexp.cdf, lower=0, upper=5,extendInt="yes")$root
}
inv.f
Second Function did not work. did not generate random numbers. any suggestion please.
RN <- function(n){
inv.f <- array(0, dim=c(n ,1))
for(i in 1:n){
u <- runif(1,0,1)
gexp.cdf <- function(x,beta=5.5){ (1-exp(-beta*x))-u }
inv.f[i,] <- uniroot(gexp.cdf, lower=0, upper=5,extendInt="yes")$root
}
}
RN(5)
Aucun commentaire:
Enregistrer un commentaire