1.源码实现
from math import sin
import numpy as np
from scipy.integrate import odeint
import pylab as pl
g = 9.8
def pendulum_equations(w, t, l):
th, v = w # v = th'
dth = v # dth = th'
dv = - g / l * sin(th)
return dth, dv
t = np.arange(0, 10, 0.01)
track = odeint(pendulum_equations, (1.0, 0), t, args=(1.0,))
pl.plot(t, track[:, 0])
pl.title(u"simple pendulum")
pl.xlabel(u"time(s)")
pl.ylabel(u"radian(rad)")
pl.savefig("test.png")
2.运行程序
$ python3 example.py
网友评论