美文网首页
scipy模拟单摆

scipy模拟单摆

作者: 一路向后 | 来源:发表于2020-12-27 11:28 被阅读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

相关文章

网友评论

      本文标题:scipy模拟单摆

      本文链接:https://www.haomeiwen.com/subject/zhkonktx.html