-
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
-
Solving for Two Different Prices
In the past, the price and quantity are both equal in the demand and supply equations, which makes our computation fairly easy. In this case, we actually have two different prices and the same quantity. This difference requires us to create a new function that solves a system of equations. Let’s walk step by step through the creation of this function.
import sympy
p = sympy.Symbol("p")
q = sympy.Symbol("q")
def eqSolve(eq1,eq2,tax):
demandP = sympy.solve(eq1-q,p)[0]
supplyP = sympy.solve(eq2-q,p)[0]
print(demandP)
print(supplyP)
eqSolve(10-p,2*p,2)
Our first equation is going to be our demand equation, the second will be our supply equation. The first two lines are taking the left hand side variable, quantity, and moving it to the right side. The equation for demand we are using, for example, is q = 10-p but for sympy we want it in the form 10-p-q when we solve.
The second argument, p, is telling sympy that we want to solve this equation for the variable p. While our equation tells us what q equals, we are going to need what the price equals for both demand and supply.
Now let’s add on the tax. We are going to specify the tax in this way. The equilibrium price without tax is p. The price the consumer pays is p+tax
consumer
, and the price the producer receives is p-tax
producer
. The tax is added for the consumer because they pay more, where as for the producer they get less revenue so it is subtracted. Finally, the two taxes must add up to the total tax so we get: tax = tax
consumer
+ tax
producer
.
Right now we have p = -q + 10 and p = q/2, this becomes p+tax
consumer
= -q + 10 and p + tax
producer
= q/2. We need to move the taxes to the right in our code, as shown below.
import sympy
p = sympy.Symbol("p")
q = sympy.Symbol("q")
cTax = sympy.Symbol("cTax")
pTax = sympy.Symbol("pTax")
def eqSolve(eq1,eq2,tax):
demandP = sympy.solve(eq1-q,p)[0]
supplyP = sympy.solve(eq2-q,p)[0]
demandP = demandP-cTax
supplyP = supplyP+pTax
print(demandP)
print(supplyP)
eqSolve(10-p,2*p,2)