Code
suppressPackageStartupMessages(library(deSolve))
suppressPackageStartupMessages(library(plotly))
This page shows a simulation of the Lorenz system. The code is drawn from Wikipedia contributors (2025).
\[\dot{x} = \sigma(y-x) \] \[\dot{y} = \rho x - y - xz \] \[\dot{z} = -\beta z + xy \]
Quietly load required libraries.
suppressPackageStartupMessages(library(deSolve))
suppressPackageStartupMessages(library(plotly))
Simulate n=10^{4} time points
# parameters
<- list(sigma = 10, rho = 28, beta = 8/3)
prm # initial values
<- c(
varini X = 1,
Y = 1,
Z = 1
)
<- function (t, vars, prm) {
Lorenz with(as.list(vars), {
<- prm$sigma*(Y - X)
dX <- X*(prm$rho - Z) - Y
dY <- X*Y - prm$beta*Z
dZ return(list(c(dX, dY, dZ)))
})
}
<- seq(from = 0, to = 100, by = 0.01)
times # call ode solver
<- ode(y = varini, times = times, func = Lorenz,
out parms = prm)
Plot data.
# to assign color to points
<- function (repArr, long) {
gfill rep(repArr, ceiling(long/length(repArr)))[1:long]
}
<- as.data.frame(out)
dout
$color <- gfill(rainbow(10), nrow(dout))
dout
# Graphics production with Plotly:
plot_ly(
data=dout, x = ~X, y = ~Y, z = ~Z,
type = 'scatter3d', mode = 'lines',
opacity = 1, line = list(width = 6, color = ~color, reverscale = FALSE)
)