Module 5 — The Marginalist Revolution

Choosing at the Margin: Utility, Optimisation, and Demand

From Smith to Simulation: Computing the Ideas that Built Economics
The University of Edinburgh · School of Economics


Part I — The History

The Revolution of the 1870s

In the early 1870s, three economists working independently — William Stanley Jevons in Manchester, Carl Menger in Vienna, and Léon Walras in Lausanne — arrived at the same idea almost simultaneously. They called it marginal utility, and it transformed economics from a study of classes and nations into a science of individual choice.

The classical economists (Smith, Ricardo, Marx) asked: what determines the value of a good? Their answer was labour: a good is worth the labour required to produce it. This created a paradox — the famous diamond-water paradox. Water is essential for life but cheap; diamonds are useless but expensive. If value comes from labour or usefulness, why is water cheap?

The marginalists’ answer: value comes not from total utility but from marginal utility — the satisfaction from one additional unit. Water is abundant, so the marginal glass adds little satisfaction. Diamonds are scarce, so the marginal diamond adds a lot. It’s not the first glass of water vs the first diamond; it’s the last glass vs the last diamond.

“Value depends entirely upon utility… We have only to trace out carefully the natural laws of the variation of utility, as depending upon the quantity of commodity in our possession, to arrive at a satisfactory theory of exchange.”
— W.S. Jevons, The Theory of Political Economy (1871)

What Changed

The Marginalist Revolution reshaped economics in three ways:

  1. From classes to individuals. Smith and Marx analysed workers, capitalists, and landlords as classes. The marginalists analysed individual consumers and firms making optimising decisions.

  2. From labour theory to subjective value. Value became subjective — determined by individual preferences — rather than objective (embedded labour).

  3. Mathematics entered economics. Jevons, Walras, and later Alfred Marshall (1842–1924) expressed economic ideas as mathematical functions, derivatives, and optimisation problems. Marshall’s Principles of Economics (1890) became the standard textbook for half a century and gave us the supply-and-demand diagrams still used today.

Edinburgh Connection

Edinburgh’s intellectual tradition — with its emphasis on systematic, evidence-based inquiry — shaped the reception of marginalism in Britain. Marshall himself acknowledged debts to the Scottish philosophical tradition, and Edinburgh’s economics department adopted the new mathematical methods earlier than many British universities.


Part II — The Computation

Setting Up

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize

Utility and Diminishing Marginal Utility

A consumer gets satisfaction — utility — from consuming goods. The key insight of the marginalists is that utility increases with consumption but at a decreasing rate: the first slice of cake is heavenly; the tenth is merely okay; the twentieth might make you ill.

We model this with a utility function. A common choice:

\[u(x) = x^{0.5}\]

The marginal utility is the derivative: \(u'(x) = 0.5 \cdot x^{-0.5}\), which is positive but decreasing.

x = np.linspace(0.01, 10, 200)

fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))

# Total utility
axes[0].plot(x, x**0.5, color='steelblue', linewidth=2.5)
axes[0].set_xlabel('Quantity consumed', fontsize=12)
axes[0].set_ylabel('Utility u(x)', fontsize=12)
axes[0].set_title('Total Utility: Increasing but Concave', fontsize=13)
axes[0].grid(True, alpha=0.3)

# Marginal utility
axes[1].plot(x, 0.5 * x**(-0.5), color='coral', linewidth=2.5)
axes[1].set_xlabel('Quantity consumed', fontsize=12)
axes[1].set_ylabel("Marginal utility u'(x)", fontsize=12)
axes[1].set_title('Marginal Utility: Positive but Falling', fontsize=13)
axes[1].grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

print("This is Jevons's 'law of diminishing marginal utility'.")
print("Each additional unit gives less satisfaction than the one before.")

The Diamond-Water Paradox Resolved

With diminishing marginal utility, the paradox dissolves. Water is abundant (high total utility but low marginal utility); diamonds are scarce (lower total utility but high marginal utility). Price reflects marginal utility, not total utility.

# Same utility function for simplicity: u(x) = x^0.5
water_quantity = 100   # abundant
diamond_quantity = 0.5 # scarce

total_utility_water = water_quantity**0.5
total_utility_diamond = diamond_quantity**0.5
marginal_utility_water = 0.5 * water_quantity**(-0.5)
marginal_utility_diamond = 0.5 * diamond_quantity**(-0.5)

print("=== The Diamond-Water Paradox ===")
print(f"\nWater (quantity = {water_quantity}):")
print(f"  Total utility:    {total_utility_water:.2f} (HIGH — water is essential)")
print(f"  Marginal utility: {marginal_utility_water:.4f} (LOW — one more glass adds little)")
print(f"\nDiamonds (quantity = {diamond_quantity}):")
print(f"  Total utility:    {total_utility_diamond:.2f} (low)")
print(f"  Marginal utility: {marginal_utility_diamond:.4f} (HIGH — one more diamond adds a lot)")
print(f"\nPrice reflects MARGINAL utility, not total utility.")
print(f"That's why diamonds cost more than water, even though water is more useful overall.")

