```python
!pip install sympy
```

    Requirement already satisfied: sympy in /Users/seanmcowen/anaconda/lib/python2.7/site-packages



```python
import sympy
x = sympy.Symbol("x")
```


```python
equation = x*2+1
print(equation)
```

    2*x + 1



```python
print(equation.subs(x,5))
```

    11



```python
equation1 = x*2+1
equation2 = x-1
print(equation1 + equation2)
```

    3*x



```python
print(sympy.solve(equation1-equation2))
```

    [-2]



```python
import sympy
p = sympy.Symbol("p")

demandEquation = 10-p
supplyEquation = p

prices = []
demandQ = []
supplyQ = []

for price in range(0,11):
    demandQ += [demandEquation.subs(p,price)]
    supplyQ += [supplyEquation.subs(p,price)]
    prices += [price]
print(prices)
print(demandQ)
print(supplyQ)
```

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



```python
EquilibriumP = sympy.solve(demandEquation-supplyEquation)
print(EquilibriumP)
EquilibriumP = EquilibriumP[0]
print(EquilibriumP)
```

    [5]
    5



```python
EquilibriumQ = demandEquation.subs(p,EquilibriumP)
print(EquilibriumQ)
```

    5



```python
import matplotlib.pyplot as plt
plt.plot(demandQ,prices)
plt.plot(supplyQ,prices)
plt.plot(EquilibriumQ,EquilibriumP, 'ro')

plt.xlabel("Quantity")
plt.ylabel("Price")
plt.show()
```


```python
import matplotlib.pyplot as plt
plt.plot(demandQ,prices)
plt.plot(supplyQ,prices)
unitsDemanded = demandEquation.subs(p,8)
unitsSupplied = supplyEquation.subs(p,8)
plt.plot(unitsDemanded,8, 'ro')
plt.plot(unitsSupplied,8, 'ro')
plt.plot([unitsDemanded,unitsSupplied],[8,8],":")

plt.xlabel("Supply and Demand")
plt.ylabel("Price")
plt.show()

surplus = unitsSupplied-unitsDemanded

print("The surplus is equal to "+str(surplus)+" units.")
```


```python
import matplotlib.pyplot as plt
plt.plot(demandQ,prices)
plt.plot(supplyQ,prices)
unitsDemanded = demandEquation.subs(p,2)
unitsSupplied = supplyEquation.subs(p,2)
plt.plot(unitsDemanded,2, 'ro')
plt.plot(unitsSupplied,2, 'ro')
plt.plot([unitsDemanded,unitsSupplied],[2,2],":")

plt.xlabel("Supply and Demand")
plt.ylabel("Price")
plt.show()

shortage = unitsDemanded-unitsSupplied

print("The shortage is equal to "+str(shortage)+" units.")
```

15a7a7755997b4cbe0392198b3e201d6c4aa214c
ipynb
Jupyter Notebook
FinanceAndPython.com-EconomicFoundations-master/6 Equilibrium.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
FinanceAndPython.com-EconomicFoundations-master/6 Equilibrium.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
FinanceAndPython.com-EconomicFoundations-master/6 Equilibrium.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