Exercise 1: Write a function that computes the level of output generated by a constant returns to scale Cobb-Douglas production function, i.e., such that it computes $A\cdot K^\alpha \cdot L^{1-\alpha}$.
def CobbDouglas(K=1, L=1, A=1, alpha=0.3):
'''
This function computes the level of output of a Cobb-Douglas production function.
Given values of K, L, A, and alpha it returns A*K^alpha*L^(1-alpha).
Parameters:
-----------
K: float, integer or any other number, default=1
L: float, integer or any other number, default=1
A: float, integer or any other number, default=1
alpha: float between (0,1), default=0.3
Returns:
--------
out = A * K**alpha * L**(1-alpha)
Example:
>>> out = CobbDouglas(4, 9, 2, 1/2)
>>> out
12
'''
out = A * K**alpha * L**(1 - alpha)
return out
Run to view results
import numpy as np
import matplotlib.pyplot as plt
def CobbDouglas(K=1, L=1, A=1, alpha=0.3):
return A * K**alpha * L**(1 - alpha)
# values of K from 0 to 5
K_vals = np.linspace(0, 5, 100)
# choose fixed values for A and L
A = 1
L = 2
alpha = 0.3
# compute output for each K
Y_vals = CobbDouglas(K=K_vals, L=L, A=A, alpha=alpha)
# plot
plt.plot(K_vals, Y_vals)
plt.xlabel("K")
plt.ylabel("Output Y")
plt.title("Cobb-Douglas Production Function")
plt.show()
Run to view results
Exercise 3: Show with a plot the effect of increasing $A$ from 1 to 2, 4, or 5
import numpy as np
import matplotlib.pyplot as plt
def CobbDouglas(K=1, L=1, A=1, alpha=0.3):
return A * K**alpha * L**(1 - alpha)
# values of K
K_vals = np.linspace(0, 5, 100)
# fixed values
L = 2
alpha = 0.3
# different A values
A_values = [1, 2, 4, 5]
# plot each production function
for A in A_values:
Y_vals = CobbDouglas(K=K_vals, L=L, A=A, alpha=alpha)
plt.plot(K_vals, Y_vals, label=f"A = {A}")
plt.xlabel("K")
plt.ylabel("Output Y")
plt.title("Effect of Increasing A on the Cobb-Douglas Production Function")
plt.legend()
plt.show()
Run to view results
import numpy as np
import matplotlib.pyplot as plt
def CobbDouglas(K=1, L=1, A=1, alpha=0.3):
return A * K**alpha * L**(1 - alpha)
# values of K
K_vals = np.linspace(0, 5, 100)
# fixed values
A = 1
alpha = 0.3
# different L values
L_values = [1, 2, 4, 5]
# plot each production function
for L in L_values:
Y_vals = CobbDouglas(K=K_vals, L=L, A=A, alpha=alpha)
plt.plot(K_vals, Y_vals, label=f"L = {L}")
plt.xlabel("K")
plt.ylabel("Output Y")
plt.title("Effect of Increasing L on the Cobb-Douglas Production Function")
plt.legend()
plt.show()
Run to view results
import numpy as np
import matplotlib.pyplot as plt
def CobbDouglas(K=1, L=1, A=1, alpha=0.3):
return A * K**alpha * L**(1 - alpha)
K_vals = np.linspace(0, 5, 100)
A = 1
alpha = 0.3
L_values = [1, 2, 4, 5]
for L in L_values:
Y_vals = CobbDouglas(K=K_vals, L=L, A=A, alpha=alpha)
plt.plot(K_vals, Y_vals, label=f"L = {L}")
plt.xlabel("K")
plt.ylabel("Output Y")
plt.title("Effect of Increasing L on the Cobb-Douglas Production Function")
plt.legend()
plt.savefig("production_plot.png")
plt.savefig("production_plot.jpeg")
plt.savefig("production_plot.pdf")
plt.show()
Run to view results
from IPython.display import IFrame
IFrame(src="https://fred.stlouisfed.org/", width=900, height=500)
Run to view results
from IPython.display import IFrame
IFrame(
src="https://databank.worldbank.org/reports.aspx?dsid=2&series=IP.PAT.RESD",
width=1000,
height=600
)
Run to view results