import numpy as np
import matplotlib.pyplot as plt

# Función de beneficios: B(q) = -2*q**2 + 40*q - 50
def beneficio(q):
    return -2*q**2 + 40*q - 50

# Derivada
def derivada(q):
    return -4*q + 40

# Valores de q
q_vals = np.linspace(0, 15, 100)
B_vals = beneficio(q_vals)
dB_vals = derivada(q_vals)

plt.figure(figsize=(10,6))
plt.plot(q_vals, B_vals, label="Beneficio")
plt.plot(q_vals, dB_vals, label="Derivada (marginal)")
plt.axhline(0, color='gray', linestyle='--')
plt.xlabel("Cantidad producida (q)")
plt.ylabel("Beneficio / Derivada")
plt.title("Beneficio y derivada marginal")
plt.legend()
plt.grid(True)
plt.show()
