#group 1: Question 1(b)
# A control system for positioning the head of a laser printer has the closed loop transfer function:
# !pip install control 

import matplotlib.pyplot as plt
import control

a=10  #Value for a
b=50  #value for b
sys1 = control.tf(20*b,[1,20+a,b+20*a,20*b])
print('3rd order system transfer function T1(s)=',sys1)
sys2=control.tf(b,[1,a,b])
print('2nd order system transfer funtion T2(s)',sys2)

value = sys1.pole()
list_of_poles = [pole.round(2) for pole in value]
print('poles',list_of_poles)

y1=control.step_response(sys1)
y2=control.step_response(sys2)
plt.plot(y1[0],y1[1],'r--', label='3rd order actual system')
plt.plot(y2[0],y2[1],'g', label='2nd order approximation system')
plt.legend()
plt.grid()
plt.xlabel('time (s)')
plt.ylabel('step response y(t)')
plt.title('step response comparison of 3rd and 2nd order system')
plt.show()

[((10, 7, 10, 44), 'control.tf', 'control.tf', ({(10, 18, 10, 22): '20 * b', (10, 23, 10, 43): '[1, 20 + a, b + 20 * a, 20 * b]'}, {}), '(20 * b, [1, 20 + a, b + 20 * a, 20 * b])', False, 'import control\n'), ((12, 5, 12, 26), 'control.tf', 'control.tf', ({(12, 16, 12, 17): 'b', (12, 18, 12, 25): '[1, a, b]'}, {}), '(b, [1, a, b])', False, 'import control\n'), ((19, 3, 19, 30), 'control.step_response', 'control.step_response', ({(19, 25, 19, 29): 'sys1'}, {}), '(sys1)', False, 'import control\n'), ((20, 3, 20, 30), 'control.step_response', 'control.step_response', ({(20, 25, 20, 29): 'sys2'}, {}), '(sys2)', False, 'import control\n'), ((21, 0, 21, 60), 'matplotlib.pyplot.plot', 'plt.plot', (), '', True, 'import matplotlib.pyplot as plt\n'), ((22, 0, 22, 65), 'matplotlib.pyplot.plot', 'plt.plot', (), '', True, 'import matplotlib.pyplot as plt\n'), ((23, 0, 23, 12), 'matplotlib.pyplot.legend', 'plt.legend', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n'), ((24, 0, 24, 10), 'matplotlib.pyplot.grid', 'plt.grid', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n'), ((25, 0, 25, 22), 'matplotlib.pyplot.xlabel', 'plt.xlabel', ({(25, 11, 25, 21): '"""time (s)"""'}, {}), "('time (s)')", True, 'import matplotlib.pyplot as plt\n'), ((26, 0, 26, 32), 'matplotlib.pyplot.ylabel', 'plt.ylabel', ({(26, 11, 26, 31): '"""step response y(t)"""'}, {}), "('step response y(t)')", True, 'import matplotlib.pyplot as plt\n'), ((27, 0, 27, 65), 'matplotlib.pyplot.title', 'plt.title', ({(27, 10, 27, 64): '"""step response comparison of 3rd and 2nd order system"""'}, {}), "('step response comparison of 3rd and 2nd order system')", True, 'import matplotlib.pyplot as plt\n'), ((28, 0, 28, 10), 'matplotlib.pyplot.show', 'plt.show', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n')]