例2:X'=aX+YZ

        Y'=b(Y-Z)

        Z'=-XY+cY-Z

       其中a=-8/3,b=-10,c=28.

求解上述方程的R代码如下:

library(deSolve)
a<- -8/3
b<--10
c<- 28
yini<- c(X=1,Y=1,Z=1)
Lorenz<-function(t,y,parms){
       with(as.list(y),{
        dX<-a*X+Y*Z
        dY<-b*(Y-Z)
        dZ<- -X*Y+c*Y-Z
        return(list(c(dX,dY,dZ)))
        })
        }
times<-seq(from=0,to=100,by=0.01)
out<-ode(y=yini,times=times,func=Lorenz,parms=NULL)

参考文献:

Karline S, Thomas P, Setzer R W. Solving Differential Equations in R[M]. Springer Publishing Company, Incorporated, 2012.