無差別曲線を可視化する
次の効用関数と制約が与えられています。
\(U(c, m)=c^{0.7}m^{0.3}\)
\(c+m=2\)
これを使って無差別曲線を可視化してください。
np と plt はすでに読み込まれています。
この演習はコースの一部です
Pythonで学ぶOptimization入門
演習の手順
- 制約を
mとして定義し、cとmの組み合わせを生成します。 - 効用関数を定義して
Fに代入します。 - 等高線と制約をプロットします。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
c = np.linspace(1, 2, 10)
# Define the constraint and generate combinations
m = ____
C, M = ____(c, m)
# Define the utility function
F = ____
plt.figure(figsize=(8, 6))
# Plot the controls and constraints
contours = ____(C, M, F, levels=[0.9, 1.00, 1.085, 1.2])
____(contours)
____(c, m, color='red')
plt.title('Indifference Curve with Constraint Line')
plt.xlabel('c')
plt.ylabel('m')
plt.grid(True)
plt.show()