Consumer Theory

with Cobb Douglas Utility Function

We begin by telling Mathematica what the parameters (or constants) of the model are. Everything else will be treated as a variable.

SetAttributes[ρ, Constant]
SetAttributes[m, Constant]
SetAttributes[λ, Constant]

The Clear command tells Mathematica to wipe out any previous values associated with the parameters and variables of the problem.  Notice that the semi-colons at the end of input lines suppress the display of output.

Clear[ρ, m, u, x1, x2, p1, p2, λ, L];

We then state the consumer's problem by defining a two-good utility function

u = x1^ρ*x2^(1 - ρ);

To make the job easier, we will work with the logarithmic expression of the utility function

logu = ρ*Log[x1] + (1 - ρ)*Log[x2];

The budget constraint is m = p1 x1 + p2 x2 or, equivalently

bc = m - (p1*x1 + p2*x2);

We then form the Lagrangian

eqL = L == logu + λ*bc

The first order conditions of the problem are computed as

foc1 = D[eqL, x1]
foc2 = D[eqL, x2]
foc3 = D[eqL, λ]

Solving the system of equations we obtain the corresponding demand functions for x1 and x2

Solve[{foc1, foc2, foc3}, {x1, x2, λ}]

Plotting the demand functions with p in the vertical axis and x in the horizontal axis, and with given values for a and m

p1 = ρ*(m/x1); 
Plot[p1 /. {ρ -> 0.7, m -> 0.1}, {x1, 0.01, 0.1}, 
  AxesLabel -> {"x1", "p1"}, PlotLabel -> "Demand Curve for x1"]

p2 = (m - ρ*m)/x2; 
Plot[p2 /. {ρ -> 0.7, m -> 0.1}, {x2, 0.01, 0.1}, 
  AxesLabel -> {"x2", "p2"}, PlotLabel -> "Demand Curve for x2"]