Profit Maximization

Hal R. Varian
January, 1992

Maximizing profit

Let's find the profit-maximizing choice for the production function x^(1/2).
We start by defining the production function

f[x_] := x^(1/2)

Profits as a function of x are

Profit[x_,p_,w_] := p f[x] - w x

Let's plot this for p=w=1:

Plot[Profit[x,1,1],{x,.001,1}]

In  order to find the profit-maximizing level of input, we solve for that x that makes the derivative of profit equal to zero:

Solve[D[Profit[x,1,1],x]==0,x]

Note that the solutions to Solve are a list of solutions; in this case the list has only one element in it: 1/4.   In order to find the input demand function, we can do this same calculation for arbitrary values of p and w:

Solve[D[Profit[x,p,w],x]==0,x]

Of course, we should always check the second-order condition to make sure that we really have a maximum.

D[Profit[x,p,w],{x,2}]

When x is positive, this is certainly a negative number

The profit function

Finally, we want to calculate the profit function for this technology.  In order to do that,  we take the the expression for profit and substitute the optimized value of x.  In Mathematica, you substitute for a value by using the notation /.

Profit[x,p,w]/.{x->p^2/(4 w^2)}

The Cobb-Douglas profit function

We can do the same sort of thing when there are several factors.  For example, consider  the Cobb-Douglas technology

f[x1_,x2_] := x1^(1/4) x2^(1/4)

The profit function is

Profit[x1_,x2_,p_,w1_,w2_] := p f[x1,x2] - w1 x1 - w2 x2

We can plot profits as a function of the inputs, with prices all fixed at 1.  We will do both a 3-D plot and a contour plot:

Plot3D[Profit[x1,x2,20,1,1],{x1,0.01,80},{x2,0.01,80},Lighting->False,
ViewPoint->{2.107, -2.506, 0.854}]

ContourPlot[Profit[x1,x2,20,1,1],{x1,0.01,80},{x2,0.01,80},
ContourShading->False]

Let's solve for the optimal value of the two factor inputs.  Just as before, we take the derivatives with respect to each input, set them equal to zero, and then solve the resulting system of equations.  This time we'll give the solution a name so we can use it later

solution=Solve[{D[Profit[x1,x2,1,1,1],x1]==0,
D[Profit[x1,x2,1,1,1],x2]==0},{x1,x2}]

Notice that we have two solutions; only the positive one makes economic sense.  We select it by using [[1]] to take the first element of the list.

solution[[1]]

We can do the same calculation for arbitrary values of p, w1 and w2.  Since we know that we'll get two answers, we'll select the first one right off the bat and call it solution

solution = Solve[{D[Profit[x1,x2,p,w1,w2],x1]==0, 
D[Profit[x1,x2,p,w1,w2],x2]==0},
{x1,x2}][[1]]

The profit function

To find the profit function, we just substitute this solution back into the definition of profit:

Profit[x1,x2,p,w1,w2]/.%

Comparative statics

Once we have solved for an optimal choice, we want to see how it responds to changes in the economic environment.   In the current context that means examining how the demand functions respond to changes in prices.

In Mathematica the easiest way to do is is by using total derivatives.  Consider a function g[x,a].  The first-order condition that a maximum value of x must satisfy is

D[g[x,a],x]==0

Totally differentiating this gives us

Dt[D[g[x,a],x]]==0

Note the notation Mathematica uses.  Dt[a] would be written da in standard notation. 
    (1,1)                                  2                         2
g     [x,a] would be d g(x,a)/dx, the second derivative. 

Solving this for dx=Dt[x] gives us the answer we are after

Solve[Dt[D[g[x,a],x]]==0,Dt[x]]

In classical notation, this simply says that
                                                        g 12
                                   dx =    -da   ---
                                                       g11

Since we know that the denominator of this expression is negative because of the second-order conditions, the sign of the entire expression is determined by the mixed partial derivative in the numerator.

Profit maximization with one input

Let's apply this to a profit maximization problem.  We have

Profit[x_,p_,w_] := p f[x] - w x

Take the derivative of this expression and solve for Dt[x].

Solve[Dt[D[Profit[x,p,w],x]]==0,Dt[x]]

This expression shows us that x decrease when w increases and increases when p increases.

Maximization with several variables

The same logic applies if there are several variables.  The only tricky part is that the second order condition is messier.  Suppose that we have a function f[x1,x2,a] and we want to know how x1 and x2 respond to changes in a.  The FOCs are

FOC={D[f[x1,x2,a],x1]==0, D[f[x1,x2,a],x2]==0}

Take the derivative of this list with respect to a and solve for Dt[x1] and Dt[x2]

Solve[Dt[FOC],{Dt[x1],Dt[x2]}]

This expression is somewhat messy.  Luckily, the denominators in this expression are simply the determinant of the Hessian matrix of f.  We will verify this by direct calculation:

hess={{D[f[x1,x2,a],x1,x1], D[f[x1,x2,a],x1,x2]},
      {D[f[x1,x2,a],x2,x1], D[f[x1,x2,a],x2,x2]}}

MatrixForm[hess]

detHess=-Det[hess]

Now substitute solve for Dt[x1] and Dt[x2] again, substituting back into the total differential

Solve[Dt[FOC],{Dt[x1],Dt[x2]}]/.{detHess->HH}

Just as before, the response of the choice variable to the parameter depends on the mixed partial derivatives, and the sign of the denominator is determined automatically by the second order conditions.

Profit maximization with two factors

Now let h[x1,x2] be the production function and totally differentiate the FOCs

solution= Solve[{Dt[D[h[x1,x2]-w1 x1 - w2 x2,x1]]==0,
       Dt[D[h[x1,x2]-w1 x1 - w2 x2,x2]]==0},
       {Dt[x1],Dt[x2]}][[1]]

The determinant of the Hessian is just as before; we'll compute it and substitute it in as before:

detHess=-Det[{{D[h[x1,x2],x1,x1], D[h[x1,x2],x1,x2]},
      {D[h[x1,x2],x2,x1], D[h[x1,x2],x2,x2]}}]

solution/.{detHess->HH}

This gives us a very simple expression for the comparative statics result: the change in x1 is the change in w1 times the second derivative of the production function with respect to x2 plus the change in w2 times the  cross partial.