双摆混沌理论 中的一个常见示例,这里通过 python 的作图工具包Matplotlib 来模拟双摆的运动过程:

注意:在 vs2017 中可以正确运行程序,在 cmd 环境下有时报错

"""
===========================
The double pendulum problem
=========================== This animation illustrates the double pendulum problem.
""" # Double pendulum formula translated from the C code at
# http://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c from numpy import sin, cos
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
import matplotlib.animation as animation G = 9.8 # acceleration due to gravity, in m/s^2
L1 = 1.0 # length of pendulum 1 in m
L2 = 1.0 # length of pendulum 2 in m
M1 = 1.0 # mass of pendulum 1 in kg
M2 = 1.0 # mass of pendulum 2 in kg def derivs(state, t): dydx = np.zeros_like(state)
dydx[0] = state[1] del_ = state[2] - state[0]
den1 = (M1 + M2)*L1 - M2*L1*cos(del_)*cos(del_)
dydx[1] = (M2*L1*state[1]*state[1]*sin(del_)*cos(del_) +
M2*G*sin(state[2])*cos(del_) +
M2*L2*state[3]*state[3]*sin(del_) -
(M1 + M2)*G*sin(state[0]))/den1 dydx[2] = state[3] den2 = (L2/L1)*den1
dydx[3] = (-M2*L2*state[3]*state[3]*sin(del_)*cos(del_) +
(M1 + M2)*G*sin(state[0])*cos(del_) -
(M1 + M2)*L1*state[1]*state[1]*sin(del_) -
(M1 + M2)*G*sin(state[2]))/den2 return dydx # create a time array from 0..100 sampled at 0.05 second steps
dt = 0.05
t = np.arange(0.0, 20, dt) # th1 and th2 are the initial angles (degrees)
# w10 and w20 are the initial angular velocities (degrees per second)
th1 = 120.0
w1 = 0.0
th2 = -10.0
w2 = 0.0 # initial state
state = np.radians([th1, w1, th2, w2]) # integrate your ODE using scipy.integrate.
y = integrate.odeint(derivs, state, t) x1 = L1*sin(y[:, 0])
y1 = -L1*cos(y[:, 0]) x2 = L2*sin(y[:, 2]) + x1
y2 = -L2*cos(y[:, 2]) + y1 fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 2))
ax.grid() line, = ax.plot([], [], 'o-', lw=2)
time_template = 'time = %.1fs'
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes) def init():
line.set_data([], [])
time_text.set_text('')
return line, time_text def animate(i):
thisx = [0, x1[i], x2[i]]
thisy = [0, y1[i], y2[i]] line.set_data(thisx, thisy)
time_text.set_text(time_template % (i*dt))
return line, time_text ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)),
interval=25, blit=True, init_func=init) # ani.save('double_pendulum.mp4', fps=15)
plt.show()

原文地址:

https://matplotlib.org/examples/animation/double_pendulum_animated.html 作图工具包

https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/general.html 微积分求解工具包

https://docs.huihoo.com/scipy/scipy-zh-cn/double_pendulum.html 简单双摆轨迹图

https://en.wikipedia.org/wiki/Catastrophe_theory 突变理论

最新文章

  1. C语言-Hello, world
  2. c++11的右值引用、移动语义
  3. iOS-工作经验+资料分享(长期更新)
  4. java07课堂作业
  5. 求树的重心(POJ1655)
  6. How to change Jenkins default folder on Windows?
  7. STSdb
  8. Centos6.5源码编译安装nginx
  9. QCA4002/QCA4004 为主流家电和消费电子产品推出低功耗Wi-Fi平台
  10. spring jar包
  11. handsontable自定义渲染
  12. HTML/CSS实现的一个列表页
  13. Oracle学习DayThree
  14. Spring MVC 学习总结(十一)——IDEA+Maven+多模块实现SSM框架集成
  15. mysql数据库1
  16. 【Java集合系列二】LinkedList解析
  17. hive之权限问题AccessControlException Permission denied: user=root, access=WR
  18. 【bzoj3132】 Sdoi2013—森林
  19. HDUOJ-----2065"红色病毒"问题
  20. 字符型设备驱动程序-first-printf以及点亮LED灯(三)

热门文章

  1. 到达时间自动点击按钮弹出提示并跳转【JavaScript实现】
  2. openjudge7627 鸡蛋的硬度
  3. LOAP& its implimenlation
  4. spring依赖注入中获取JavaBean
  5. Windows堆思维导图--Windows pro sp3
  6. restful接口就是url嘛,通过http请求发起访问。那接口进行监控,就可以监控这个restful url嘛
  7. Linux下搭建maven私服Nexus 3.2.1-01
  8. [转载]【BlackHat 2017】美国黑客大会首日议题汇总,演讲PPT下载也在这里
  9. 017 SSH
  10. centos 建立Clamav自动扫描脚本