from demos.setup import np, plt, demo
from compecon import BasisChebyshev, NLP, nodeunif
%matplotlib inline
def resid(c):
Q.c = c
q = Q(p)
return p + q / (-3.5 * p **(-4.5)) - np.sqrt(q) - q ** 2
n, a, b = 21, 0.5, 2.5
Q = BasisChebyshev(n, a, b)
c0 = np.zeros(n)
c0[0] = 2
p = Q.nodes
monopoly = NLP(resid)
Q.c = monopoly.broyden(c0)
nplot = 1000
p = nodeunif(nplot, a, b)
rplot = resid(Q.c)
demo.figure("Monopolist's Effective Supply Curve", 'Quantity', 'Price')
plt.plot(Q(p), p)
plt.show()
demo.figure('Functional Equation Residual', 'Price', 'Residual')
plt.hlines(0, a, b, 'k', '--')
plt.plot(p, rplot)
plt.show()