Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 675
skrooms Avatar asked Apr 13 '18 00:04

skrooms


People also ask

How do you plot a phase portrait?

To generate the phase portrait, we need to compute the derivatives y′1 and y′2 at t=0 on a grid over the range of values for y1 and y2 we are interested in. We will plot the derivatives as a vector at each (y1, y2) which will show us the initial direction from each point.

What is a pendulum phase?

The phase-space trajectory that represents the motion of the pendulum at the limit where the motion changes from 'back and forth' to continuous rotation is called the separatrix. The purple trajectory in figure 2 is very close in energy to the separatrix and is extremely close to it in shape.

What does a phase portrait show?

A phase portrait represents the directional behavior of a system of ordinary differential equations (ODEs). The phase portrait can indicate the stability of the system.


1 Answers

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

enter image description here

like image 108
Lutz Lehmann Avatar answered Sep 28 '22 17:09

Lutz Lehmann