## Monday, August 20, 2012

### Lorenz Attractor Simulation

# This is a brief exploration of Chaos theory.  The Lorenz attractor is an equation used to model convection.  It is defined by the system of equations:

# dx/dt = sigam(y-x)
# dy/dt = x(rho-z)-y
# dz/dt = xy-beta*z

# With sigma, rho, and beta representing model parameters.

# We can easily approximate this system by a series of discreet time steps

# First set the initial values
y = 5
x = 5
z = 5

# Now let's set the parameters
sigma = 10
rho = 28
beta = 8/3

for (i in 1:9999) {
x[i+1] = x[i] + sigma*(y[i]-x[i])/200
y[i+1] = y[i] + (x[i]*(rho-z[i])-y[i])/200
z[i+1] = z[i] + (x[i]*y[i]-beta*z[i])/200
}

plot(x[!is.na(x)],y[!is.na(x)], type="n")

for(i in 1:(length(x)-1))
lines (x[i:(i+1)], y[i:(i+1)], col = rainbow(length(x))[i])