Sub topic 8
Computing Surplus with Linear Demand and Supply
This chapter assumes you know four things. You can read supply and demand curves. You can find an equilibrium price and quantity. You can compute the area of a triangle and a trapezoid. You can read a line written as P = a - bQ. Consumer surplus and producer surplus were defined in the previous two chapters. Here you turn those definitions into a repeatable calculation.
The setup: two lines and four numbers
A linear market is fully described by two straight lines, each written with price on the left:
- Inverse demand: P = a - bQ
- Inverse supply: P = c + dQ
The four parameters have direct meanings:
| Parameter | Meaning | Must satisfy |
|---|---|---|
| a | Demand intercept. The price at which quantity demanded falls to zero (the choke price). | a > c for any trade to occur |
| b | Slope of demand. Price drops by b for each extra unit bought. | b > 0 |
| c | Supply intercept. The cost of the very first unit. | c ≥ 0 |
| d | Slope of supply. Price rises by d for each extra unit sold. | d > 0 |
Inverse demand gives the willingness to pay for the Q-th unit. Inverse supply gives the cost of producing the Q-th unit. Surplus is the gap between these two numbers and the price, added up over every unit traded.
Step 1: Find the equilibrium
At equilibrium, demand and supply give the same price at the same quantity:
a - bQ = c + dQ
Solving for Q:
Q* = (a - c) / (b + d)
Then substitute Q* into either line to get the price:
P = c + dQ
With a = 100, b = 2, c = 10, d = 1, you get Q = 90 / 3 = 30 and P = 10 + 30 = 40. Check with the demand line: 100 - 2(30) = 40. Both lines agree.
Step 2: Draw the triangles
Each surplus is a triangle whose base sits on the vertical axis and whose tip sits at the equilibrium point (Q, P).
- Consumer surplus (CS) lies between the demand line and the price line. Its height on the price axis runs from P up to a. Its width is Q.
- Producer surplus (PS) lies between the price line and the supply line. Its height runs from c up to P. Its width is Q.
Because each region is a right triangle with width Q*, the formula is half the base times the height:
- CS = ½ × Q × (a - P)
- PS = ½ × Q × (P - c)
- Total surplus = CS + PS
Worked example in code
The following script does the whole calculation. It also guards against the case where demand starts below supply, which would make Q* negative.
def linear_surplus(a, b, c, d):
"""Return (Q, P, CS, PS, total) for demand P = a - b*Q and supply P = c + d*Q."""
if a <= c:
# Even the first buyer values the good below the first seller's cost.
return 0.0, None, 0.0, 0.0, 0.0
q = (a - c) / (b + d)
p = c + d * q
cs = 0.5 * q * (a - p)
ps = 0.5 * q * (p - c)
return q, p, cs, ps, cs + ps
q, p, cs, ps, total = linear_surplus(a=100, b=2, c=10, d=1)
print(q, p, cs, ps, total)
# 30.0 40.0 900.0 450.0 1350.0Consumer surplus is 900, producer surplus is 450, and total surplus is 1350. Buyers capture twice as much as sellers here. The next section explains why.
Shortcuts worth knowing
Two identities save time and double as sanity checks.
Total surplus in one step. The two triangles together form one large triangle. It has width Q* and height a - c, the full gap between the demand intercept and the supply intercept:
Total = ½ × Q* × (a - c) = (a - c)² / (2(b + d))
For the example: 90² / 6 = 8100 / 6 = 1350. This matches the sum of the two triangles.
The split depends only on the slopes. Along the demand line, a - P = bQ. Along the supply line, P - c = dQ. Substituting:
- CS = ½ × b × Q*²
- PS = ½ × d × Q*²
So CS : PS = b : d. In the example, b = 2 and d = 1, which gives 900 : 450. The steeper curve gets the larger share. If demand and supply have equal slopes, buyers and sellers split the surplus evenly.
Converting from quantity form
Textbooks and datasets often give curves as quantity equations, such as Qd = 50 - 0.5P. The formulas above need price on the left, so invert first.
- Start with Qd = 50 - 0.5P.
- Move terms: 0.5P = 50 - Qd.
- Divide by 0.5: P = 100 - 2Qd. So a = 100 and b = 2.
For supply, Qs = P - 10 becomes P = 10 + Qs, so c = 10 and d = 1. These are the same curves as the example.
Shifts: recomputing after a change
A change in demand or supply changes a, b, c or d. Rerun the same steps with the new values.
Suppose demand rises so the intercept moves from a = 100 to a = 130, with the slopes unchanged.
def linear_surplus(a, b, c, d):
if a <= c:
return 0.0, None, 0.0, 0.0, 0.0
q = (a - c) / (b + d)
p = c + d * q
cs = 0.5 * q * (a - p)
ps = 0.5 * q * (p - c)
return q, p, cs, ps, cs + ps
before = linear_surplus(100, 2, 10, 1)
after = linear_surplus(130, 2, 10, 1)
labels = ["Q", "P", "CS", "PS", "Total"]
for name, b_val, a_val in zip(labels, before, after):
print(f"{name:5s} {b_val:8.1f} -> {a_val:8.1f}")The output shows:
| Quantity | Before | After |
|---|---|---|
| Equilibrium quantity | 30 | 40 |
| Equilibrium price | 40 | 50 |
| Consumer surplus | 900 | 1600 |
| Producer surplus | 450 | 800 |
| Total surplus | 1350 | 2400 |
Both groups gain. Buyers value the good more, so trade expands and the price rises. The price rise cuts into the buyers' gain per unit, but the extra units more than make up for it. The ratio of CS to PS stays 2 : 1 because the slopes did not change.
Edge cases and checks
- No trade. If a ≤ c, the formula would give a negative quantity. The correct answer is zero trade and zero surplus, so check this case first.
- Vertical or horizontal curves. The shortcuts assume finite, nonzero slopes. A perfectly inelastic (vertical) demand has no choke price, so consumer surplus is not a triangle and the formulas do not apply. Treat such cases separately.
- Unequal bases. The triangle formulas work only because the price is the market-clearing price, so both triangles end at Q*. If the price is held away from equilibrium, the surplus regions change shape and a trapezoid appears. A later chapter on price controls handles that case.
- Units. Surplus has units of price times quantity, for example dollars per unit times units, which gives dollars. If quantity is in thousands, the surplus is in thousands of dollars.
- Sanity check. CS + PS must equal (a - c)² / (2(b + d)). If your two triangles do not add up to this, one of the heights is wrong.
Exercises
Exercise
A market has demand Qd = 80 - 2P and supply Qs = 3P - 15. Find the equilibrium, consumer surplus, producer surplus and total surplus.
Show answer
Invert both curves. Demand: 2P = 80 - Q, so P = 40 - 0.5Q, giving a = 40 and b = 0.5. Supply: 3P = Q + 15, so P = 5 + Q/3, giving c = 5 and d = 1/3. Then Q = (40 - 5) / (0.5 + 1/3) = 35 / (5/6) = 42, and P = 5 + 42/3 = 19. Check with the original forms: Qd = 80 - 38 = 42 and Qs = 57 - 15 = 42. CS = 0.5 × 42 × (40 - 19) = 441. PS = 0.5 × 42 × (19 - 5) = 294. Total = 735, which matches (a - c)² / (2(b + d)) = 35² / (2 × 5/6) = 735.
Exercise
In a linear market, the supply slope d is three times the demand slope b. Without computing the equilibrium, what share of total surplus goes to consumers?
Show answer
CS : PS = b : d = 1 : 3, so consumers receive 1 / (1 + 3) = 25% of total surplus and producers receive 75%. The result follows from CS = ½bQ² and PS = ½dQ².