1- # phaseplots.py - examples of phase portraits
2- # RMM, 24 July 2011
3- #
4- # This file contains examples of phase portraits pulled from "Feedback
5- # Systems" by Astrom and Murray (Princeton University Press, 2008).
6-
7- import os
8-
9- import numpy as np
10- import matplotlib .pyplot as plt
11- from control .phaseplot import phase_plot
12- from numpy import pi
13-
14- # Clear out any figures that are present
15- plt .close ('all' )
16-
171#
182# Inverted pendulum
193#
@@ -40,9 +24,11 @@ def invpend_ode(x, t, m=1., l=1., b=0.2, g=1):
4024 logtime = (3 , 0.7 )
4125)
4226
27+ get_plot ()
4328# Separatrices
4429phase_plot (invpend_ode , X0 = [[- 2.3056 , 2.1 ], [2.3056 , - 2.1 ]], T = 6 , lingrid = 0 )
4530
31+ get_plot ()
4632#
4733# Systems of ODEs: damped oscillator example (simulation + phase portrait)
4834#
@@ -55,12 +41,13 @@ def oscillator_ode(x, t, m=1., b=1, k=1):
5541plt .figure ()
5642plt .clf ()
5743phase_plot (oscillator_ode , [- 1 , 1 , 10 ], [- 1 , 1 , 10 ], 0.15 )
44+
5845#plt.plot([0], [0], '.')
5946# a=gca; set(a,'FontSize',20); set(a,'DataAspectRatio',[1,1,1])
6047plt .xlabel ('$x_1$' )
6148plt .ylabel ('$x_2$' )
6249plt .title ('Damped oscillator, vector field' )
63-
50+ get_plot ()
6451# Generate a phase plot for the damped oscillator
6552plt .figure ()
6653plt .clf ()
@@ -79,7 +66,7 @@ def oscillator_ode(x, t, m=1., b=1, k=1):
7966plt .xlabel ('$x_1$' )
8067plt .ylabel ('$x_2$' )
8168plt .title ('Damped oscillator, vector field and stream lines' )
82-
69+ get_plot ()
8370#
8471# Stability definitions
8572#
@@ -115,6 +102,7 @@ def saddle_ode(x, t):
115102plt .xlabel ('$x_1$' )
116103plt .ylabel ('$x_2$' )
117104plt .title ('Asymptotically stable point' )
105+ get_plot ()
118106
119107# Saddle
120108plt .figure ()
@@ -140,6 +128,7 @@ def saddle_ode(x, t):
140128plt .xlabel ('$x_1$' )
141129plt .ylabel ('$x_2$' )
142130plt .title ('Saddle point' )
131+ get_plot ()
143132
144133# Stable isL
145134m = 1
@@ -161,6 +150,4 @@ def saddle_ode(x, t):
161150plt .xlabel ('$x_1$' )
162151plt .ylabel ('$x_2$' )
163152plt .title ('Undamped system\n Lyapunov stable, not asympt. stable' )
164-
165- if 'PYCONTROL_TEST_EXAMPLES' not in os .environ :
166- plt .show ()
153+ get_plot ()
0 commit comments