CompEcon Toolbox:
DemApp10
Monopolist's Effective Supply Function
Randall Romero Aguilar, PhD

This demo is based on the original Matlab demo accompanying the Computational Economics and Finance 2001 textbook by Mario Miranda and Paul Fackler.

Last updated: 2020-Sep-09

Initial tasks

In [ ]:
if 'google.colab' in str(get_ipython()):
    print("This notebook is running on Google Colab. Installing the compecon package.")
    !pip install compecon
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
from compecon import BasisChebyshev, NLP, demo

Residual Function

In [ ]:
def resid(c):
    Q.c = c
    q = Q(p)
    marginal_income = p + q / (-3.5 * p **(-4.5))
    marginal_cost = np.sqrt(q) + q ** 2
    return  marginal_income - marginal_cost 

Approximation structure

In [ ]:
n, a, b = 21, 0.5, 2.5
Q = BasisChebyshev(n, a, b)
c0 = np.zeros(n)
c0[0] = 2
p = Q.nodes

Solve for effective supply function

In [ ]:
monopoly = NLP(resid)
Q.c = monopoly.broyden(c0)

Plot effective supply

In [ ]:
nplot = 1000
p = np.linspace(a, b, nplot)
rplot = resid(Q.c)
In [ ]:
fig1, ax = plt.subplots()
ax.set(title="Monopolist's Effective Supply Curve",
       xlabel='Quantity', 
       ylabel='Price')
ax.plot(Q(p), p);

Plot residual

In [ ]:
fig2, ax = plt.subplots()
ax.set(title='Functional Equation Residual',
       xlabel='Price',
       ylabel='Residual')
ax.hlines(0, a, b, 'k', '--')
ax.plot(p, rplot);

Save all figures to disc

In [ ]:
#demo.savefig([fig1, fig2], name='demapp10')