Sub topic 9
Writing Demand as a Linear Function
What this chapter assumes
You should already know the law of demand, the demand schedule, the demand curve, and the difference between a movement along the curve and a shift of the whole curve. You should also be comfortable with y = m x + c. This chapter writes the same ideas as an equation. An equation lets you compute quantities, shift the curve with one number, and check your graph reading.
The direct demand function
The simplest demand function is linear:
Q = a - b * PQis the quantity demanded.Pis the price.ais the quantity demanded when the price is zero. On a graph with quantity on the horizontal axis,ais the horizontal intercept.bis a positive number that says how many units of quantity are lost for each one-unit rise in price. The minus sign in front of it is the law of demand.
A quantity cannot be negative. The formula gives a negative number once P passes a / b. That price is called the choke price, because demand is choked off completely there. So the full function has a floor:
Q = max(a - b * P, 0)The code below builds the schedule for a = 100 and b = 2.
def quantity_demanded(price, a=100, b=2):
"""Linear demand: Q = a - b * P, never below zero."""
return max(a - b * price, 0)
print("Price Quantity")
for p in range(0, 51, 10):
print(f"{p:>5} {quantity_demanded(p):>8}")
# Output:
# Price Quantity
# 0 100
# 10 80
# 20 60
# 30 40
# 40 20
# 50 0Each $10 increase in price removes 20 units, because b = 2 and 2 * 10 = 20. The choke price is 100 / 2 = 50, which matches the last row.
What a and b mean in words
| Parameter | Meaning | Where it shows on the graph |
|---|---|---|
| `a` | Quantity demanded at price zero | Horizontal intercept |
| `a / b` | Choke price, where quantity demanded reaches zero | Vertical (price) intercept |
| `b` | Units of quantity lost per one-unit price rise | Controls steepness (see the next section) |
A larger b means buyers react more strongly to price changes in absolute units. Be careful with the word "steeper" here. It is the next section's main trap.
Inverse demand: solving for price
Economists draw price on the vertical axis and quantity on the horizontal axis. The function Q = a - b * P has price as its input, so it is written the opposite way from the graph. Solving for P gives the inverse demand function:
P = a / b - Q / bdef inverse_demand(quantity, a=100, b=2):
"""Inverse demand: the highest price at which buyers take this quantity."""
return (a - quantity) / b
for q in (0, 20, 40, 60, 80, 100):
print(q, inverse_demand(q))
# Output:
# 0 50.0
# 20 40.0
# 40 30.0
# 60 20.0
# 80 10.0
# 100 0.0Inverse demand has a second reading. At quantity 40, the price is 30. Buyers will take 40 units only if the price is 30 or lower. That is why the inverse form is useful later, when a seller asks what price clears a given quantity.
The slope trap
On the standard graph, the slope is rise over run, which is price change divided by quantity change. For P = 50 - 0.5 Q, the slope is -1 / b = -0.5, not -b = -2.
So a larger b gives a flatter demand curve on the usual graph. Buyers lose more units per dollar, so the curve spreads out sideways and the price axis changes less. If you remember only one rule, remember this one: the graph slope is the reciprocal of the coefficient in front of P.
Adding the determinants of demand
The function Q = a - b * P holds everything except price fixed. Those fixed things are folded into a. To see them move, pull them out of a and give each one its own term. For income I:
Q = a - b * P + c * IHere c is how many extra units buyers want per extra unit of income, at the same price.
def quantity_demanded(price, income, a=20, b=2, c=0.01):
"""Normal good: Q = a - b * P + c * income."""
return max(a - b * price + c * income, 0)
price = 10
print(quantity_demanded(price, income=3000)) # 30.0
print(quantity_demanded(price, income=4000)) # 40.0Price stayed at 10. Income rose by 1000, and quantity rose by 0.01 * 1000 = 10. Since price did not change, this is not a movement along the curve. The whole curve shifted to the right by 10 units at every price.
The two kinds of change enter the function in different places.
- A price change moves you along the curve. It changes the input
P. - A change in any other determinant shifts the curve. It changes the effective intercept, which here is
a + c * I.
The diagram plots the schedule from the first example and a second schedule after a rise in the intercept of 10 units.
The lines are parallel because only the intercept changed. The slope term b did not. The shift is 10 units horizontally. Measured on the price axis, the same shift is 10 / b = 5 dollars vertically. Both descriptions are correct, and they are two ways of reading one shift.
Signs of the other coefficients
You can include more determinants as extra terms. Each coefficient's sign tells you what kind of good or relationship you are modelling.
| Determinant | Term | Sign of coefficient | Meaning |
|---|---|---|---|
| Income, normal good | `c * I` | Positive | More income, more demand |
| Income, inferior good | `c * I` | Negative | More income, less demand |
| Price of a substitute | `d * P_sub` | Positive | Rival gets dearer, demand for this good rises |
| Price of a complement | `-e * P_comp` | Negative effect | Partner good gets dearer, demand falls |
| Number of buyers | scales `a` | Positive | More buyers, more demand at each price |
Tastes and expectations usually have no natural unit, so they are typically handled by changing a directly.
def demand(price, income, p_sub, p_comp,
a=20, b=2, c=0.01, d=0.5, e=1.0):
"""Q = a - b*P + c*income + d*p_sub - e*p_comp, floored at zero."""
q = a - b * price + c * income + d * p_sub - e * p_comp
return max(q, 0)
base = demand(price=10, income=3000, p_sub=8, p_comp=4)
sub_up = demand(price=10, income=3000, p_sub=12, p_comp=4)
comp_up = demand(price=10, income=3000, p_sub=8, p_comp=6)
print(round(base, 2)) # 30.0
print(round(sub_up, 2)) # 32.0
print(round(comp_up, 2)) # 28.0A rise of 4 in the substitute's price adds 0.5 * 4 = 2 units. A rise of 2 in the complement's price removes 1.0 * 2 = 2 units. Each call changes one input and holds the rest, which is the ceteris paribus rule written as code.
Estimating a and b from two observations
Suppose you observe two price and quantity pairs on the same demand curve: (P1, Q1) and (P2, Q2). Then:
b = -(Q2 - Q1) / (P2 - P1)
a = Q1 + b * P1def fit_linear_demand(point_1, point_2):
"""Return (a, b) for Q = a - b*P through two (price, quantity) points."""
p1, q1 = point_1
p2, q2 = point_2
if p1 == p2:
raise ValueError("The two prices must differ.")
b = -(q2 - q1) / (p2 - p1)
a = q1 + b * p1
return a, b
a, b = fit_linear_demand((10, 80), (30, 40))
print(a, b) # 100.0 2.0The two points recover a = 100 and b = 2, which matches the first example.
This only works if nothing else changed between the observations. If income rose between week 1 and week 2, the second point lies on a different curve. The line you fit would blend a movement with a shift, and b would be wrong. Real data needs many observations and a method such as regression that controls for the other determinants.
Slope is not elasticity
On a linear demand curve, b is the same everywhere. The price elasticity of demand is not. The point elasticity is:
elasticity = (change in Q / change in P) * (P / Q) = -b * P / QIt scales the response by how large the price and quantity already are.
def point_elasticity(price, a=100, b=2):
q = a - b * price
return -b * price / q
for p in (10, 25, 40):
print(p, round(point_elasticity(p), 2))
# Output:
# 10 -0.25
# 25 -1.0
# 40 -4.0Near the top of the quantity range (price 10, quantity 80), a price rise is small in percentage terms and the elasticity is -0.25. Near the choke price (price 40, quantity 20), the percentage change is large and the elasticity is -4. Along one straight line, demand goes from insensitive to very sensitive.
Be careful at the endpoints. At P = 50 in this example, Q = 0, so the function divides by zero. At the vertical intercept, elasticity is not defined by this formula. A later chapter develops elasticity fully. For now, remember that a constant slope does not mean a constant response in percentage terms.
Limits of the linear form
Linear demand is a local approximation, not a law of nature. Keep these edge cases in mind.
- The floor matters. Without
max(..., 0), a computed quantity goes negative past the choke price. Any code that sums demands or computes revenue will then give nonsense. - The function is only trustworthy near the data. A straight line fit between prices 10 and 30 says little about a price of 2 or 48.
- Units belong to the coefficients. If price is in dollars and you switch to cents,
bis divided by 100. The graph's shape does not change, but the numbers do. - Real demand curves are often curved. A constant-elasticity form such as
Q = k * P^(-e)fits many markets better. The linear form is chosen because its algebra is easy, and that is a good reason for a first model. - The sign of
bis the law of demand. If a fittedbis negative, quantity rises with price. Either the data mixes shifts with movements, or you have one of the rare goods covered in a later chapter.
Summary of the working model
- Write demand as
Q = a - b * P, floored at zero. - Read
aas the quantity at price zero anda / bas the choke price. - Convert to inverse demand
P = a / b - Q / bto draw the graph. The drawn slope is-1 / b. - Change
Pto move along the curve. Change any other determinant, through its own coefficient, to shift the curve. - A constant slope does not mean constant elasticity. Elasticity is
-b * P / Qand varies along the line.
Exercise
A demand function is Q = 120 - 4P. (a) Find the choke price. (b) Write the inverse demand function. (c) Find the quantity demanded at P = 10. (d) What is the slope of the demand curve when price is on the vertical axis?
Show answer
(a) The choke price is a / b = 120 / 4 = 30. (b) P = 30 - Q / 4. (c) Q = 120 - 4 * 10 = 80. (d) The drawn slope is -1 / b = -1/4 = -0.25, not -4.
Exercise
A normal good has demand Q = 30 - 3P + 0.02 * I, where I is income. Income rises from 2000 to 2500 and price stays at 5. (a) What is the quantity demanded before and after? (b) Is this a movement along the curve or a shift? (c) By how many units does the curve shift at every price, and by how many dollars on the price axis?
Show answer
(a) Before: 30 - 15 + 40 = 55. After: 30 - 15 + 50 = 65. (b) It is a shift, because price did not change and the intercept moved. (c) The horizontal shift is 0.02 * 500 = 10 units at every price. On the price axis the shift is 10 / 3, about 3.33 dollars.
Exercise
On the demand curve Q = 100 - 2P, compute the point elasticity at P = 20. Is demand more or less sensitive to price there than at P = 10, where the elasticity is -0.25?
Show answer
At P = 20, Q = 60, so elasticity = -2 * 20 / 60 = -0.67 (rounded). Its size is larger than 0.25, so demand is more sensitive to price at P = 20, even though the slope is the same.