可视化无差异曲线
已为您提供如下效用函数和约束条件。
\(U(c, m)=c^{0.7}m^{0.3}\)
\(c+m=2\)
请据此可视化无差异曲线。
np 和 plt 已为您加载完成。
本练习是课程的一部分
Python 优化入门
练习说明
- 将约束写成关于
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()