forked from python-control/python-control
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphaseplot_test.py
More file actions
82 lines (64 loc) · 2.83 KB
/
phaseplot_test.py
File metadata and controls
82 lines (64 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""phaseplot_test.py - test phase plot functions
RMM, 17 24 2011 (based on TestMatlab from v0.4c)
This test suite calls various phaseplot functions. Since the plots
themselves can't be verified, this is mainly here to make sure all
of the function arguments are handled correctly. If you run an
individual test by itself and then type show(), it should pop open
the figures so that you can check them visually.
"""
import matplotlib.pyplot as mpl
import numpy as np
from numpy import pi
import pytest
from control import phase_plot
@pytest.mark.usefixtures("mplcleanup")
class TestPhasePlot:
def testInvPendNoSims(self):
phase_plot(self.invpend_ode, (-6,6,10), (-6,6,10));
def testInvPendSims(self):
phase_plot(self.invpend_ode, (-6,6,10), (-6,6,10),
X0 = ([1,1], [-1,1]))
def testInvPendTimePoints(self):
phase_plot(self.invpend_ode, (-6,6,10), (-6,6,10),
X0 = ([1,1], [-1,1]), T=np.linspace(0,5,100))
def testInvPendLogtime(self):
phase_plot(self.invpend_ode, X0 =
[ [-2*pi, 1.6], [-2*pi, 0.5], [-1.8, 2.1],
[-1, 2.1], [4.2, 2.1], [5, 2.1],
[2*pi, -1.6], [2*pi, -0.5], [1.8, -2.1],
[1, -2.1], [-4.2, -2.1], [-5, -2.1] ],
T = np.linspace(0, 40, 200),
logtime=(3, 0.7),
verbose=False)
def testInvPendAuto(self):
phase_plot(self.invpend_ode, lingrid = 0, X0=
[[-2.3056, 2.1], [2.3056, -2.1]], T=6, verbose=False)
def testOscillatorParams(self):
# default values
m = 1
b = 1
k = 1
phase_plot(self.oscillator_ode, timepts = [0.3, 1, 2, 3], X0 =
[[-1,1], [-0.3,1], [0,1], [0.25,1], [0.5,1], [0.7,1],
[1,1], [1.3,1], [1,-1], [0.3,-1], [0,-1], [-0.25,-1],
[-0.5,-1], [-0.7,-1], [-1,-1], [-1.3,-1]],
T = np.linspace(0, 10, 100), parms = (m, b, k))
def testNoArrows(self):
# Test case from aramakrl that was generating a type error
# System does not have arrows
# cf. issue #96,
# https://github.com/python-control/python-control/issues/96
def d1(x1x2,t):
x1,x2 = x1x2
return np.array([x2, x2 - 2*x1])
x1x2_0 = np.array([[-1.,1.], [-1.,-1.], [1.,1.], [1.,-1.],
[-1.,0.],[1.,0.],[0.,-1.],[0.,1.],[0.,0.]])
mpl.figure(1)
phase_plot(d1,X0=x1x2_0,T=100)
# Sample dynamical systems - inverted pendulum
def invpend_ode(self, x, t, m=1., l=1., b=0, g=9.8):
import numpy as np
return (x[1], -b/m*x[1] + (g*l/m) * np.sin(x[0]))
# Sample dynamical systems - oscillator
def oscillator_ode(self, x, t, m=1., b=1, k=1, extra=None):
return (x[1], -k/m*x[0] - b/m*x[1])