```python
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))))
```

    0.157894736842105
    0.294117647058824
    0.466666666666667
    0.692307692307692
    1.00000000000000
    1.44444444444444
    2.14285714285714
    3.40000000000000
    6.33333333333333



```python
[x for x in range(1,11)]
```




    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]




```python
demandQ = [DemandEquation.subs(p,x) for x in range(0,12)]
prices = [x for x in range(0,12)]
```


```python
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))
```


```python
for x in range(1,11):
    quantity = DemandEquation.subs(p,x)
    elast = abs(elasticity(x,x+1,DemandEquation.subs(p,x),DemandEquation.subs(p,x+1)))
    plt.plot(demandQ,prices)
    drawRevenue(x,quantity)
    print("The elasticity at this point is "+str(elast))
    plt.show()
```


```python
for x in range(1,11):
    quantity = DemandEquation.subs(p,x)
    elast = abs(elasticity(x,x+1,DemandEquation.subs(p,x),DemandEquation.subs(p,x+1)))
    revenue = quantity*x
    print("At price "+str(x)+" elasticity is "+str(elast)+" and the revenue is "+str(revenue)+".")
```

    At price 1 elasticity is 0.157894736842105 and the revenue is 10.
    At price 2 elasticity is 0.294117647058824 and the revenue is 18.
    At price 3 elasticity is 0.466666666666667 and the revenue is 24.
    At price 4 elasticity is 0.692307692307692 and the revenue is 28.
    At price 5 elasticity is 1.00000000000000 and the revenue is 30.
    At price 6 elasticity is 1.44444444444444 and the revenue is 30.
    At price 7 elasticity is 2.14285714285714 and the revenue is 28.
    At price 8 elasticity is 3.40000000000000 and the revenue is 24.
    At price 9 elasticity is 6.33333333333333 and the revenue is 18.
    At price 10 elasticity is 21.0000000000000 and the revenue is 10.



```python
elast = [abs(elasticity(x,x+1,DemandEquation.subs(p,x),DemandEquation.subs(p,x+1))) for x in range(1,11)]
revenue = [DemandEquation.subs(p,x)*x for x in range(1,11)]
prices = [x for x in range(1,11)]
plt.plot(prices,revenue)
plt.show()
plt.plot(elast,revenue)
plt.show()
```


```python
import sympy
import matplotlib.pyplot as plt
import matplotlib.patches as patches
p = sympy.Symbol("p")

def supplyShift(demandEquation,supplyEquation1,supplyEquation2,priceStart,priceEnd):
    prices = []
    demandQ = []
    supplyQ1 = []
    supplyQ2 = []
    for price in range(priceStart,priceEnd+1):
        prices += [price]
        demandQ += [demandEquation.subs(p,price)]
        supplyQ1 += [supplyEquation1.subs(p,price)]
        supplyQ2 += [supplyEquation2.subs(p,price)]

    equilibriumP1 = sympy.solve(demandEquation-supplyEquation1)[0]
    equilibriumQ1 = demandEquation.subs(p,equilibriumP1)
    equilibriumP2 = sympy.solve(demandEquation-supplyEquation2)[0]
    equilibriumQ2 = demandEquation.subs(p,equilibriumP2)
    
    
    
    plt.plot(demandQ,prices)
    plt.plot(supplyQ1,prices)
    plt.plot(supplyQ2,prices)
    plt.legend(["Old Demand","Old Supply","New Supply"])
    plt.plot(equilibriumQ1,equilibriumP1, 'ro')
    plt.plot(equilibriumQ2,equilibriumP2, 'ro')
    plt.xlabel("Supply and Demand Quantity")
    plt.ylabel("Price")
    
    rect1 = patches.Rectangle((0,0),equilibriumQ1,equilibriumP1,linewidth=1,color="blue")
    rect2 = patches.Rectangle((0,0),equilibriumQ2,equilibriumP2,linewidth=1,color="red")
    currentAxis = plt.gca()
    currentAxis.add_patch(rect1)
    currentAxis.add_patch(rect2)
    
    plt.show()
    print("The old equilibrium price is "+str(equilibriumP1)+" and old equilibrium quantity is "+str(equilibriumQ1)+".")
    print("The new equilibrium price is "+str(equilibriumP2)+" and new equilibrium quantity is "+str(equilibriumQ2)+".")
    print("The price shifted "+str(equilibriumP2-equilibriumP1)+" and the quantity shifted "+str(equilibriumQ2-equilibriumQ1)+".")
    print("")
    print("The old revenue was "+str(equilibriumQ1*equilibriumP1))
    print("The new revenue is "+str(equilibriumQ2*equilibriumP2))
    print("The revenue shifted by " +str(equilibriumQ2*equilibriumP2-equilibriumQ1*equilibriumP1))
supplyShift(10-p,p,2*p,0,10)
```

1c53b8fdca932e412ceaa6f5d68a8473f3b3d725
ipynb
Jupyter Notebook
FinanceAndPython.com-EconomicFoundations-master/8 Elasticity and Revenue.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
FinanceAndPython.com-EconomicFoundations-master/8 Elasticity and Revenue.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
FinanceAndPython.com-EconomicFoundations-master/8 Elasticity and Revenue.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
2019-12-07T07:01:18.000Z
2022-02-05T01:46:45.000Z
Qwen/Qwen-72B
1. YES
2. YES