Consumer Choice: Two Goods and a Budget

The marginalists’ core problem: a consumer has income \(m\) and must choose how much to buy of two goods (\(x_1\) and \(x_2\)) with prices \(p_1\) and \(p_2\). They maximise utility subject to a budget constraint:

\[\max_{x_1, x_2} \; u(x_1, x_2) \quad \text{subject to} \quad p_1 x_1 + p_2 x_2 \leq m\]

We’ll use the Cobb-Douglas utility function:

\[u(x_1, x_2) = x_1^a \cdot x_2^{(1-a)}\]

where \(a\) governs how much the consumer values good 1 relative to good 2.

First, let’s visualise the indifference curves and the budget line.

# Parameters
a = 0.4    # preference weight on good 1
p1 = 2     # price of good 1
p2 = 3     # price of good 2
m = 120    # income

def utility(x1, x2, a=a):
    return x1**a * x2**(1 - a)

# Budget line: x2 = (m - p1*x1) / p2
x1_budget = np.linspace(0, m/p1, 200)
x2_budget = (m - p1 * x1_budget) / p2

# Indifference curves
x1_grid = np.linspace(0.1, 70, 200)
fig, ax = plt.subplots(figsize=(8, 6))

for u_level in [5, 10, 15, 20, 25]:
    # x2 = (u_level / x1^a) ^ (1/(1-a))
    x2_ic = (u_level / x1_grid**a) ** (1 / (1 - a))
    ax.plot(x1_grid, x2_ic, color='steelblue', alpha=0.4, linewidth=1)

ax.plot(x1_budget, x2_budget, 'r-', linewidth=2.5, label='Budget constraint')

ax.set_xlabel('Good 1 ($x_1$)', fontsize=12)
ax.set_ylabel('Good 2 ($x_2$)', fontsize=12)
ax.set_title('Indifference Curves and Budget Constraint', fontsize=13)
ax.set_xlim(0, 70)
ax.set_ylim(0, 50)
ax.legend(fontsize=11)
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()

Solving the Consumer’s Problem with scipy.optimize.minimize

We want to find the bundle \((x_1^*, x_2^*)\) that maximises utility on the budget line. Since minimize minimises, we minimise negative utility.

def neg_utility(x):
    """Negative utility (because we use minimize, not maximize)."""
    x1, x2 = x
    if x1 <= 0 or x2 <= 0:
        return 1e10  # penalty for non-positive consumption
    return -utility(x1, x2)

# Budget constraint: p1*x1 + p2*x2 <= m
budget_constraint = {'type': 'ineq', 'fun': lambda x: m - p1*x[0] - p2*x[1]}

# Bounds: both goods must be positive
bounds = [(0.01, None), (0.01, None)]

# Solve
result = minimize(neg_utility, x0=[10, 10], method='SLSQP',
                  bounds=bounds, constraints=budget_constraint)

x1_star, x2_star = result.x
u_star = utility(x1_star, x2_star)

print(f"Optimal bundle:")
print(f"  x1* = {x1_star:.2f} (spending £{p1*x1_star:.2f})")
print(f"  x2* = {x2_star:.2f} (spending £{p2*x2_star:.2f})")
print(f"  Total spending: £{p1*x1_star + p2*x2_star:.2f} (budget = £{m})")
print(f"  Utility: {u_star:.4f}")

# Analytical solution for Cobb-Douglas: x1* = a*m/p1, x2* = (1-a)*m/p2
x1_analytical = a * m / p1
x2_analytical = (1 - a) * m / p2
print(f"\nAnalytical solution: x1* = {x1_analytical:.2f}, x2* = {x2_analytical:.2f}")
print(f"Match: {np.allclose([x1_star, x2_star], [x1_analytical, x2_analytical], rtol=0.01)}")
# Visualise the solution
fig, ax = plt.subplots(figsize=(8, 6))

for u_level in [5, 10, u_star, 20, 25]:
    x2_ic = (u_level / x1_grid**a) ** (1 / (1 - a))
    alpha_val = 1.0 if np.isclose(u_level, u_star) else 0.3
    lw = 2.5 if np.isclose(u_level, u_star) else 1
    ax.plot(x1_grid, x2_ic, color='steelblue', alpha=alpha_val, linewidth=lw)

