Suppose that a consumer’s preferences can be represented by the utility function U = f(X, Y) where X and Y represent the amounts of goods X and Y consumed. Our consumer’s problem is to maximize utility subject to the constraint that total expenditures on the two goods equals income: I = PXX + PYY.

To solve this problem, we form the function V = f(X, Y) + l
(I - PXX - PYY). (This function is called a "Lagrangian" and the variable l
is known as the "Lagrange multiplier." As long as l
is not equal to zero, maximizing V is equivalent to maximizing U subject to the income constraint, since V and U are equivalent only for those values of X and Y for which the budget constraint is fulfilled: I - PXX - PYY = 0.) To maximize utility, all the partial derivatives of this Lagrange equation must be set equal to zero:

These three conditions represent three equations in the three unknowns—X, Y, and l
. We can use the first two equations to eliminate l
: From the first, we see that l
= and the second equation can also be solved for l
to obtain l
= . Since both of these expressions equal l
, they must equal each other: = . The terms in the numerators are the marginal utilities of goods X and Y, respectively, so this is the condition that we require. Maximum utility is achieved when the marginal utility per dollar of each good is the same: . Of course, the final equation implies that the consumer’s budget must be exhausted as well. (We assume that the second-order conditions for a maximum are fulfilled.)

Alternatively, the first two equations could be solved as follows. Add lPX to both sides of the first equation and lPY to both sides of the second to obtain ¶f/¶X = lPX and ¶f/¶Y = lPY. Next, divide the first of these equalities by the second to obtain . The term on the left, the ratio of the marginal utilities, is known as the "marginal rate of substitution," the rate at which a consumer is willing to substitute X for Y. In this formulation, we see that maximum utility requires that the consumer’s marginal rate of substitution be equal to the ratio of the prices of the two goods. That is, a consumer will adjust purchases of the two goods until her willingness to trade one for the other just matches the rate at which they can be traded in the marketplace, as given by the ratio of their prices.