The code generates step response for underdamped second order system. The code can also be used to illustrate overlaying of plots. The code generates and displays graphically, the response for two values of time constant parameter. The code also illustrates creation of comet in a for loop.
import numpy as np
import matplotlib.pyplot as plt
The following programme runs on version 3.6.
Code generates a pair of lines and the line 2 is removed in a for loop which
simulates a comet effect
pts=100
t2 = np.linspace(0.0,5.0,pts)
t2=(t2/50)
tm=t2*(10**3)
nz=t2.size
tc=np.linspace(0.8,2.5,2)
nz=tc.size
for n in range (nz):
print(tc[n])
resp = 1 - np.exp(-tc[n]*tm*10**-3*50) * np.cos(2*np.pi*50*tm*10**-3)
for m in range(pts):
plt.xlim(0,100)
plt.ylim(0,2)
plt.xlabel('Time,in milliseconds',fontsize=12)
plt.ylabel('Respose',fontsize=12)
plt.title('Underdamped Second Order System Step Response',fontsize=14)
line1,=plt.plot(tm[0:m+1],resp[0:m+1],color='black',linewidth=0.2)
line2,=plt.plot(tm[m],resp[m],marker='o',color='red',markersize=5)
ax = plt.gca()
plt.pause(0.02)
ax.lines.remove(line2)
plt.grid('on')
plt.show()