In: Computer Science
Take the linear demand and functions for the market for beef:
Demand: P=a1-b1Qd+cPc
Supply: P=a2+b2Qd
where a1 and a2 are demand and supply intercepts, respectively. b1 and b2 are the slopes for demand and supply. Pc is the price of chicken, a substitute for beef. In this case, assume that both c and Pc are exogenously determined parameters.
1. In Python, create a function for the demand that inputs the prices and the parameters, and outputs the quantity demanded using the above function (Hint: You need to do some algebra to get Qd=…).
2. Create a function for supply, that inputs the prices and the parameters, and outputs the quantities supplied.
3. Using the parameters a1=80, a2=10, b1=.5, b2=2, c=.5, Pc=10, create graphs that show supply and demand. Be sure to put prices on the y-axis and quantities on the x-axis. Comment on what the graph shows for the approximate equilibrium price and quantity (hint: have prices go from 0 to 100, in increments of 10). Make sure your graphs have labels.
4. Now say the price of chicken rises from 10 to 20 and a new innovation in beef production causes supply to shift out, so that a2 = 5. Generate the new lists of quantities (use the same list of prices and give a new graph with old demand, old supply, new demand, and new supply). Be sure to give graph labels to make clear which line is which. Comment on the value of the new equilibrium.
5. Using pen and paper, solve for the equilibrium prices and quantities as functions of the parameters
6. Create a function that inputs the model parameters and outputs the equilibrium values for a given set of parameters.
7. Call the function to get the equilibrium for #3 and then call the function to get the equilibrium for #4. Comment on the differences. What happens to prices and quantities in equilibrium between the two and why?
Problem must be answered in Python
1).ANSWER:
GIVEN BELOW:
# For finding Demand Quantity
def demandQuantity(a1,b1,c,pc,Price):
Qd=(a1+c*pc-Price)/b1
return Qd
# function for finding Supply Quantity
def supplyQuantity(a2,b2, Price):
Qd=(a2-Price)/b2
return Qd
# Numpy librery is used to compute scientific calculation in python
# Here numpy is used for taking price in range 0 - 100 in increments of 10
# Here We increase the endinf poind in order to get perfect equilibirium point in graph
import numpy as np
price=np.arange(0,150,10).tolist()
print(price)
*for #3*
# Parameters for calculating demand and supply Quantity
a1=80
a2=10
b1=0.5
b2=2
c=0.5
pc=10
supplyQd=[] # These two lists will store supply and demand quantity
demandQd=[]
for i in price:
DQd=demandQuantity(a1,b1,c,pc,i)
demandQd.append(DQd)
SQd=supplyQuantity(a2,b2,i)
supplyQd.append(SQd)
# printing supply and demand quantity lists
print(demandQd)
print(supplyQd)
# Here, we used the matplotlib library for ploting graph
import matplotlib.pyplot as plt
plt.plot(demandQd,price,'-o') # Plot demand vs price
plt.plot(supplyQd,price,'-o',color='red') # Plot supply vs price
plt.legend(["Demand Quantity","Supply Quantity"],loc="upper right")
plt.xlabel("Quantity") # for labels
plt.ylabel("Price")
plt.show()
*for #4*
# parameters for Question no 4
a1=80
a2=5
b1=0.5
b2=2
c=0.5
pc=10
new_supplyQd=[]
new_demandQd=[]
for i in price:
new_demandQd.append(demandQuantity(a1,b1,c,pc,i))
new_supplyQd.append(supplyQuantity(a2,b2,i))
# here we printed a new list
print(new_demandQd)
print(new_supplyQd)
# Here, we used the matplotlib library for ploting graph
import matplotlib.pyplot as plt
plt.plot(demandQd,price,'-o') # old demand vs new price
plt.plot(supplyQd,price,'-o',color='red') #old suply vs price
plt.plot(new_demandQd,price,'-',color='green') #new demand vs price
plt.plot(new_supplyQd,price,'-') # new supply vs price
plt.legend(["Old Demand Quantity","New Supply Quantity", "New Demand Quantity", "New Supply Quantity"],loc="upper right") # legend
plt.xlabel("Quantity") # for labels
plt.ylabel("Price")
plt.show()
# Function for finfing Equilibirium price :
def findEquilibrumPoint(a1, a2, b1, b2, c ,pc):
price = (a1*b2 + c*pc*b2 - a2*b1)/(b2 - b1)
return price
print("Equilibirium Price for #3-------")
Equilibrium_price = findEquilibrumPoint(80, 10, 0.5, 2, 0.5, 10)
print(Equilibrium_price)
print("Equilibrium Price When the Demand Quantity met with Supply Quantity : "+str(Equilibrium_price))
print("\n")
print("Equilibirium Price for #4-------")
Equilibrium_price = findEquilibrumPoint(80, 5, 0.5, 2, 0.5, 10)
print(Equilibrium_price)
print("Equilibrium Price When the Demand Quantity met with Supply Quantity : "+str(Equilibrium_price))
OUTPUT :
GRAPH FOR #3....
GRAPF FOR #4....
EQUILIBRIUM POINTS
Equilibirium Price for #3------- 110.0
Equilibrium Price When the Demand Quantity met with Supply Quantity : 110.0
Equilibirium Price for #4------- 111.66666666666667
Equilibrium Price When the Demand Quantity met with Supply Quantity : 111.66666666666667
SCREENSHOT OF CODE AND OUTPUT :