ax.plot(x1_budget, x2_budget, 'r-', linewidth=2.5, label='Budget constraint')
ax.plot(x1_star, x2_star, 'ko', markersize=10, zorder=5)
ax.annotate(f'Optimum\n({x1_star:.1f}, {x2_star:.1f})',
            xy=(x1_star, x2_star), xytext=(x1_star + 10, x2_star + 5),
            fontsize=11, arrowprops=dict(arrowstyle='->', color='black'),
            bbox=dict(boxstyle='round,pad=0.3', facecolor='lightyellow', edgecolor='gray'))

ax.set_xlabel('Good 1 ($x_1$)', fontsize=12)
ax.set_ylabel('Good 2 ($x_2$)', fontsize=12)
ax.set_title('Consumer Optimisation: Highest Indifference Curve on the Budget Line', fontsize=13)
ax.set_xlim(0, 70)
ax.set_ylim(0, 50)
ax.legend(fontsize=11)
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()

Deriving the Demand Curve Computationally

Marshall’s great achievement was deriving the demand curve from the theory of consumer choice. As the price of good 1 rises, the consumer buys less of it. We can trace this out by solving the optimisation problem at many different prices.

# Vary p1 and compute optimal x1 at each price
p1_range = np.linspace(0.5, 10, 30)
x1_demand = []

for p1_val in p1_range:
    constraint = {'type': 'ineq', 'fun': lambda x, p=p1_val: m - p*x[0] - p2*x[1]}
    res = minimize(neg_utility, x0=[10, 10], method='SLSQP',
                   bounds=[(0.01, None), (0.01, None)],
                   constraints=constraint)
    x1_demand.append(res.x[0])

x1_demand = np.array(x1_demand)

# Also compute analytical demand: x1* = a*m/p1
x1_analytical_demand = a * m / p1_range

fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(x1_demand, p1_range, 'o', color='steelblue', markersize=6, label='Numerical (scipy)')
ax.plot(x1_analytical_demand, p1_range, '-', color='coral', linewidth=2, label='Analytical')
ax.set_xlabel('Quantity demanded ($x_1$)', fontsize=12)
ax.set_ylabel('Price ($p_1$)', fontsize=12)
ax.set_title('The Demand Curve — Derived from Utility Maximisation', fontsize=13)
ax.legend(fontsize=11)
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()

print("The demand curve slopes downward — exactly as Marshall drew it in 1890.")
print("But now we've DERIVED it from individual optimisation, not assumed it.")

Part III — Exercises

Exercise 1 — Income and Substitution Effects

When the price of good 1 rises, two things happen: (1) the consumer is effectively poorer (income effect), and (2) good 1 is now relatively more expensive (substitution effect).

Using \(a = 0.4\), \(p_2 = 3\), \(m = 120\):

(a) Compute the optimal \(x_1^*\) at \(p_1 = 2\) and at \(p_1 = 4\). What is the total change \(\Delta x_1\)?

(b) To isolate the substitution effect, compute the “compensated” demand: at the new price \(p_1 = 4\), how much income would the consumer need to achieve the same utility as before? (Use minimize to find the minimum expenditure that achieves the old utility level.) Then compute \(x_1\) at the new price with this compensated income.

(c) The substitution effect is the change in \(x_1\) from (a) to the compensated bundle. The income effect is the rest. Compute both and verify they sum to the total change.

(d) For a normal good, both effects reduce \(x_1\) when \(p_1\) rises. Verify this is the case here.

# Your answer here

Exercise 2 — Beyond Cobb-Douglas: CES Utility

The CES utility function allows different degrees of substitutability:

\[u(x_1, x_2) = \left( a \cdot x_1^\rho + (1-a) \cdot x_2^\rho \right)^{1/\rho}\]

where \(\rho = (\sigma - 1)/\sigma\) and \(\sigma\) is the elasticity of substitution.

(a) Define a CES utility function. Using \(a = 0.5\), \(p_1 = 2\), \(p_2 = 3\), \(m = 120\), solve the consumer’s problem for \(\sigma = 0.5, 1, 2, 5\). How does the optimal bundle change?

(b) Derive the demand curve for good 1 at each \(\sigma\) (vary \(p_1\) from 0.5 to 8). Plot all four demand curves on one graph. Which value of \(\sigma\) gives the most elastic (responsive) demand?

(c) What happens as \(\sigma \to \infty\)? (Hint: the goods become perfect substitutes.) What does the demand curve look like?

# Your answer here

Exercise 3 — From Smith to the Marginalists

In Module 1, we found market equilibrium by setting supply equal to demand. Now we can derive the demand curve from first principles.

(a) Suppose 100 identical consumers each have income \(m = 120\) and Cobb-Douglas utility with \(a = 0.4\) over two goods. Compute the aggregate demand curve for good 1: for each \(p_1\), total demand \(= 100 \times x_1^*(p_1)\).

(b) Define a linear supply curve: \(Q^S(p_1) = 500 + 200 p_1\).

