πŸ”¬ Tutorial problems lambda

Contents

πŸ”¬ Tutorial problems lambda#

Hide code cell content
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from myst_nb import glue

f = lambda x: (x[0])**3 - (x[1])**3
lb,ub = -1.5,1.5

x = y = np.linspace(lb,ub, 100)
X, Y = np.meshgrid(x, y)
zs = np.array([f((x,y)) for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)

a,b=1,1
# (x/a)^2 + (y/b)^2 = 1
theta = np.linspace(0, 2 * np.pi, 100)
X1 = a*np.cos(theta)
Y1 = b*np.sin(theta)
zs = np.array([f((x,y)) for x,y in zip(np.ravel(X1), np.ravel(Y1))])
Z1 = zs.reshape(X1.shape)

fig = plt.figure(dpi=160)
ax2 = fig.add_subplot(111)
ax2.set_aspect('equal', 'box')
ax2.contour(X, Y, Z, 50,
            cmap=cm.jet)
ax2.plot(X1, Y1)
plt.setp(ax2, xticks=[],yticks=[])
glue("pic1", fig, display=False)

fig = plt.figure(dpi=160)
ax3 = fig.add_subplot(111, projection='3d')
ax3.plot_wireframe(X, Y, Z,
            rstride=2,
            cstride=2,
            alpha=0.7,
            linewidth=0.25)
f0 = f(np.zeros((2)))+0.1
ax3.plot(X1, Y1, Z1, c='red')
plt.setp(ax3,xticks=[],yticks=[],zticks=[])
ax3.view_init(elev=18, azim=154)
glue("pic2", fig, display=False)


f = lambda x: x[0]**3/3 - 3*x[1]**2 + 5*x[0] - 6*x[0]*x[1]
x = y = np.linspace(-10.0, 10.0, 100)
X, Y = np.meshgrid(x, y)
zs = np.array([f((x,y)) for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
a,b=4,8
# (x/a)^2 + (y/b)^2 = 1
theta = np.linspace(0, 2 * np.pi, 100)
X1 = a*np.cos(theta)
Y1 = b*np.sin(theta)
zs = np.array([f((x,y)) for x,y in zip(np.ravel(X1), np.ravel(Y1))])
Z1 = zs.reshape(X1.shape)

fig = plt.figure(dpi=160)
ax2 = fig.add_subplot(111)
ax2.set_aspect('equal', 'box')
ax2.contour(X, Y, Z, 50,
            cmap=cm.jet)
ax2.plot(X1, Y1)
plt.setp(ax2, xticks=[],yticks=[])
glue("pic3", fig, display=False)

fig = plt.figure(dpi=160)
ax3 = fig.add_subplot(111, projection='3d')
ax3.plot_wireframe(X, Y, Z, 
            rstride=2, 
            cstride=2,
            alpha=0.7,
            linewidth=0.25)
f0 = f(np.zeros((2)))+0.1
ax3.plot(X1, Y1, Z1, c='red')
plt.setp(ax3,xticks=[],yticks=[],zticks=[])
ax3.view_init(elev=18, azim=154)
glue("pic4", fig, display=False)
_images/9207bfd219ca984986a6a92fcc0bd03860754af19875606a5080bad763c06d77.png _images/0e28951d63b7f95b342f37426df0f85f6dbaddc37e9eb5b016cbc259821c147a.png _images/9c6f524d6b0a7902469c59abf1311c8d582f92ee14c84d8543831366fabc4433.png _images/d1641a091417d258e07db925184992333893dee5474522b444ef7de3ab6b398e.png

Ξ».1#

Solve the following constrained maximization problem using the Karush-Kuhn-Tucker method. Verify that the found stationary/critical points satisfy the second order conditions.

f(x,y)=x3βˆ’y3β†’maxx,ysubject tox2+y2≀1,x,y∈R

Standard KKT method should work for this problem.

_images/9207bfd219ca984986a6a92fcc0bd03860754af19875606a5080bad763c06d77.png

Fig. 100 Level curves of the criterion function and constraint curve.#

_images/0e28951d63b7f95b342f37426df0f85f6dbaddc37e9eb5b016cbc259821c147a.png

Fig. 101 3D plot of the criterion surface with the constraint curve projected to it.#

⏱

Ξ».2#

Solve the following constrained maximization problem using the Karush-Kuhn-Tucker method. Verify that the found stationary/critical points satisfy the second order conditions.

f(x,y)=βˆ’x2β†’maxx,ysubject tox2βˆ’y2βˆ’2xyβ‰₯2,x,y∈R

Standard KKT method should work for this problem.

⏱

Ξ».3#

Roy’s identity

Consider the choice problem of a consumer endowed with strictly concave and differentiable utility function u:R++N→R where R++N denotes the set of vector in RN with strictly positive elements.

The budget constraint is given by pβ‹…x≀m where p∈R++N are prices and m>0 is income.

Then the demand function x⋆(p,m) and the indirect utility function v(p,m) (value function of the problem) satisfy the equations

xi⋆(p,m)=βˆ’βˆ‚vβˆ‚pi(p,m)/βˆ‚vβˆ‚m(p,m),βˆ€i∈{1,…,N}
  1. Prove the statement

  2. Verify the statement by direct calculation (i.e. by expressing the indirect utility and plugging its partials into the identity) using the following specification of utility

u(x)=∏i=1Nxiαi,αi>0

Envelope theorem should be useful here.

⏱