<jupyter_start><jupyter_text>Profit Maximizing Quantity (Linear Demand)Consider a situation of a monopolist facing a linear demand curve\begin{align}    D(p) &= a - b p\end{align}where $a, b > 0$.  The firm will produce exactly enough units of their product to meet the demand $D(p)$ and it costs them $c > 0$ to produce each unit of product.  The total profits the monopolist expects from choosing price $p>0$ is\begin{align}    \pi(p) &= (a - bp)p - c(a - bp) \\    &= (p - c)(a - bp)\end{align}To identify the profit maximizing price we need to identify a local maximum consisting of a critical point, an $x^*$ that satisfies a first order condition $\frac{d\pi }{dp} (x^*) = 0$ and a second order condition $\frac{d^2 \pi}{d x^2}(x^*) < 0$.<jupyter_code>from sympy import *
init_printing()
a, b, c, P = symbols('a b c P',
                     real=True,
                     positive=True,
                     finite=True)
demand = a - b * P
revenue = P * demand
cost = c * demand
profit = factor(revenue - cost)

Eq(Symbol('\pi(P)'), profit)
# To satisfy the first order condition
# for a maximum we take the derivative
# of the profit function w.r.t. p
DP = profit.diff(P)
Eq(Symbol('\\frac{d \pi}{d p}'), DP)
# Set the derivative equal to zero
# and solve for p.
P_star = solve(DP, P)[0]
Eq(Symbol('P^{*}(a,b,c)'), P_star)<jupyter_output><empty_output><jupyter_text>Now that we have the price that satisfies the first order condition, we need to evaluate the second order condition wich is the second derivative of profit with respect to price and test its sign at the $p^*$.<jupyter_code>D2P = DP.diff(P)
D2P, D2P.is_negative<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12439903846153846, 'fraction_numerical': 0.006610576923076923, 'mean_word_length': 3.6638655462184873, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '163608', 'license': 'MIT', 'n_tokens_mistral': 556, 'n_tokens_neox': 535, 'n_words': 215, 'path': 'assets/pdfs/math_bootcamp/notebooks/profit_max_linear_demand.ipynb', 'repo_name': 'joepatten/joepatten.github.io', 'size': '1664'}