Untitled

 avatar
unknown
plain_text
9 months ago
2.1 kB
10
Indexable
import numpy as np
import matplotlib.pyplot as plt

# Example numeric values (replace with your j,k,m,n,c,d if you want)
j,k = 2, 6       # A's initial bundle
m,n = 6, 2       # B's initial bundle
c,d = 1, 1       # Cobb-Douglas exponents (c>0,d>0)

Xtot = j + m
Ytot = k + n

fig, ax = plt.subplots(figsize=(6,6))
ax.set_xlim(0, Xtot)
ax.set_ylim(0, Ytot)

# Box and labels
ax.plot([0, Xtot, Xtot, 0, 0], [0, 0, Ytot, Ytot, 0], color='black')
ax.set_xlabel("Good x (A's axis, origin at lower-left)")
ax.set_ylabel("Good y (A's axis, origin at lower-left)")
ax.set_title("Edgeworth box (A origin lower-left, B origin upper-right)")

# Endowment point (A's coordinates)
ax.scatter([j], [k], color='red', s=60)
ax.text(j+0.1, k+0.1, "Endowment (A: j,k)", color='red')

# Also mark B's bundle measured from A's origin for clarity
B_x_from_A = Xtot - m  # alternative representation if needed
B_y_from_A = Ytot - n
ax.scatter([B_x_from_A], [B_y_from_A], color='blue', s=60)
ax.text(B_x_from_A+0.1, B_y_from_A+0.1, "B's point (from A origin)", color='blue')

# Draw a few indifference curves for A through (j,k)
# Cobb-Douglas: U = x^c y^d => level U0 => y = (U0^(1/d)) * x^{-c/d}
U_A = (j**c) * (k**d)
xs = np.linspace(1e-3, Xtot-1e-3, 400)
ys_A = (U_A / (xs**c))**(1.0/d)
ax.plot(xs, ys_A, color='red', linestyle='--', alpha=0.7)
ax.text(xs[-1]*0.7, ys_A[int(0.7*len(xs))], "A indiff. curve", color='red')

# Draw B's indifference curve passing through its allocation.
# B's consumption measured from B's origin: (m,n). Its indifference curve in A coords:
# For Cobb-Douglas, level U_B = m^c n^d.
U_B = (m**c) * (n**d)
# For B we want locus of points (x_A, y_A) that give B the same utility:
# B's consumption (in terms of A's coordinates) is (Xtot-x_A, Ytot-y_A).
# So we solve (Xtot-x)^{c} (Ytot-y)^{d} = U_B  => y = Ytot - (U_B / (Xtot-x)^c)^{1/d}
xs_B = np.linspace(1e-3, Xtot-1e-3, 400)
ys_B = Ytot - (U_B / ((Xtot - xs_B)**c))**(1.0/d)
ax.plot(xs_B, ys_B, color='blue', linestyle='--', alpha=0.7)
ax.text(xs_B[int(len(xs_B)*0.1)], ys_B[int(len(xs_B)*0.1)]-0.7, "B indiff. curve", color='blue')

ax.set_aspect('equal', adjustable='box')
plt.show()
Editor is loading...
Leave a Comment