How do I use pylab to plot a phase plane for pendulum motion?

折月煮酒 提交于 2021-01-27 05:21:25

问题


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

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(θ)

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


回答1:


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

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

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()

which gives the usual phase portrait



来源:https://stackoverflow.com/questions/49807524/how-do-i-use-pylab-to-plot-a-phase-plane-for-pendulum-motion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!