Untitled

 avatar
unknown
plain_text
18 days ago
1.7 kB
2
Indexable
import numpy as np
import matplotlib.pyplot as plt

# Define the range of quantities
Q = np.linspace(0, 100, 100)

# Define the demand curve (MB)
MB = 100 - 0.5 * Q  # Linear downward-sloping demand

# Private Marginal Cost (PMC)
PMC = 20 + 0.3 * Q  # Linear upward-sloping supply

# Social Marginal Cost (SMC) = PMC + External Cost
SMC = PMC + 15  # Shifting PMC upwards

# Finding intersections
def find_intersection(Q, curve1, curve2):
    idx = np.argmin(np.abs(curve1 - curve2))
    return Q[idx], curve1[idx]

Q_private, P_private = find_intersection(Q, MB, PMC)
Q_social, P_social = find_intersection(Q, MB, SMC)

# Plot setup
plt.figure(figsize=(8,6))

# Plot curves
plt.plot(Q, MB, label="Demand (MB)", color="blue")
plt.plot(Q, PMC, label="Private Marginal Cost (PMC)", color="green")
plt.plot(Q, SMC, label="Social Marginal Cost (SMC)", color="red")

# Marking equilibria
plt.scatter(Q_private, P_private, color='black', zorder=3)
plt.scatter(Q_social, P_social, color='black', zorder=3)

# Welfare loss area (DWL)
plt.fill_between(Q[(Q >= Q_social) & (Q <= Q_private)], 
                 SMC[(Q >= Q_social) & (Q <= Q_private)], 
                 PMC[(Q >= Q_social) & (Q <= Q_private)], 
                 color='red', alpha=0.3, label="Welfare Loss (DWL)")

# Labels and annotations
plt.axvline(Q_private, linestyle="dotted", color="black", alpha=0.7)
plt.axvline(Q_social, linestyle="dotted", color="black", alpha=0.7)

plt.text(Q_private+2, P_private-5, r"$Q_{market}$", fontsize=12)
plt.text(Q_social-7, P_social-5, r"$Q_{social}$", fontsize=12)

plt.xlabel("Quantity of Vapes (Q)")
plt.ylabel("Price (P)")
plt.title("Negative Externality of Production")

plt.legend()
plt.show()
Editor is loading...
Leave a Comment