In [2]:
import imp
import matplotlib.pyplot as plt
import numpy as np
ctrl = imp.load_package('control', r'C:\Users\gonmo\PycharmProjects\python-control-GDM\control')
% matplotlib inline

Simple example that is not OK


In [3]:
sys1 = ctrl.tf([1, 1], [1, 10, 1])
print(sys1)


    s + 1
--------------
s^2 + 10 s + 1


In [4]:
r, k = ctrl.rlocus(sys1)
plt.show()
r, k = ctrl.rlocus(sys1, grid=True)


However, when I plot the grid the figure looks not so good. The problem are the axis limits. If I redefine the y-axis limits the problem is solved.


In [5]:
r, k = ctrl.rlocus(sys1, grid=True, ylim=[-10, 10])


Excercises from Franklyn

I gonna plot several root locus in order to test the quality of the plots.


In [5]:
sys1 = ctrl.tf([1,2],np.poly([0,-1,-5,-10]))
r1,k1=ctrl.rlocus(sys1)
plt.show()
r1,k1=ctrl.rlocus(sys1, grid = True)



In [6]:
sys2 = ctrl.tf([1],np.poly([0,-1,-5,-10]))
r2,k2=ctrl.rlocus(sys2)
plt.show()
r2,k2=ctrl.rlocus(sys2, grid = True)



In [7]:
sys3 = ctrl.tf(np.poly([-2,-6]),np.poly([0,-1,-5,-10]))
r3,k3=ctrl.rlocus(sys3)
plt.show()
r3,k3=ctrl.rlocus(sys3, grid = True)



In [8]:
sys4 = ctrl.tf(np.poly([-2,-4]),np.poly([0,-1,-5,-10]))
r4,k4=ctrl.rlocus(sys4)
plt.show()
r4,k4=ctrl.rlocus(sys4, grid = True)



In [9]:
sys5 = ctrl.tf([1],np.poly(np.roots([1,3,10])))
r5,k5=ctrl.rlocus(sys5)
plt.show()
r5,k5=ctrl.rlocus(sys5, grid = True)


Here the plot show problems. This is beacuase the axis limits are not similar. I can resolve his problem redefinig the x limits axis.


In [10]:
r5,k5=ctrl.rlocus(sys5, grid = True, xlim=[-5,0.1])



In [11]:
sys6 = ctrl.tf([1],np.poly(np.hstack((np.roots([1,3,10]),[0]))))
r6,k6=ctrl.rlocus(sys6)
plt.show()
r6,k6=ctrl.rlocus(sys6, grid = True)



In [12]:
sys7 = ctrl.tf(np.poly(np.roots([1,2,8])),np.poly(np.hstack((np.roots([1,2,10]),[0]))))
r7,k7=ctrl.rlocus(sys7)
plt.show()
r7,k7=ctrl.rlocus(sys7, grid = True)



In [13]:
sys8 = ctrl.tf([1,0,1],[1,0,4,0])
r8,k8=ctrl.rlocus(sys8)
plt.show()
r8,k8=ctrl.rlocus(sys8, grid = True)



In [14]:
sys9 = ctrl.tf(np.poly(np.roots([1,2,12])),np.poly(np.hstack((np.roots([1,2,10]),[0]))))
r9,k9=ctrl.rlocus(sys9)
plt.show()
r9,k9=ctrl.rlocus(sys9, grid = True)



In [15]:
sys10 = ctrl.tf([1,0,4],[1,0,1,0])
r10,k10=ctrl.rlocus(sys10)
plt.show()
r10,k10=ctrl.rlocus(sys10, grid = True)


Simple examples that can cause problems


In [16]:
sys11 = ctrl.tf([1, 0, -4], [1, 0, -1])
r11,k11=ctrl.rlocus(sys11)
plt.show()
r11,k11=ctrl.rlocus(sys11, grid = True)



In [17]:
sys12 = ctrl.tf([1, 1], [1, 0])
r12,k12=ctrl.rlocus(sys12)
plt.show()
r12,k12=ctrl.rlocus(sys12, grid = True)