@@ -23,7 +23,7 @@ def invpend_ode(x, t, m=1., l=1., b=0.2, g=1):
23
23
# Set up the figure the way we want it to look
24
24
mpl .figure (); mpl .clf ();
25
25
mpl .axis ([- 2 * pi , 2 * pi , - 2.1 , 2.1 ]);
26
- mpl .title ('Inverted pendlum ' )
26
+ mpl .title ('Inverted pendulum ' )
27
27
28
28
# Outer trajectories
29
29
phase_plot (invpend_ode ,
@@ -35,9 +35,7 @@ def invpend_ode(x, t, m=1., l=1., b=0.2, g=1):
35
35
logtime = (3 , 0.7 ) )
36
36
37
37
# Separatrices
38
- mpl .hold (True );
39
38
phase_plot (invpend_ode , X0 = [[- 2.3056 , 2.1 ], [2.3056 , - 2.1 ]], T = 6 , lingrid = 0 )
40
- mpl .show ();
41
39
42
40
#
43
41
# Systems of ODEs: damped oscillator example (simulation + phase portrait)
@@ -49,9 +47,10 @@ def oscillator_ode(x, t, m=1., b=1, k=1):
49
47
# Generate a vector plot for the damped oscillator
50
48
mpl .figure (); mpl .clf ();
51
49
phase_plot (oscillator_ode , [- 1 , 1 , 10 ], [- 1 , 1 , 10 ], 0.15 );
52
- mpl . hold ( True ); mpl .plot ([0 ], [0 ], '.' );
50
+ # mpl.plot([0], [0], '.');
53
51
# a=gca; set(a,'FontSize',20); set(a,'DataAspectRatio',[1,1,1]);
54
- mpl .xlabel ('x1' ); mpl .ylabel ('x2' );
52
+ mpl .xlabel ('$x_1$' ); mpl .ylabel ('$x_2$' );
53
+ mpl .title ('Damped oscillator, vector field' )
55
54
56
55
# Generate a phase plot for the damped oscillator
57
56
mpl .figure (); mpl .clf ();
@@ -61,11 +60,10 @@ def oscillator_ode(x, t, m=1., b=1, k=1):
61
60
[- 1 , 1 ], [- 0.3 , 1 ], [0 , 1 ], [0.25 , 1 ], [0.5 , 1 ], [0.75 , 1 ], [1 , 1 ],
62
61
[1 , - 1 ], [0.3 , - 1 ], [0 , - 1 ], [- 0.25 , - 1 ], [- 0.5 , - 1 ], [- 0.75 , - 1 ], [- 1 , - 1 ]
63
62
], T = np .linspace (0 , 8 , 80 ), timepts = [0.25 , 0.8 , 2 , 3 ])
64
- mpl .hold ( True ); mpl . plot ([0 ], [0 ], 'k.' ); # 'MarkerSize', AM_data_markersize*3);
63
+ mpl .plot ([0 ], [0 ], 'k.' ); # 'MarkerSize', AM_data_markersize*3);
65
64
# set(gca,'DataAspectRatio',[1,1,1]);
66
- mpl .xlabel ('x1' ); mpl .ylabel ('x2' );
67
-
68
- mpl .show ()
65
+ mpl .xlabel ('$x_1$' ); mpl .ylabel ('$x_2$' );
66
+ mpl .title ('Damped oscillator, vector field and stream lines' )
69
67
70
68
#
71
69
# Stability definitions
@@ -88,9 +86,10 @@ def saddle_ode(x, t):
88
86
[- 1.3 ,- 1 ]
89
87
], T = np .linspace (0 , 10 , 100 ),
90
88
timepts = [0.3 , 1 , 2 , 3 ], parms = (m , b , k ));
91
- mpl .hold ( True ); mpl . plot ([0 ], [0 ], 'k.' ); # 'MarkerSize', AM_data_markersize*3);
89
+ mpl .plot ([0 ], [0 ], 'k.' ); # 'MarkerSize', AM_data_markersize*3);
92
90
# set(gca,'FontSize', 16);
93
- mpl .xlabel ('{\itx}_1' ); mpl .ylabel ('{\itx}_2' );
91
+ mpl .xlabel ('$x_1$' ); mpl .ylabel ('$x_2$' );
92
+ mpl .title ('Asymptotically stable point' )
94
93
95
94
# Saddle
96
95
mpl .figure (); mpl .clf ();
@@ -103,9 +102,10 @@ def saddle_ode(x, t):
103
102
[0.95 , 1 ], [0.9 , 1 ], [0.8 , 1 ], [0.6 , 1 ], [0.4 , 1 ], [0.2 , 1 ],
104
103
[- 0.5 , - 0.45 ], [- 0.45 , - 0.5 ], [0.5 , 0.45 ], [0.45 , 0.5 ],
105
104
[- 0.04 , 0.04 ], [0.04 , - 0.04 ] ], T = np .linspace (0 , 2 , 20 ));
106
- mpl .hold ( True ); mpl . plot ([0 ], [0 ], 'k.' ); # 'MarkerSize', AM_data_markersize*3);
105
+ mpl .plot ([0 ], [0 ], 'k.' ); # 'MarkerSize', AM_data_markersize*3);
107
106
# set(gca,'FontSize', 16);
108
- mpl .xlabel ('{\itx}_1' ); mpl .ylabel ('{\itx}_2' );
107
+ mpl .xlabel ('$x_1$' ); mpl .ylabel ('$x_2$' );
108
+ mpl .title ('Saddle point' )
109
109
110
110
# Stable isL
111
111
m = 1 ; b = 0 ; k = 1 ; # zero damping
@@ -115,8 +115,9 @@ def saddle_ode(x, t):
115
115
[pi / 6 , pi / 3 , pi / 2 , 2 * pi / 3 , 5 * pi / 6 , pi , 7 * pi / 6 , 4 * pi / 3 , 9 * pi / 6 , 5 * pi / 3 , 11 * pi / 6 , 2 * pi ],
116
116
X0 = [ [0.2 ,0 ], [0.4 ,0 ], [0.6 ,0 ], [0.8 ,0 ], [1 ,0 ], [1.2 ,0 ], [1.4 ,0 ] ],
117
117
T = np .linspace (0 , 20 , 200 ), parms = (m , b , k ));
118
- mpl .hold ( True ); mpl . plot ([0 ], [0 ], 'k.' ) # 'MarkerSize', AM_data_markersize*3);
118
+ mpl .plot ([0 ], [0 ], 'k.' ) # 'MarkerSize', AM_data_markersize*3);
119
119
# set(gca,'FontSize', 16);
120
- mpl .xlabel ('{\itx}_1' ); mpl .ylabel ('{\itx}_2' );
120
+ mpl .xlabel ('$x_1$' ); mpl .ylabel ('$x_2$' );
121
+ mpl .title ('Undamped system\n Lyapunov stable, not asympt. stable' )
121
122
122
123
mpl .show ()
0 commit comments