In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
Instructions: Complete the instructions in this notebook. You may work together with other students in the class and you may take full advantage of any internet resources available. You must provide thorough comments in your code so that it's clear that you understand what your code is doing and so that your code is readable.
Submit the assignment by saving your notebook as an html file (File -> Download as -> HTML) and uploading it to the appropriate Dropbox folder on EEE.
The Cobb-Douglas production function can be written in per worker terms: \begin{align} y & = A k^{\alpha}, \end{align} where $y$ denotes output per worker, $k$ denotes capital per worker, and $A$ denotes total factor productivity or technology Do the following:
Suppose that $A$ = 1 and $\alpha = 0.35$. Construct a well-labeled plot of the Cobb-Douglas production function with $k$ on the horizontal axis and $y$ on the vertical axis for $k$ between 0 and 10. Your plot must have a title and axis labels.
Plot the Cobb-Douglas production for $A = 0.75 , 1,$ and $1.25$ with $\alpha = 0.35$ and $k$ ranging from 0 to 10. Each line should have a different style (e.g., solid, dashed, dot-dashed). Your plot must have a title and axis labels. the plot should also contain a legend that clearly indicates which line is associated with which value of $A$ and does not cover the plotted lines.
In [3]:
# Question 1.1
A = 1
alpha = 0.35
k = np.arange(0,10,0.001)
y = A*k**alpha
plt.plot(k,y,lw=3,alpha = 0.65)
plt.xlabel('capital')
plt.ylabel('output')
plt.title('Cobb-Douglas production function')
plt.grid()
In [4]:
# Question 1.2
def cobbDouglas(A,k,alpha):
return A*k**alpha
A = 1
alpha = 0.35
k = np.arange(0,10,0.001)
for A in [0.75,1,1.25]:
plt.plot(k,cobbDouglas(A,k,alpha),lw=3,alpha = 0.65,label='A='+str(A))
plt.xlabel('capital')
plt.ylabel('output')
plt.title('Cobb-Douglas production function')
plt.legend(loc='lower right')
plt.grid()
The cardioid is a shape described by the parametric equations:
\begin{align} x & = a(2\cos \theta - \cos 2\theta), \\ y & = a(2\sin \theta - \sin 2\theta). \end{align}
Construct a well-labeled graph of the cardiod for $a=1$ and $\theta$ in $[0,2\pi]$. Each line should have a different style (e.g., solid, dashed, dot-dashed). Your plot must have a title and axis labels.
In [7]:
# Question 2
a = 1
theta = np.arange(0,2*np.pi,0.001)
x = a*(2*np.cos(theta) - np.cos(2*theta))
y = a*(2*np.sin(theta) - np.sin(2*theta))
plt.plot(x,y,lw=3,alpha=0.65)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Cardioid')
plt.grid()
Recall the two good utility maximization problem from microeconomics. Let $x$ and $y$ denotes the amount of two goods that a person consumes. The person receives utility from consumption given by: \begin{align} u(x,y) & = x^{\alpha}y^{\beta} \end{align} The person has income $M$ to spend on the two goods and the price of the goods are $p_x$ and $p_y$. The consumer's budget constraint is: \begin{align} M & = p_x x + p_y y \end{align} Suppose that $M = 100$, $\alpha=0.25$, $\beta=0.75$, $p_x = 1$. and $p_y = 0.5$. The consumer's problem is to maximize their utility subject to the budget constraint. While this problem can easily be solved by hand, we're going to use a computational approach.
Do the following:
Use the budget constraint to solve for $y$ in terms of $x$, $p_x$, $p_y$, and $M$. Use the result to write the consumer's utility as a function of $x$ only. Create a variable called x equal to an array of values from 0 to 80 with step size equal to 0.001 and a variable called utility equal to the consumer's utility. Plot the consumer's utility against $x$.
The NumPy function np.max() returns the highest value in an array and np.argmax() returns the index of the highest value. Print the highest value and index of the highest value of utility.
Use the index of the highest value of utility to find the value in x with the same index and store value in a new variable called xstar. Print the value of xstar.
Use the budget constraint to the find the implied utility-maximizing vaue of $y$ and store this in a variable called ystar. Print ystar.
Bonus question: Create a well-labeled plot of the consumer's budget constraint and the indifference curve that corresponds with the optimal choice of $x$ and $y$.
In [20]:
# Question 3.1
alpha = 0.25
beta = 0.75
M = 100
px=1
py=0.5
x = np.arange(0,80,0.001)
utility = x**alpha*((M-px*x)/py)**beta
plt.plot(x,utility,lw=3,alpha=0.65)
plt.xlabel('x')
plt.ylabel('utility')
plt.title('u[x,y(x)]')
plt.grid()
In [21]:
# Question 3.2
print('highest utility value :',np.max(utility))
print('index of highest utility value:',np.argmax(utility))
In [22]:
# Question 3.3
xstar = x[np.argmax(utility)]
print('xstar:',xstar)
In [23]:
# Question 3.4
ystar = M/py - px*xstar/py
print('ystar:',ystar)
In [45]:
# Question 3 bonus
x = np.arange(0.001,120,0.001)
bc = M/py - px*x/py
ic = (np.max(utility)/x**alpha)**(1/beta)
plt.plot(x,bc,lw=3,alpha = 0.65,label='B.C.')
plt.plot(x,ic,lw=3,alpha = 0.65,label='I.C.')
plt.plot(xstar,ystar,'o',label='Optimal')
plt.grid()
plt.xticks([0,xstar,100])
plt.yticks([0,ystar,200])
plt.ylim([0,250])
plt.xlim([0,120])
plt.legend(numpoints = 1)
Out[45]: