, ,的连续到达计算为
独立指数间隔的累积和。所以这里的两个主要成分是和
。然后,您使用步进插值(和的额外点会有所帮助。Sii=12…rexpcumsum[Si,i]type = "s"i=0Si:=0
在给定的时间间隔内,您事先不知道有多少到达将到来。因此,您可以使用带有
控制语句的循环,也可以模拟超出需要的内容,如此处所示。第二个选项在 R 中可能更有效。Sibreak
lambda <- 0.5
tMax <- 100
## find the number 'n' of exponential r.vs required by imposing that
## Pr{N(t) <= n} <= 1 - eps for a small 'eps'
n <- qpois(1 - 1e-8, lambda = lambda * tMax)
## simulate exponential interarrivals the
X <- rexp(n = n, rate = lambda)
S <- c(0, cumsum(X))
plot(x = S, y = 0:n, type = "s", xlim = c(0, tMax))
## several paths?
nSamp <- 50
## simulate exponential interarrivals
X <- matrix(rexp(n * nSamp, rate = lambda), ncol = nSamp,
dimnames = list(paste("S", 1:n, sep = ""), paste("samp", 1:nSamp)))
## compute arrivals, and add a fictive arrival 'T0' for t = 0
S <- apply(X, 2, cumsum)
S <- rbind("T0" = rep(0, nSamp), S)
head(S)
## plot using steps
matplot(x = S, y = 0:n, type = "s", col = "darkgray",
xlim = c(0, tMax),
main = "Homogeneous Poisson Process paths", xlab = "t", ylab = "N(t)")