import control as ctrl
import matplotlib.pyplot as plt
import numpy as np
# Define a transfer function (example: G(s) = 1 / (s^2 + 2s + 1))
numerator = [1]
denominator = [1, 3, 2, 1]
system = ctrl.TransferFunction(numerator, denominator)
system_cl = ctrl.feedback(system, 1)
# Create a Nyquist plot
ctrl.nyquist_plot(system_cl, omega=np.logspace(-2, 2, 1000), plot=True)
# Customize the plot (optional)
plt.title('Nyquist Plot')
plt.xlabel('Real')
plt.ylabel('Imaginary')
plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)
plt.grid(True, which='both', linestyle='--', linewidth=0.5)
plt.show()
numerator = [0.1]
denominator = [1, 3, 2, 1]
system = ctrl.TransferFunction(numerator, denominator)
system_cl = ctrl.feedback(system, 1)
# Create a Nyquist plot
ctrl.nyquist_plot(system_cl, omega=np.logspace(-2, 2, 1000), plot=True)
# Customize the plot (optional)
plt.title('Nyquist Plot')
plt.xlabel('Real')
plt.ylabel('Imaginary')
plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)
plt.xlim(-1, 1)
# plt.ylim(-0.001, 0.001)
plt.grid(True, which='both', linestyle='--', linewidth=0.5)
plt.show()
system