(c) Use fsolve to find the market equilibrium price and quantity. Plot the supply and demand curves.

(d) In 2–3 sentences, explain how the marginalist approach provides microfoundations for the supply-and-demand model Smith described verbally.

# Your answer here

Part IV — Quiz

Conceptual Questions

Q1. The diamond-water paradox is resolved by recognising that price reflects:

  1. Total utility
  2. Marginal utility
  3. Labour content
  4. Production cost

Q2. The Marginalist Revolution of the 1870s shifted economics from:

  1. Trade theory to monetary theory
  2. Class-based analysis to individual optimisation
  3. Mathematics to verbal reasoning
  4. Microeconomics to macroeconomics

Q3. Diminishing marginal utility means:

  1. Total utility decreases with consumption
  2. Each additional unit provides less additional satisfaction than the last
  3. Utility is negative beyond some point
  4. Consumers always prefer less to more

Q4. Alfred Marshall’s main contribution was:

  1. Inventing calculus
  2. Synthesising marginalist theory into the supply-and-demand framework
  3. Disproving comparative advantage
  4. Founding the London School of Economics

Q5. The consumer’s optimal bundle is where:

  1. They spend all income on the cheaper good
  2. The highest indifference curve touches the budget constraint
  3. Marginal utility is zero
  4. The budget constraint crosses the origin

Computational Questions

Q6. For Cobb-Douglas utility \(u = x_1^{0.4} x_2^{0.6}\) with prices \(p_1 = 2\), \(p_2 = 3\), and income \(m = 120\), the optimal \(x_1^*\) is:

  1. \(0.4 \times 120 / 2 = 24\)
  2. \(0.6 \times 120 / 2 = 36\)
  3. \(120 / 2 = 60\)
  4. \(0.4 \times 120 / 3 = 16\)

Q7. To maximise utility using scipy.optimize.minimize, we minimise:

  1. Utility directly
  2. Negative utility
  3. The budget constraint
  4. Price times quantity

Q8. A demand curve derived from utility maximisation slopes downward because:

  1. Firms produce less at higher prices
  2. Higher prices reduce the consumer’s purchasing power and make the good relatively more expensive
  3. Government regulations limit demand
  4. Utility functions are always linear

Q9. In a constrained optimisation, the SLSQP method is used because:

  1. It is the fastest method
  2. It handles both bounds and equality/inequality constraints
  3. It doesn’t require a starting guess
  4. It only works with two variables

Q10. For Cobb-Douglas utility, the share of income spent on good 1 is:

  1. Always 50%
  2. Equal to the exponent \(a\)
  3. Depends on the price ratio
  4. Equal to 1 minus the price ratio

Quiz Answers

Click to reveal answers

Q1. (b) Price reflects marginal utility, not total utility. Water has high total but low marginal utility (it’s abundant); diamonds have low total but high marginal utility (they’re scarce).

Q2. (b) The marginalists replaced the classical focus on classes (workers, capitalists, landlords) with a framework based on individual consumers and firms making optimising decisions.

Q3. (b) Diminishing marginal utility means each successive unit consumed adds less to total satisfaction — the 10th apple brings less joy than the 1st.

Q4. (b) Marshall’s Principles of Economics (1890) synthesised the marginalists’ ideas into the coherent supply-and-demand framework still used today.

Q5. (b) The consumer reaches the highest attainable indifference curve (utility level) that still touches the budget constraint — the tangency point.

Q6. (a) For Cobb-Douglas, \(x_1^* = a \cdot m / p_1 = 0.4 \times 120 / 2 = 24\).

Q7. (b) Since minimize finds minima, we minimise negative utility, which is equivalent to maximising utility.

Q8. (b) A higher \(p_1\) has both an income effect (consumer is poorer) and a substitution effect (good 1 is relatively more expensive), both reducing demand for a normal good.

Q9. (b) SLSQP (Sequential Least-Squares Quadratic Programming) handles bounds on variables and general inequality/equality constraints, making it suitable for budget-constrained optimisation.

Q10. (b) A remarkable property of Cobb-Douglas: the consumer always spends exactly fraction \(a\) of income on good 1, regardless of prices. This makes the demand function \(x_1^* = a m / p_1\).


Further Reading

  • Jevons, W.S. The Theory of Political Economy (1871), Chapter 3.
  • Backhouse, R. The Penguin History of Economics, Chapter 7 (“The Marginalist Revolution”).
  • Marshall, A. Principles of Economics (1890), Book III (on demand and utility).
  • Mas-Colell, A., Whinston, M., & Green, J. Microeconomic Theory, Chapter 3 (for the mathematically adventurous).

Next week: Keynes and the Great Depression — why the marginalists’ beautiful model of rational individuals couldn’t explain mass unemployment.