scipy模拟单摆

2020-12-27  本文已影响0人  一路向后

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

3.执行结果

test.png
上一篇 下一篇

猜你喜欢

热点阅读