Skip to content

Instantly share code, notes, and snippets.

@gufodotto
Created June 3, 2012 14:29
Show Gist options
  • Save gufodotto/2863741 to your computer and use it in GitHub Desktop.
Save gufodotto/2863741 to your computer and use it in GitHub Desktop.
Lorentz
library(deSolve) # require this library
Lorenz<-function(t, state, parameters) {
with(as.list(c(state, parameters)),{
# rate of change
dX <- a*X + Y*Z
dY <- b * (Y-Z)
dZ <- -X*Y + c*Y - Z
# return the rate of change
list(c(dX, dY, dZ))
}
) # end with(as.list ...
}
# define controlling parameters
parameters <- c(a = -8/3, b = -10, c = 28)
# define initial state
state <- c(X = 1, Y = 1, Z = 1)
# define integrations times
times <- seq(0, 100, by = 0.001)
# perform the integration and assign it to variable 'out'
out<-ode(y = state, times = times, func = Lorenz, parms = parameters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment