Skip to content

Commit d7f166c

Browse files
authored
edited to suite Better Control Systems Wiki
1 parent 03183d1 commit d7f166c

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

examples/phaseplots.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
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
4429
phase_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):
5541
plt.figure()
5642
plt.clf()
5743
phase_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])
6047
plt.xlabel('$x_1$')
6148
plt.ylabel('$x_2$')
6249
plt.title('Damped oscillator, vector field')
63-
50+
get_plot()
6451
# Generate a phase plot for the damped oscillator
6552
plt.figure()
6653
plt.clf()
@@ -79,7 +66,7 @@ def oscillator_ode(x, t, m=1., b=1, k=1):
7966
plt.xlabel('$x_1$')
8067
plt.ylabel('$x_2$')
8168
plt.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):
115102
plt.xlabel('$x_1$')
116103
plt.ylabel('$x_2$')
117104
plt.title('Asymptotically stable point')
105+
get_plot()
118106

119107
# Saddle
120108
plt.figure()
@@ -140,6 +128,7 @@ def saddle_ode(x, t):
140128
plt.xlabel('$x_1$')
141129
plt.ylabel('$x_2$')
142130
plt.title('Saddle point')
131+
get_plot()
143132

144133
# Stable isL
145134
m = 1
@@ -161,6 +150,4 @@ def saddle_ode(x, t):
161150
plt.xlabel('$x_1$')
162151
plt.ylabel('$x_2$')
163152
plt.title('Undamped system\nLyapunov stable, not asympt. stable')
164-
165-
if 'PYCONTROL_TEST_EXAMPLES' not in os.environ:
166-
plt.show()
153+
get_plot()

0 commit comments

Comments
 (0)