<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Problem 1
(a)
Choosing sampling time and calculating the discrete-time poles. The time constant of the first-order response is $T=120$s. Rise time is $T_r = 2.2T = 264$s. Rule-of-thumb is 4-10 sampling periods per rise time.
Step1:  (b)
Backward difference approximation of given continuous-time controller
Step2:  Problem 2
Calculate the pulse transfer function from the disturbance d to the output y
Step3:  Problem 3
Find the diagonal form of the system in problem 2, but without the time delay
Step4:  Set up the state-space model. Make sure it is correct.
Step5:  (c) Finding the feedback gain
Step6:  Check with matlab
<ASSISTANT_TASK:>
Python Code:
T = 120
Tr = 2.2*120
print [Tr/10, Tr/4]
h = 40.0
pc = -1.0/120
pd = np.exp(pc*h)
print pd
Explanation: Problem 1
(a)
Choosing sampling time and calculating the discrete-time poles. The time constant of the first-order response is $T=120$s. Rise time is $T_r = 2.2T = 264$s. Rule-of-thumb is 4-10 sampling periods per rise time.
End of explanation
s,z = sy.symbols('s, z')
h = sy.symbols('h', positive=True)
F = (16*s+1)/(100*s+1)
H = sy.simplify(F.subs(s, (z-1)/(z*h)))
print H
p1,p2,p3,p4 = sy.symbols('p1, p2, p3, p4') 
sy.expand((z-0.7+sy.I*0.1)*(z-0.7-sy.I*0.1))
Explanation: (b)
Backward difference approximation of given continuous-time controller
End of explanation
B = 0.6*z + 0.5
A = z*(z**2 - 1.9*z + 0.9)
S, R = sy.symbols('S, R')
H_dy = (B/A) / (1 + (B/A)*(S/R))
sy.simplify(H_dy)
H_dys = sy.simplify(H_dy)
s=sy.latex(H_dys)
print s
Explanation: Problem 2
Calculate the pulse transfer function from the disturbance d to the output y
End of explanation
H = sy.simplify(z*B/A)
sy.apart(H)
Explanation: Problem 3
Find the diagonal form of the system in problem 2, but without the time delay
End of explanation
Phi = sy.Matrix([[0.9, 0], [0, 1]])
Gamma = sy.Matrix([[1],[1]])
Cm = sy.Matrix([[-10.4, 11.0]])
Htest = Cm*(z*sy.eye(2)-Phi).inv()*Gamma
Htest
                
H
Explanation: Set up the state-space model. Make sure it is correct.
End of explanation
l1, l2 = sy.symbols('l1, l2')
L = sy.Matrix([[l1, l2]])
sy.factor((z*sy.eye(2) - (Phi - Gamma*L)).det(), z)
sy.simplify(sy.expand((z-0.6+sy.I*0.3)*(z-0.6-sy.I*0.3)))
Explanation: (c) Finding the feedback gain
End of explanation
%load_ext pymatbridge
%%matlab  --size 800,400
%Mean arteriar pressure, automatic anasthesia model
% Plant
G = tf([1], [120 1 0]);
a = 1/100;
b = 1/160;
F0 = zpk([-b], [-a], a/b);
K = 1e-2;
F = K*F0;
Gc = feedback(G*F, 1);
step(Gc, 1000)
%%matlab --size 800,400 -o L,y,t
h = 40.0;
Phi = [0.9 0; 0 1]; 
Gamma = [1;1]; 
C = [-10.4  11.0]; 
D = 0;
sys = ss(Phi, Gamma, C, D, h);
L = place(Phi, Gamma, [0.6+i*0.3 0.6-i*0.3]);
sys_cl = ss(Phi-Gamma*L, Gamma, C, D, h);
[y, t] = step(sys_cl);
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure()
plt.plot(t, y)
Explanation: Check with matlab
End of explanation
<END_TASK>