import numpy as np
import matplotlib.pyplot as plt
def is_stable(roots):
return all(abs(root) < 1 for root in roots)
def check_stability(K):
# Coeficientes del polinomio característico: z^2 + (K-1.5)z + 0.5
coeffs = [1, K-1.5, 0.5]
roots = np.roots(coeffs)
return is_stable(roots)
# Rango de K para verificar
K_values = np.linspace(-1, 4, 500)
stable_K = [K for K in K_values if check_stability(K)]
# Graficar resultados
plt.figure(figsize=(10, 6))
plt.plot(K_values, [check_stability(K) for K in K_values])
plt.xlabel('K')
plt.ylabel('Estable')
plt.title('Estabilidad del sistema en función de K')
plt.grid(True)
plt.axvline(x=0, color='r', linestyle='--')
plt.axvline(x=3, color='r', linestyle='--')
plt.show()
print(f"El sistema es estable para K en el rango aproximado: [{min(stable_K):.4f}, {max(stable_K):.4f}]")
Click Run or press shift + ENTER to run code