@@ -23,7 +23,7 @@ def invpend_ode(x, t, m=1., l=1., b=0.2, g=1):
2323# Set up the figure the way we want it to look
2424mpl .figure (); mpl .clf ();
2525mpl .axis ([- 2 * pi , 2 * pi , - 2.1 , 2.1 ]);
26- mpl .title ('Inverted pendlum ' )
26+ mpl .title ('Inverted pendulum ' )
2727
2828# Outer trajectories
2929phase_plot (invpend_ode ,
@@ -35,9 +35,7 @@ def invpend_ode(x, t, m=1., l=1., b=0.2, g=1):
3535 logtime = (3 , 0.7 ) )
3636
3737# Separatrices
38- mpl .hold (True );
3938phase_plot (invpend_ode , X0 = [[- 2.3056 , 2.1 ], [2.3056 , - 2.1 ]], T = 6 , lingrid = 0 )
40- mpl .show ();
4139
4240#
4341# Systems of ODEs: damped oscillator example (simulation + phase portrait)
@@ -49,9 +47,10 @@ def oscillator_ode(x, t, m=1., b=1, k=1):
4947# Generate a vector plot for the damped oscillator
5048mpl .figure (); mpl .clf ();
5149phase_plot (oscillator_ode , [- 1 , 1 , 10 ], [- 1 , 1 , 10 ], 0.15 );
52- mpl . hold ( True ); mpl .plot ([0 ], [0 ], '.' );
50+ # mpl.plot([0], [0], '.');
5351# 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' )
5554
5655# Generate a phase plot for the damped oscillator
5756mpl .figure (); mpl .clf ();
@@ -61,11 +60,10 @@ def oscillator_ode(x, t, m=1., b=1, k=1):
6160 [- 1 , 1 ], [- 0.3 , 1 ], [0 , 1 ], [0.25 , 1 ], [0.5 , 1 ], [0.75 , 1 ], [1 , 1 ],
6261 [1 , - 1 ], [0.3 , - 1 ], [0 , - 1 ], [- 0.25 , - 1 ], [- 0.5 , - 1 ], [- 0.75 , - 1 ], [- 1 , - 1 ]
6362 ], 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);
6564# 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' )
6967
7068#
7169# Stability definitions
@@ -88,9 +86,10 @@ def saddle_ode(x, t):
8886 [- 1.3 ,- 1 ]
8987 ], T = np .linspace (0 , 10 , 100 ),
9088 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);
9290# 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' )
9493
9594# Saddle
9695mpl .figure (); mpl .clf ();
@@ -103,9 +102,10 @@ def saddle_ode(x, t):
103102 [0.95 , 1 ], [0.9 , 1 ], [0.8 , 1 ], [0.6 , 1 ], [0.4 , 1 ], [0.2 , 1 ],
104103 [- 0.5 , - 0.45 ], [- 0.45 , - 0.5 ], [0.5 , 0.45 ], [0.45 , 0.5 ],
105104 [- 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);
107106# 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' )
109109
110110# Stable isL
111111m = 1 ; b = 0 ; k = 1 ; # zero damping
@@ -115,8 +115,9 @@ def saddle_ode(x, t):
115115 [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 ],
116116 X0 = [ [0.2 ,0 ], [0.4 ,0 ], [0.6 ,0 ], [0.8 ,0 ], [1 ,0 ], [1.2 ,0 ], [1.4 ,0 ] ],
117117 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);
119119# 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' )
121122
122123mpl .show ()
0 commit comments