15.1 常微分方程
洛伦兹系统是一个常微分方程组,系统参数的默认值为 \((\sigma = 10, \rho = 28, \beta = 8/3)\),初值为 \((-13, -14, 47)\)。
\[\begin{equation*} \left\{ \begin{array}{l} \frac{\partial x}{\partial t} = \sigma (y - x) \\ \frac{\partial y}{\partial t} = x(\rho -z) - y \\ \frac{\partial x}{\partial t} = xy - \beta z \end{array} \right. \end{equation*}\]library(deSolve)
# 参数
<- c(a = -8 / 3, b = -10, c = 28)
pars # 初值
<- c(X = 1, Y = 1, Z = 1)
state # 时间间隔
<- seq(0, 100, by = 0.01)
times # 定义方程组
<- function(t, state, parameters) {
lorenz_fun with(as.list(c(state, parameters)), {
<- a * X + Y * Z
dX <- b * (Y - Z)
dY <- -X * Y + c * Y - Z
dZ list(c(dX, dY, dZ))
})
}<- ode(
out y = state, times = times,
func = lorenz_fun, parms = pars
)
调用 scatterplot3d 绘制三维曲线图,如图15.1 所示
library(scatterplot3d)
scatterplot3d(
x = out[, "X"], y = out[, "Y"], z = out[, "Z"],
col.axis = "black", type = "l", color = "gray",
xlab = expression(x), ylab = expression(y), zlab = expression(z),
col.grid = "gray", main = "Lorenz"
)