双摆混沌理论 中的一个常见示例,这里通过 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 突变理论

双摆模拟 python(转)的更多相关文章

  1. Mock实现模拟python的对象

    Mock库的应用 Mock在Python3.3之前是第三方库,需要安装 pip install Mock :导入 import mock Mock在Python3.3之后是Python标准库,导入方式 ...

  2. OpenAI 开源机器人模拟 Python 库,并行模拟处理速度提升400%

    10000da.cnvboyule.cnjiaeidaypt.cn  在过去一年的研究中,OpenAI团队开源一个使用 MuJoCoengine开发的用于机器人模拟的高性能Python库.雷锋网了解到 ...

  3. Enigma模拟-Python

    设计思想 Enigma机的机械结构: 键盘:加密人员通过键盘进行输入 转子:Enigma机上一般装有至少3个转轮.每个转轮有代表26个字母的触头和触点,触点和触头在转轮内部有导线相连(一个转轮相当于一 ...

  4. 模拟python中的Yield伪并发

    并发,在操作系统中,是指一个时间段中有几个程序都处于已启动运行到运行完毕之间,且这几个程序都是在同一个处理机上运行,但任一个时刻点上只有一个程序在处理机上运行. #Yield伪并发 _author_= ...

  5. C++模拟python风格的print函数--打印vector,map,list等结构

    // 最基本实现 template<typename T> static void print(T t) { std::cout << t; } // 处理 std::pair ...

  6. Python 的mock模拟测试介绍

    如何不靠耐心测试 可能我们正在写一个社交软件并且想测试一下"发布到Facebook的功能",但是我们不希望每次运行测试集的时候都发布到Facebook上. Python的unitt ...

  7. Python学习--04条件控制与循环结构

    Python学习--04条件控制与循环结构 条件控制 在Python程序中,用if语句实现条件控制. 语法格式: if <条件判断1>: <执行1> elif <条件判断 ...

  8. CoffeeScript实现Python装潢器

    在上篇Angular遇上CoffeeScript – NgComponent封装中,我们讲述了CoffeeScript这门小巧的语言,摒弃JavaScript中糟粕(“坑”)部分,并将JavaScri ...

  9. Python IDLE 运行错误:IDLE's subprocess didn't make connection. --已解决(原创)!

    Python IDLE 错误描述: Subprocess Startup ErrorIDLE's subprocess didn't make connection. Either IDLE can' ...

随机推荐

  1. 2.3 comparator(比较器)

    1.comparator是java的一种机制,用来帮助我们给相同对象的不同属性排序 2.Comparable接口,是一个对象本身就已经支持自比较所需要实现的接口,如String,Integer自己就已 ...

  2. poj_3006_Dirichlet's Theorem on Arithmetic Progressions_201407041030

    Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  3. Extjs6(六)——增删查改之查询

    本文主要实现的效果是:点击查询按钮,根据form中的条件,在Grid中显示对应的数据(如果form为空,显示全部数据) 一.静态页面 1.查询按钮 { text:'查询', handler: 'onS ...

  4. 洛谷 P1122 最大子树和

    P1122 最大子树和 题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的 ...

  5. redhat and centos 系统经常使用命令

    查看cpu信息:     more /proc/cpuinfo |grep "model name"     通常是至强系统 查看内存信息:     grep MemTotal / ...

  6. 数学之路-分布式计算-storm(3)

    .安装zookeeper 本博客全部内容是原创.假设转载请注明来源 http://blog.csdn.net/myhaspl/ myhaspl@aaayun:~/jzmq-master$cd .. m ...

  7. tmux还有这种操作,我在这边的窗口上操作,你那边可以实时的看到我的操作,厉害了

  8. 重置网络命令win7

    开始→运行→输入:CMD 点击确定(或按回车键),打开命令提示符窗口. 在命令提示符中输入:netsh winsock reset (按回车键执行命令) 稍后,会有成功的提示:成功地重置Winsock ...

  9. 从头认识Spring-2.3 注解装配-@autowired(4)-required(2)

    这一章节我们来继续具体讨论一下@autowired里面的參数required.在多构造器注入的情况. 1.domain(重点) 蛋糕类: package com.raylee.my_new_sprin ...

  10. C# .NET 如何修改代码字体

    工具-选项-字体和颜色