-
Introduction 4
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
-
Production Possibilities Frontier 4
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
-
Trade 3
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
-
Demand 4
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
-
Supply 2
-
Lecture5.1
-
Lecture5.2
-
-
Equilibrium 4
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
-
Curve Movements 4
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
Lecture7.4
-
-
Elasticity and Revenue 5
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
Lecture8.4
-
Lecture8.5
-
-
Taxes 7
-
Lecture9.1
-
Lecture9.2
-
Lecture9.3
-
Lecture9.4
-
Lecture9.5
-
Lecture9.6
-
Lecture9.7
-
-
Consumer and Producer Surplus 8
-
Lecture10.1
-
Lecture10.2
-
Lecture10.3
-
Lecture10.4
-
Lecture10.5
-
Lecture10.6
-
Lecture10.7
-
Lecture10.8
-
-
Imports and Exports 4
-
Lecture11.1
-
Lecture11.2
-
Lecture11.3
-
Lecture11.4
-
-
Tariffs 2
-
Lecture12.1
-
Lecture12.2
-
Elasticity
Solution
import sympy
def elasticity(P1,P2,Q1,Q2):
return ((Q2-Q1)/((Q2+Q1)/2))/((P2-P1)/((P2+P1)/2))
p = sympy.Symbol("Price")
DemandEquation = 11-p
for x in range(1,10):
print(abs(elasticity(x,x+1,DemandEquation.subs(p,x),DemandEquation.subs(p,x+1))))
The only new code is the abs() function, it returns the absolute value, which is how we will present our demand elasticity (since otherwise it would be negative each time)
Our elasticity is highest when our price is high, and lowest when our price is low. At a higher price, if we were to cut the price we would get a much larger quantity increase than a lower price being cut even lower (on a percetange basis).
Before we move on in this we will introduce a new python concept, list comprehension. It is a way to create arrays in much less code than we have been doing. The set up of it is as follows:
[A for B in C]
A is the function that you want to apply to whatever variable you are getting, B is the way you denote the variable you are using the function on, and C is the array you are pulling variables. So if you had an array yourArray = [1,2,3,4] and wanted to double it you would write:
[x*2 for x in yourArray]
Now if we wanted to get a list of the numbers 1 through 10, we could do this:
[x for x in range(1,11)]
Let’s move onto revenue, which has an easy equation.
Equation
For revenue, you can draw a square from the point on the demand curve we are at, which will have area equal to this equation. Let’s create a function to draw over our plot. First initialize our demand equation as we have done in this past:
demandQ = [DemandEquation.subs(p,x) for x in range(0,12)]
prices = [x for x in range(0,12)]
To create our squares on the graph, we are going to need to import matplotlib.patches. Our equation to draw the square on the graph is:
import matplotlib.pyplot as plt
import matplotlib.patches as patches
def drawRevenue(P,Q):
rect = patches.Rectangle((0,0),Q,P,linewidth=1,facecolor="blue")
currentAxis = plt.gca()
currentAxis.add_patch(rect)
print("The revenue of the graph below is "+str(P*Q))
Let’s start with creating the rectangle. patches.Rectangle() creates a rectangle after we give it a few arguments. The first is a tuple (a data type we have not yet used which holds elements within a set of parentheses). This tuple is the origin point of our rectangle, so we feed it (x,y). The next argument is the width, so we put whatever the quantity is (since quantity is on the x axis). The argument after is height, so we put in the price. Finally, the last two decide the color and line width of our square.
The next line, plt.gca() gets our current axes. We need to do this so that we can add our rectangle to it. The line after adds a patch, and we specify that the patch to add is our rectangle. Finally, the last line outputs what the revenue is.
Challenge