library(stats) # input x = (x_0, x_1, ... x_{n+1}), and simulate the process on this, # begun at w, up to time T, # killed upon hitting x_0 or x_{n+1}. simul <- function(w, x, T=1000) { x <- sort(x); n <- length(x); dx <- diff(x); dir <- runif(T); loc <- c(which(w==x),rep(NA,T)); if(is.na(loc[1])) {error("initial point not in state space");} i<-1; while (i