What about
n<-2000 params <- list(s=10,b=8/3,p=28,dt=0.003) X0 <- X <- c(x=10,y=0,z=20) itfun <- function(X) { with(c(as.list(X),params), X + c(s*(yx),x*(pz)-y,x*yb*z)*dt) } Xmat <- rbind(X0,t(replicate(n,X <<- itfun(X)))) library(rgl) plot3d(Xmat,type= 'l',col = 'red')
or (including response from comments)
do.call(rbind, Reduce(function(X, i) { with(c(params, as.list(X)), X + c(s*(yx),x*(pz)-y,x*yb*z)*dt) }, seq(n), X, accumulate=TRUE)[-1])
PS How do you calculate the lines? If you use a sufficient number of semicolons, you can do it all on one line :-) I count 11 statements in your code
edit : some brackets were missing in update x
source share