## This examples shows that 'solvePosDef' can be much faster
## than 'solve'
## creating a covariance matrix for a temporal process
covmatrix <- function(model, x) {
x <- as.matrix(dist(x))
return(eval(substitute(model)))
}
size <- 600
x <- runif(size, 0, size / 10)
M <- covmatrix((1 - x) * (x < 1) , x) ## Askey's model of covariance
b <- seq(0, 1, len=size)
unix.time(inv2 <- solve(M, b))
unix.time(inv1 <- solvePosDef(M, b)) ## much faster in this case
range(inv2 - inv1)Run the code above in your browser using DataLab