ラグランジュの未定乗数法
100日後に数学ができるようになる僕。
制約条件と等高線のグラフ
import matplotlib.pyplot as plt import numpy as np x = np.arange(-1, 1, 0.01) y = np.arange(-1, 1, 0.01) X, Y = np.meshgrid(x, y) Z = 2 * X ** 2 + 3 * Y ** 2 plt.contourf(X, Y, Z, levels=20, cmap='gray') plt.colorbar() plt.plot(x, 1 - x, color='red', label='x + y = 1') plt.legend() plt.annotate('Local minimum', xy=(3/5, 2/5), xytext=(-1/4, 1/4), color='red', arrowprops=dict(arrowstyle='->', color='red', connectionstyle='angle3, angleA=0, angleB=-90')) plt.axis([-1, 1, -1, 1]) plt.show()