Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi,

Another option is to use the function desolve_odeint (from version 4.6 on, see the docs on desolve_odeint?), which uses the odeint solver internally, but takes as an input symbolic funcions . For instance, to integrate the Lorenz attractor, you would do

 sage: x,y,z=var('x,y,z') # Declare the variables 
 sage: lorenz=[10.0*(y-x),x*(28.0-z)-y,x*y-(8.0/3.0)*z]
 sage: times=srange(0,50.05,0.05) # Integration Time 
 sage: ics=[0,1,1] # and initial conditions
 sage: sol=desolve_odeint(lorenz,ics,times,[x,y,z]) #integrate

to plot the attractor, simply:

sage: line3d(sol)

I do not know what you mean exactly by the double pendulum, but here it is something similar:

sage: theta1,theta2,x1,x2=var('theta1,theta2,x1,x2')
sage: dpendulum=[x1,x2,-sin(theta1)-0.1*sin(theta2),-sin(theta2)+0.1*sin(theta1)]
sage: # Time and initial conditions
sage: times=srange(0,50.05,0.05) 
sage: ics=[1,1,0,0] 
sage: sol=desolve_odeint(dpendulum,ics,times,[theta1,theta2,x1,x2])

and a nice plot is here

sage: graphics_array([line(zip(sol[:,0],sol[:,2])),line(zip(sol[:,1],sol[:,3]))])

Joaquim Puig