longd0_function(ps, pss, pff, n, d) { #this program compute the probability P(L0>=d)# #L0 is the perfect matching run within a sequence of length n# # ps is the initial prob. for "s", and pss is the transition prob of 1 given 1# a <- matrix(1, d, 1) b <- diag(a, d) c <- matrix(0, 1, d) p0 <- cbind(1, c) p0 <- cbind(p0, 0) U <- rbind(a, 0) U <- rbind(1, U) c <- cbind(c, 1) M <- cbind((1 - pss) * a, pss * b) M <- rbind(M, c) M <- cbind(0, M) M <- rbind(0, M) M[1, 2] <- 1 - ps M[1, 3] <- ps M[2, 2] <- pff M[2, 3] <- 1 - pff Mn <- M %*% M for(i in 3:n) { Mn <- Mn %*% M } 1 - p0 %*% Mn %*% U }