如何使用 pylab 绘制钟摆运动的相平面? [英] How do I use pylab to plot a phase plane for pendulum motion?

查看:51
本文介绍了如何使用 pylab 绘制钟摆运动的相平面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于绘制以下捕食者猎物模型的代码:

I have code that will work for plotting the following predator prey model:

dx/dt = x − xy,dy/dt = −y + xy

dx/dt = x − xy, dy/dt = −y + xy

from pylab import *
xvalues, yvalues = meshgrid(arange(0, 3, 0.1), arange(0, 3, 0.1))
xdot = xvalues - xvalues * yvalues
ydot = - yvalues + xvalues * yvalues
streamplot(xvalues, yvalues, xdot, ydot)
show()

但是我不确定如何使用这些功能绘制相平面(使用流图)来模拟摆运动,定义为

But I am not sure how to use these functions to draw a phase plane (using streamplot) to model pendulum motion, defined as

d^2θ/dt^2 = (−g/L)sin(θ)

d^2θ/dt^2 = (−g/L)sin(θ)

如何使用matplotlib和pylab来实现该模型以生成相平面?

How can I implement this model to produce a phase plane using matplotlib and pylab?

推荐答案

你也一样,先把它改成一阶系统

You do it the same way, first transform it into a first order system

thetadot = omega
omegadot = -g/L*sin(theta)

theta, omega 重命名为 x,y 以方便起见,然后像以前一样继续:

rename theta, omega to x,y for shortness and then proceed as before:

g,L = 1,1
xvalues, yvalues = meshgrid(arange(-8, 8, 0.1), arange(-3, 3, 0.1))
xdot = yvalues
ydot = -g/L*sin(xvalues)
streamplot(xvalues, yvalues, xdot, ydot)
grid(); show()

这给出了通常的相图

这篇关于如何使用 pylab 绘制钟摆运动的相平面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