44import os
55import matplotlib .pyplot as plt # MATLAB plotting functions
66from control .matlab import * # Load the controls systems library
7- from scipy import arange # function to create range of numbers
7+ from numpy import arange # function to create range of numbers
8+
9+ from control import reachable_form
810
911# Create several systems for testing
1012sys1 = tf ([1 ], [1 , 2 , 1 ])
1315# Generate step responses
1416(y1a , T1a ) = step (sys1 )
1517(y1b , T1b ) = step (sys1 , T = arange (0 , 10 , 0.1 ))
16- (y1c , T1c ) = step (sys1 , X0 = [1 , 0 ])
18+ # convert to reachable canonical SS to specify initial state
19+ sys1_ss = reachable_form (ss (sys1 ))[0 ]
20+ (y1c , T1c ) = step (sys1_ss , X0 = [1 , 0 ])
1721(y2a , T2a ) = step (sys2 , T = arange (0 , 10 , 0.1 ))
1822
19- plt .plot (T1a , y1a , T1b , y1b , T1c , y1c , T2a , y2a )
23+ plt .plot (T1a , y1a , label = '$g_1$ (default)' , linewidth = 5 )
24+ plt .plot (T1b , y1b , label = '$g_1$ (w/ spec. times)' , linestyle = '--' )
25+ plt .plot (T1c , y1c , label = '$g_1$ (w/ init cond.)' )
26+ plt .plot (T2a , y2a , label = '$g_2$ (w/ spec. times)' )
27+ plt .xlabel ('time' )
28+ plt .ylabel ('output' )
29+ plt .legend ()
2030
2131if 'PYCONTROL_TEST_EXAMPLES' not in os .environ :
22- plt .show ()
32+ plt .show ()
0 commit comments