109회 4교시 2번 문제¶

In [1]:
import sympy
import control as ct
import numpy as np
import matplotlib.pyplot as plt
In [2]:
A = np.asarray([
    [0, 1],
    [-5, -6]
])
B = np.asarray([
    0,1
])

C = np.asarray([0, 1])
In [3]:
system = ct.ss2tf(A, B, C, 0)
system
Out[3]:
$$\frac{s + 3.553 \times 10^{-15}}{s^2 + 6 s + 5}$$
In [4]:
answer_t = np.linspace(0, 7, 1000)
answer_fn = 0.25*np.exp(-answer_t) -0.25*np.exp(-5*answer_t)
t, y = ct.step_response(system)
plt.plot(t, y, color = 'blue')
plt.plot(answer_t, answer_fn, color = 'red')
plt.title('Step Response')
plt.xlabel('Time (seconds)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()
In [5]:
answer_t = np.linspace(0, 7, 1000)
answer_fn = 0.25*np.exp(-answer_t) -0.25*np.exp(-5*answer_t)
plt.plot(answer_t, answer_fn, color = 'red')
plt.grid(True)
plt.show()
In [6]:
t, y = ct.step_response(system)
plt.plot(t, y, color = 'blue')
plt.grid(True)
plt.show()