CHAPTER 7
UNCONSTRAINED OPTIMIZATION
        
Most of the optimizing problems in economics are constrained optimizing problems. In a constrained optimizing problem the economic unit optimizes an objective function given that certain constraints are to be satisfied.  For example, in the theory of production, the optimizing problem may be formulated as maximizing output for a given level of cost, or minimizing cost of production for a certain level of output. However, there are many occasions in which the problem may be that of finding the optimum values of an objective function with no constraint attached. Such problems are unconstrained optimizing problems. Examples of such problems are maximizing total revenue, maximizing profit, or minimizing cost. Problems of  this nature are simply problems of finding the critical values of a function in differential calculus.

Finding the critical values of a function is one of the best known and commonly applied areas of differential calculus. In this chapter the definitions and techniques of the preceding chapter will be utilized in finding  the critical points of functions and solving  some unconstrained optimizing problems in economics.

TOOL BOX
Mathematica Commands				Function
Solve[D[y, x] == 0, x]					Sets (dy/dx) = 0 and solves it for x
D[y, x]/. x-> a						Evaluates (dy/dx) at x = a.
D[y, {x, 2}]/. x->a					Evaluates ((dy^2)/((d^2) x)) at x = a.
Solve[{D[z,x] == 0, D[z,y]==0, {x,y}]			Sets ∂(z/∂)x = 0, ∂(z/∂)y= 0 and solves them for x and y
D[D[z, x], y]						Finds (Subscript[f, xy]) = ∂((z^2)/(∂x ∂y)) of the function z = f(x, y).
D[D[z, y], x]						Finds (Subscript[f, yx]) = ∂((z^2)/(∂y ∂x)) of the function z = f(x, y).
(({{D[D[z,  x],  x], D[D[z, x], y]}, {D[D[x, y], x], D[D[z, y],  y]}}))			Hessian matrix, H = (({{(Subscript[f, xx]), (Subscript[f, xy])}, {(Subscript[f, yx]), (Subscript[f, yy])}})) of z = f(x, y).
(({{D[D[z,  x],  x], D[D[z, x], y]}, {D[D[x, y], x], D[D[z, y],  y]}}))/.{x->a, y->b}		Hessian evaluated at x = a and y = b.

I.   The Critical Points: The Solve[D[y, x] == 0, x] Command
The critical points of a function are its maxima, minima, and inflection points. A function  f  is said to have a relative maxima at x = (Subscript[x, o]) if f((Subscript[x, o])) is the absolute maximum of  f  in some interval in the neighborhood of (Subscript[x, o]) which contains (Subscript[x, o]).  Similarly, f  is said to have a relative minimum at x = (Subscript[x, 1]) if f((Subscript[x, 1])) is the absolute minimum of  f  in some interval in the neighborhood of (Subscript[x, 1]) which contains (Subscript[x, 1]).  A maximum or a minimum of a function, whether relative or absolute, is called an extremum.  The following figure illustrates the critical points the function y = f(x) = x3 - 3x2 + 15. Based on the definition of the critical points, point (0, 15) is a relative maxima.  However, in the interval -1 < x < 1, this point is also an absolute maximum. Point (2, 11) is a relative minima.  However, in the interval 1 < x < 3, this point is also an absolute minimum.  Point (1, 13) is an  inflection point.  



The points (0, 15) and (2, 11) are also called interior extrema versus exterior extrema, which are usually located at the end points of a graph.

Derivatives and the Critical Points:  For a continuous function defined by y = f(x), the point ((Subscript[x, o]), f((Subscript[x, o]))) is an interior extremum if (Subscript[x, o]) is in the domain of the function and f ’((Subscript[x, o])) = 0. Therefore, to locate interior maxima or minima of a function we need only those values of x for which f ’(x) = 0. The exterior maxima or minima can be tested for by examining the end points of an interval.

Example:  Find the extrema of  f  defined by y = f(x) = x3 - 2x2 + x + 1 in the interval 0 < x < 2.  
Solution:  f ’(x) = 3(x^2) - 4x + 1 = 0. The solution of the quadratic form yields, (Subscript[x, 1]) = 1 and (Subscript[x, 2]) = (1/3).  Therefore, the points (1, 1) and ((1/3), (31/27)) are the interior extrema.  The endpoints of the function in the domain 0 < x < 2 are (0, 1) and (2, 3). Thus, these two points are exterior extrema.  To observe the points graphically, plot the function using the critical points and x and y intercepts as,


To solve the problem using Mathematica,
Clear[x,  y,  sol]
y =  x^3 - 2  x^2 + x + 1 ;
sol = Solve[D[y, x] == 0, x]
{{x -> (1/3)}, {x -> 1}}
y /. sol
{(31/27), 1}
To observe the points graphically, plot the function as,
Plot[y,  {x,  0, 2},  
          AxesLabel -> {"X",  "Y"}] 

The condition f '(x) = 0 locates the extrema points of the function  f, but it does not determine whether the points are maxima or minima. One convenient way to test whether an extremum is a maximum or a minimum is to use the second derivative test.

The second derivative of  f  at a point (Subscript[x, o]) shows the rate at which the slope of  f (x) changes at (Subscript[x, o]).  In fact, it represents the slope of the slope function at (Subscript[x, o]).  If the function has a maximum at (Subscript[x, o]), the slope of the curve at this point has to be horizontal or f '((Subscript[x, o])) = 0 and the slope of the slope at this point has to be negative, f "((Subscript[x, o])) < 0.  That is any move from (Subscript[x, o]) at any direction should be a downward move.  If the function has a minimum at (Subscript[x, o]), the slope of the curve at this point has to be horizontal or f  '((Subscript[x, o])) = 0 and the slope of the slope at this point has to be positive, f "((Subscript[x, o])) > 0.  That is any move from (Subscript[x, o]) at any direction should be an upward move.  If  f "((Subscript[x, o])) = 0, then the function f may have an inflection point at (Subscript[x, o]).  The three cases are presented below: 

Case 1: f '((Subscript[x, o])) = 0 and f "((Subscript[x, o])) < 0.  At (Subscript[x, o]), f(x) has a maximum.  

Example:  Test for the critical points of  y = f(x) = 2x - (x^2) in the interval 0 < x < 2. 
Solution:   The first derivative of the function is f '(x) = 2 - 2x and the second derivative is f "(x) = -2.   The first derivative has a zero at x = 1.  At this point slope of the function is zero, f '(1) = 0,  and f "(1) = -2 < 0.  Therefore, at (Subscript[x, o])= 1,  f  has a maximum.  The graph of the function below shows the critical point and the slope of the function in the neighborhood of the critical point.


Using Mathematica, 
Clear[x, y,  sol]
y = 2  x  -  x^2 ; 
sol = Solve[D[y, x] == 0,  x]
{{x -> 1}}
D[y, {x, 2}] /. sol
{-2}
Plot[y, {x, 0, 2}, AxesLabel -> {"X",  "Y"}]

Case 2: f '((Subscript[x, o])) = 0 and f "((Subscript[x, o])) > 0.  At (Subscript[x, o]), f(x) has a minimum.  

Example:  Test for the critical points of  y = f(x) = 2x + (x^2) in the interval  -2 < x < 0. 
Solution:   The first derivative of the function is f '(x) = 2 + 2x and the second derivative is f "(x) = 2.   The first derivative has a zero at (Subscript[x, o])= -1.  At this point slope of the function is zero, f '(-1) = 0,  and f "(-1) = 2 > 0.  Therefore, at (Subscript[x, o])= -1,  f  has a minimum.  The graph of the function below shows the critical point and the slope of the function in the neighborhood of the critical point.


Using Mathematica,
Clear[x, y,  sol]
y = 2  x  +  x^2 ; 
sol  =  Solve[D[y, x] == 0,  x]
{{x -> -1}}
D[y, {x, 2}] /. sol
{2}
Plot[y, {x, -2,  0}, 
            AxesLabel -> {"X",  "Y"}]

Case 3: f "((Subscript[x, o])) = 0.  At (Subscript[x, o]), f(x) may have an inflection point.  

Example:  Test for the critical points of  y = f(x) = 3x - x3  in the interval -3 < x < 3. 
Solution:   The first derivative of the function is f '(x) = 3 - 3(x^2) and the second derivative is f "(x) = -6x.   The first derivative has zeroes at (Subscript[x, 1]) = -1 and (Subscript[x, 2]) = 1.  The signs of the second derivative of the function at these points rae f "(-1) = 6 > 0 and f "(1) = -6 < 0, respectively.  Therefore, the function has a minima at (Subscript[x, 1]) = -1 and a maxima at (Subscript[x, 2]) = 1.  At (Subscript[x, o])= 0, f "(0) = 0.  The inspection of the graph below shows that  f  has an inflection point at (0, 0).


Clear[x, y, sol]
y = 3  x  -  x^3 ; 
sol  =  Solve[D[y, x] == 0,  x]
{{x -> -1}, {x -> 1}}
D[y, {x, 2}] /. sol
{6, -6}
D[y, {x, 2}] /. x -> 0
0
Plot[y, {x, -3, 3}, AxesLabel -> {"X",  "Y"}]
The preceding discussion shows that, f '(x) = 0 locates the relative extrema of a function and the sign of f "(x) decides whether the point is a maximum or a minimum at the extrema ((Subscript[x, o])).  If f '((Subscript[x, o])) = 0 and f "((Subscript[x, o])) < 0, the function  f  has a maximum at (Subscript[x, o]).  If f '((Subscript[x, o])) = 0 and f "((Subscript[x, o])) > 0, the function f has a minimum at (Subscript[x, o]).  If f "((Subscript[x, o])) = 0 the function f may have an inflection point at (Subscript[x, o]).  The first derivative test of extrema is called the first order condition and the second derivative test is called the second order condition for relative extrema. 

Example: Find the critical points of y = f(x) = x3 - 3x2 - 72x + 8 and test for maxima and minima.
Solution:  The first order condition is y' = f '(x) = 3x2 - 6x - 72 = 0.  The quadratic form has zeroes at x1 = 6 and x2 = -4.  Therefore the extrema are (6, -316) and (-4, 184).  To test whether these points are maxima or minima, find the second derivative and test for the second order condition.  The second derivative is y" = f "(x) = 6x - 6.  Evaluated at the critical points f "(6) = 30 > 0 and f "(-4) = -30 < 0.  Thus the point (6, -316) is a relative minimum and the point (-4, -392) is a relative maximum.  At x = 1, f"(1) = 0 and the point (1, -66) is an inflection point.   The graph below shows the critical points.



Using Mathematica, the solution is
Clear[x,  y]
y  =  x^3  -  3  x^2  -  72  x  +  8;
sol = Solve[D[y,  x] == 0,  x]
{{x -> -4}, {x -> 6}}
D[y,  {x,  2}] /. sol
{-30, 30}
D[y,  {x,  2}] /. sol
{-30, 30}
Plot[y,  {x,  -10,  12}, 
          AxesLabel -> {"X",  "Y"}]
Geometrically, the first order condition, f ' (x) = 0, implies that a tangent to the curve at the relative maximum or relative minimum is parallel to the x-axis. For a function to have a maximum at x = (Subscript[x, o]), the second order condition requires f "((Subscript[x, o])) < 0. This condition implies that, as x changes in the neighborhood of (Subscript[x, o]), the function f(x) changes at a decreasing rate (increases at a decreasing rate and decreases at a decreasing rate). Such a function is said to be concave upward.  Below, the graph of the y = f(x) = x3 - 3x2 - 72x + 8 at the neighborhood of (Subscript[x, o]) = -4 illustrates this point.


For a function f(x) to have a minimum at x = (Subscript[x, o]), the second order condition requires f "((Subscript[x, o])) > 0. This condition implies that, as x changes in the neighborhood of (Subscript[x, o]) that contains (Subscript[x, o]), the function f(x) changes at an increasing rate (decreases at an increasing rate and increases at an increasing rate). Such a function is said  to be convex upward.  Below, the graph of the y = f(x) = x3 - 3x2 - 72x + 8 at the neighborhood of (Subscript[x, o]) = 6 illustrates this point.


The second derivative test is a convenient way for finding the relative maxima and minima. However, the test fails if the second derivative vanishes at the critical point.  If  f "((Subscript[x, o])) = 0, one way to test for the relative extremum is to check the sign of  f "((Subscript[x, o])) in the neighborhood of (Subscript[x, o]).  If the sign of  f "(x) changes in the neighborhood of (Subscript[x, o]), the point is a relative extremum.  If the sign does not change, the point is an inflection point.

Example: Find the critical point of y = f(x) = x3, and test for maxima or minima.
Solution: y' = f '(x) = 3x2. Therefore, f(x) has a critical point at (Subscript[x, o]) = 0.   The second derivative test shows that f "(x) = 6x vanishes at x = (Subscript[x, o]), f "(0) = 0.  Therefore, the second-derivative test fails to determine maximum or minimum. To test for the sign of f '(x) in the neighborhood of (Subscript[x, o]) = 0, it is clear that f'(x) > 0 for x > 0 and for x < 0.  Since the sign of f '(x), or the slope of the function does not change in the neighborhood of (Subscript[x, o]) = 0, the point (0, 0) is an inflection point and not an extrema. The graph of the function illustrates this fact.



Example: Find the critical points of y = f(x) = x4.
Solution:  f(x) has a critical point at (Subscript[x, o]) = 0.  The second order condition shows that the second derivative of  f , f " (x ) = 12(x^2), vanishes at (Subscript[x, o]) = 0.  Therefore, the second-derivative test fails to determine minimum or maximum points.  However, the slope test in the neighborhood of (Subscript[x, o]) = 0 shows that f '(x) < 0 for x < 0 and f '(x) > 0 for x > 0.  Since the slope of the function changes from negative to positive in the neighborhood of (Subscript[x, o]) = 0, the function has a relative minimum at (Subscript[x, o]) = 0.  The graph of the function illustrates this point.



Example:  Revenue Function
Demand for a product is given as Q = 100 - 2P.  Find the price and the quantity at which profit is maximized.  Prove that at this point price elasticity of demand equals -1.
Solution:  Total revenue TR = P.Q.  Using the given demand function, P = 50 - . 5Q and TR = 50Q - . 5(Q^2).  To maximize TR, find Q by solving (dTR/dQ) = 0 and test for the second order condition.  The solution of (dTR/dQ) = 50 - Q = 0 is Q = 50.  Therefore, Q = 50 is the critical point. The second derivative of TR yields (((d^2) TR)/(dQ^2)) = -1.  Since the second derivative is negative, at Q = 50 the revenue function has a maximum.  At Q = 50, P = 25.  To find the price elasticity of demand at this point, (Subscript[ϵ, p]) = (dQ/dP)(P/Q).  Since (dQ/dP) = -2 (slope of the demand curve), (Subscript[ϵ, p]) = -2(25/50) = -1.

Example: Theory of Firm   
A firm in a perfectly competitive market has the cost function, TC = c(Q), where TC is the total cost and Q is output. What is the optimum level of output, if the objective of the firm is maximizing profit?
Solution:  The total profit of the firm (TP) is total revenue (TR) minus total cost, where TR = P.Q.  Therefore, TP = TR - TC = P.Q - C(Q).  To maximize profit, the first order condition requires that derivative of TP with respect to Q to be equal to zero.  That is, (dTP/dQ) = P - C '(Q) = 0 or C '(Q) = P.  This means, to maximize the profit, a firm in a perfectly competitive market decides the output level by setting the marginal cost (MC = C '(Q)) equal to the market price (MC = P). The second order condition requires that (((d^2) TP)/(dQ^2))< 0.  Since (((d^2) TP)/(dQ^2)) = - C"(Q), the profit maximizing condition requires that C'(Q) > 0 or the marginal cost curve to be sloping upward at the profit maximizing point.

Example: Inventory Cost
A retailer has estimated that the cost for ordering and storing Q units of a products is TC(Q) = 3Q + (30000/Q).  The delivery truck can deliver at most 150 units per order, 1 ≤ Q ≤ 150.  Find the order size that will minimize the cost.
Solution:  Minimize TC with respect to Q.   If the Q is in the range 1 ≤ Q ≤ 150, the resulting number is the solution.  Otherwise, look for an absolute minimum for TC at Q = 1 or Q 150.  To minimize TC, set TC '(Q) = 0 and solve for Q.  TC '(Q) = 3 + ((-30000)/(Q^2)) = 0.  Solving for Q gives Q = 100.  To test for second order condition, find TC "(Q) and evaluate it at Q = 100.  TC "(Q) = (60000/(Q^3)).  Evaluated at Q = 100, TC "(100) = (3/50) > 0.  That is at Q = 100, the function has a minimum.
Using Mathematica, the solution is found as,
Clear[TC,  Q,  sol]
TC = 3  Q + 30000/Q;
sol = Solve[D[TC,  Q] == 0,  
            Q]   
{{Q -> -100}, {Q -> 100}}
Q = 100 will be the solution, if it satisfies the second order condition.  To test for the second order condition, find the second derivative of TC and evaluate it at Q = 100.  If the resulting number is positive, Q = 100 is the solution to the problem.
D[TC,  {Q,  2}] /. sol
{-(3/50), (3/50)}

Example: Total Cost and Perfectly Competitive Market
A firm in a perfectly competitive market has the cost function, TC(q) = (1/3)q3 - 3.5q2 + 26q + 10, where TC is the total cost and q is output. What is the optimum level of output, if the market price of the good is $20?
Solution:  Total profit (TP), total cost (TC), and total revenue (TR) are all functions of q,  TP(q) = TR(q) - TC(q).  To maximize profit, set the first derivative of TP(q), or marginal profit, equal to zero.  This will set the first derivative of TC(q) (marginal cost), equal to the first derivative of TR(q) (marginal revenue).   In a perfectly competitive market, price and marginal revenue are the same.  Thus, the profit maximizing quantity is decided by setting price equal to marginal cost.  The marginal cost is TC '(q) = (q^2) - 7q + 26.   Solving (q^2) - 7q + 26 = 20 gives q = 1 and q = 6.  To test for the second order condition, the second derivative of TP(q) = -TC "(q) .  To have maximum profit at the critical points, -TC "(q) has to be negative or TC "(q) > 0.   TC"(1) = -5 < 0 and TC"(6) = 5 > 0.  Therefore, the profit maximizing solution is q = 5.
Using Mathematica,
Clear[TC,  q,  sol]
TC  =  (1/3) q^3  - 3.5  q^2 + 26  q + 10;
sol = Solve[D[TC,  q] == 20,  q]
{{q -> 1.`}, {q -> 6.`}}
D[TC,  {q,  2}] /. sol
{-5.`, 5.`}
The first-order condition results in two values for q, q = 1 and q = 6.  It is obvious from the second-order condition that the only acceptable solution is q = 6.


Example: Monopoly
A firm operating in a monopoly market has the cost function, TC = c(q), where TC is the total cost and q is output. What is the optimum level of output, if the objective of the firm is to maximize profit?
Solution:  If the firm is a monopoly, the price of the product is a function of output, and the total profit (TP) is TP(q) = P(q).q - C(q) = TR(q) - TC(q) where, TR(q) is total revenue as a function of q.  The first order condition requires that TP'(q) = TR'(q) - TC'(q) = 0.  TR'(q) is the marginal revenue (MR) and TC'(q) is the marginal cost (MC).  Therefore, the first-order condition requires that MR = MC.  Differentiating TR(q) with respect to q gives MR as, P(q) + q.P'(q).  Factor out p(q) to get, p(q)(1 - (q/p)p'(q)).  The term (q/p)p'(q) is the inverse of the price elasticity of demand ((Subscript[ϵ, p])).  Therefore, the profit-maximizing condition requires that (1 - (1/(Subscript[ϵ, p])))P = MC.  That is, to maximize profit, a monopolist sets its MC = MR = (1 - (1/(Subscript[ϵ, p])))P.  Since monopolies always sell at the elastic portion of their demand curve (1 -  (1/(Subscript[ϵ, p])))P < P.  For monopolist this results in selling less goods than if the industry were a perfectly competitive industry and selling at a higher price than perfectly competitive market.  The second order condition requires that (1 -  (1/( (Subscript[∈ , p]))))(dp/dq) -  C"(q) < 0.  (dp/dq) is the slope of the demand curve and is negative and (1 -  (1/(Subscript[ϵ, p]))) > 0.  Therefore, the second order condition requires that C"(q) > 0, or the marginal cost curve slope upward at the profit maximizing level of output.

Example: Monopoly
A monopoly has the cost function, TC = (1/3)q3 - 5q2 + 23q + 25, where C is the total cost and q is output. What is the optimum level of output, if the market demand is given as q = -2p + 90.
Solution: With the given market demand, p = -. 5q + 45.  Total revenue is TR = p.q = -. 5q2 + 45q.  Therefore, solve for q by setting MR = MC.  That is, (q^2) -10q + 23 = -q + 45, the solution of which is q = -2 and q = 11.  The only acceptable solution is q = 11.  To test for the second order condition find TC "(11).  TC "(Q) = 2q - 10 and TC "(11) = 12.  Since TC "(11) > 0, at q = 11 MC slopes upward and this quantity is the profit maximizing or loss minimizing quantity.
Using Mathematica, the solution is
Clear[TR, TC, q,  sol]

        TC = (1/3) q^3 - 5  q^2 + 23  q + 25;

        TR = - .5 q^2 + 45  q;
sol  =  Solve[D[TR, q] == D[TC, q], q]
{{q -> -2.291502622129181`}, {q -> 
            8.291502622129181`}}
D[TC,  {q,  2}] /. sol
{-11.583005244258363`, 9.583005244258363`}

Problems:
1.   Find the extreme points of the following functions and test for maximum and/or minimum.
       a) y = x2 - 6x + 5		
       b) y = -x2 + 6x - 5
       c) y = 2x3 - 15x2 + 36x + 10    
       d) y = x3 - 3x2 + 3x
       e) y = (x - 1)3                           
       f) y = (x2 - 1)2
       g) y = ln((x  +  1)/((x^2)  +  3))      
       h) z = x3 + 3x2y2 + y3
       i) z = (1 - x)2 + (1 - y)2             
       j) z = (x + y)3 -2xy
2.   A monopolistic firm faces the demand P = 100 - 2Q for its product    
a) Find the output level where the total revenue of the firm is maximum.
b) Prove that this point lies in the middle of the demand curve, where the price elasticity of demand is -1.
c) If marginal cost of the firm is MC = 20, what level of output will maximize the profit?
3.   The output (Q) of a single-product firm is related to its labor input (L) through the production function Q = 100L + 10L2 - L3
a)	Find the marginal product of labor.
b)	Find the maximum level of output.
c)	Find the inflection point of the function.
d)	Show that for the output levels below the inflection point, an increase in labor input increases output at an increasing rate. For output levels higher than the inflection point, an increase in labor increases output at a deceasing rate.  
4.   The cost function of a single-product firm is given as C = (1/3)Q3 - 3.5Q2 + 6Q where Q is output and C is total cost.
a)	Find the inflection point of the cost function.
b)	Show that for output levels below the inflection point an increase in output increases total cost at a decreasing rate. For output levels over the inflection point an increase in output increases cost at an increasing rate.
5.  A profit-maximizing monopoly is facing market demand, Q = 50 - (1/2)P and a total cost function, TC = (1/12)(Q^3) - 5(Q^2) + 120Q + 30.  Find profit-maximizing price and quantity.


II.  The Critical Points of a Function of Two or More Variables: The Solve[{D[z,x] == 0, D[z,y]==0, {x,y}] Command
In the previous section we studied the critical points of functions with only one independent variable. The results of that section can be extended to the case of functions of several variables.  For the functions of two or more independent variables the first order and the second order conditions for the existence of extrema is analogous to the conditions of the previous section. However, here the functions represent surfaces in three or more dimensions. Therefore, the first order condition (parallel slope of tangent to f at the extrema) and the second order condition (upward convexity or concavity in the neighborhood of the extrema) should be satisfied not only in the direction of one axis but also in the direction of every relevant axes.  For example, a function of two independent variables, z = f(x, y) represents a surface in three dimensions x, y, and z. For  f  to have a maximum at the critical point p((Subscript[x, o]), (Subscript[y, o]), (Subscript[z, o])), the tangent to the surface at this point should be parallel to x-y plane at every direction.  The following figure illustrates a surface in three dimensions with a maximum.



The fact that the tangent to the surface at the point p((Subscript[x, o]), (Subscript[y, o]), (Subscript[z, o])) should be parallel to x-axis implies that we are holding fixed the value of y and we are setting ∂(f/∂)x = (Subscript[f, x]) = 0;  and the fact that the tangent to the surface at p((Subscript[x, o]), (Subscript[y, o]), (Subscript[z, o])) should be parallel to y axis implies that we are holding fixed the value of x and we are setting ∂(f/∂)y = (Subscript[f, y]) = 0. Therefore, for z = f(x, y) to have an  extrema at  p((Subscript[x, o]), (Subscript[y, o]), (Subscript[z, o])), the first order condition requires that (Subscript[f, x]) = (Subscript[f, y]) = 0 at this point.  The second order condition for z = f(x, y) to have a maximum at the critical point p((Subscript[x, o]), (Subscript[y, o]), (Subscript[z, o])) is that d2z to be negative definite at this point.  For z = f(x, y) to have a minimum at p((Subscript[x, o]), (Subscript[y, o]), (Subscript[z, o])), the second order condition requires that d2z to be positive definite at this point.  

To find d2z, find the total differential of dz = (Subscript[f, x])dx + (Subscript[f, y])dy.  This gives d2z = (Subscript[f, xx])dx2 + (Subscript[f, xy])dxdy + (Subscript[f, yx])dydx + (Subscript[f, yy])dy2.  Using the matrix notations this equation can be expressed in a quadratic form as (({{dx, dy}}))(({{(Subscript[f, xx]), (Subscript[f, xy])}, {(Subscript[f, yx]), (Subscript[f, yy])}}))(({{dx}, {dy}})).   A quadratic form is said to be positive definite if all the principal minors of the Hessian determinant, defined as H = (({{(Subscript[f, xx]), (Subscript[f, xy])}, {(Subscript[f, yx]), (Subscript[f, yy])}})) are positive.  A quadratic form is said to be negative definite if the principal minors of the Hessian determinant alternate in sign, beginning with a negative first principal minor.  Therefore, for  (({{dx, dy}}))(({{(Subscript[f, xx]), (Subscript[f, xy])}, {(Subscript[f, yx]), (Subscript[f, yy])}}))(({{dx}, {dy}})) to be positive definite the following should be satisfied: (Subscript[f, xx]) > 0 and (Subscript[f, xx])(Subscript[f, yy]) - (Subscript[f, yx])(Subscript[f, xy]) > 0.  The quadratic form will be negative definite if (Subscript[f, xx]) < 0 and (Subscript[f, xx])(Subscript[f, yy]) - (Subscript[f, yx])(Subscript[f, xy]) > 0.   If the pattern of the principal minors of  the quadratic form fits neither that of positive definite nor that of negative definite, then  f  is said to have a saddle point at the critical point.  A saddle point is a point on the surface where it is a maximum when viewed  against the background of xz-plane and is a minimum when viewed against the background of yz-plane, or vise versa.  The following graphs shows a saddle point.



A second, may be an easier, way to test for the positive or negative definiteness of a quadratic form is to use the eigenvalues of the matrix.  A quadratic form and its corresponding matrix A is said to be positive definite if and only if all the eigenvalues of A are positive.  A quadratic form and its corresponding matrix A is said to be negative definite if and only if all the eigenvalues of A are negative. 
The results of this section can be generalized to the case of functions with n independent variables z = f(x, y, w, .....).

Example:  Find the critical points of z = f(x, y) = xy - x\(TraditionalForm\`\^2\) -  y\(TraditionalForm\`\^2\) - 6x and test for the second order condition.
Solution:  The first order condition is ∂(f/∂)x=  (Subscript[f, x]) = y - 2x - 6 = 0 and ∂(f/∂)y =  (Subscript[f, y]) = x - 2y = 0.  Solving the two equations together yields,  x = -4, y = -2, and z = 12. Thus, the point (-4, -2, 12) is the extremum.  To test for the second order condition, form the Hessian H =(({{(Subscript[f, xx]), (Subscript[f, xy])}, {(Subscript[f, yx]), (Subscript[f, yy])}})) = (({{-2, 1}, {1, -2}})).  The principal minors of the Hessian are -2 and 3, respectively. Since the principal minors alternate in sign, with the first principal minor negative, the matrix is negative definite and the function has a maximum at the extremum.  The 3-D graph of the function shows the critical point.


To solve the problem using Mathematica,
Clear[x, y, z, sol]
z = x y - x^2 - y^2 -6x; 
sol = Solve[{D[z, x] == 0 , D[z, y]== 0}, {x, y}]
{{x -> -4, y -> -2}}
z/.sol
{12}
To test for the second order condition, evaluate the eigenvalues of the Hessian matrix at the critical point,
Eigenvalues[(({{D[D[z,  x],  x], D[D[z,  x],  y]}, {D[D[z,  y],  x], D[D[z,  y],  y]}}))]/.{sol}
{{{-3, -1}}}
Since both eigenvalues are negative, the quadratic form is negative definite and the critical point is a maximum.  
Note that,  in Mathematica, the second derivative of z with respect to x can be formulated as D[z, {x,  2}] or as D[D[z, x], x].  For the sake of harmony between mathematical and Mathematica notations I have adopted the latter form.  To view the graph of the function at the critical point, use the "Plot3D" command as,
Plot3D[z, {x, -15, 15}, {y, -15, 5}, 
          AxesLabel -> {"X", "Y", "Z"}]

Example:  Find the critical points of z = f(x, y) = x\(TraditionalForm\`\^2\) -  y\(TraditionalForm\`\^2\)  and test for maxima or minima.
Solution:  The first order condition is (Subscript[f, x]) = 2x = 0 and (Subscript[f, y]) = 2y = 0.  This gives x = y = z = 0 as the critical point.  To test for the second order condition, form H = (({{(Subscript[f, xx]), (Subscript[f, xy])}, {(Subscript[f, yx]), fyy}})) = (({{2, 0}, {0, 2}})) and do either an eigenvalue test or the principal minor test.  The determinants of the principal minors are 2 and -4, respectively.  Since the sign of the determinants does not match that of the positive or negative definiteness, the function has a saddle point at P(0, 0, 0).  The graph below show this fact.


To solve the problem using Mathematica, 
Clear[x,  y,  z,  sol]
z  =  x^2  -  y^2;
sol  =  
          Solve[{D[z,  x] == 0,  D[z,  y]  == 0},  {x,  y}]
{{x -> 0, y -> 0}}
z /. sol
{0}
Eigenvalues[(({{D[D[z,  x], x], D[D[z, x], y]}, {D[D[x, y], x], D[D[z, y],  y]}}))]/.{sol}
{{{-2, 2}}}
The graph of the function use "Plot3D" command as, 
Plot3D[x^2  -  y^2, {x, -5, 5}, {y, -5, 5}, 
          AxesLabel -> {"X", "Y", "Z"}]

Do More Practice:
1- Change the function to z = (x^2) + (y^2), find the extermum, and graph the function.
2- Change the function to z = -(x^2) - (y^2), find the extermum, and graph the function.

Example:  Find the critical points of z = f(x, y) = -x\(TraditionalForm\`\^3\) + 9xy -  y\(TraditionalForm\`\^3\) and test for the second order condition.
Solution:  The first order condition gives (Subscript[f, x]) = -3(x^2) + 9y = 0 and (Subscript[f, y]) = 9x - 3(y^2) = 0.   Solving the two equations together results in two critical points (0, 0, 0) and (3, 3, 27).  To test for the second order condition, form the H = (({{(Subscript[f, xx]), (Subscript[f, xy])}, {(Subscript[f, yx]), (Subscript[f, yy])}})) = (({{-6 x, 9}, {9, -6 y}})).  Evaluate H at everyone of the critical points and do either an eigenvalues test or principal minor test to decide whether the critical points are maxima, minima, or saddle point.  At (0, 0, 0), H = (({{0, 9}, {9, 0}})) and the determinant of the principal minors are 0 and -81, respectively.  This doesn't fit any pattern of positive or negative definiteness.  Therefore, at this point the function has a saddle point.  At (3, 3, 27), H = (({{-18, 9}, {9, -18}})).  The determinant of the principal minors are -18 and 243.  Since the principal minors alternate in sign, starting with a negative sign, at (3, 3, 27) H is negative definite and the function has a local maximum.  
To solve the problem using Mathematica,
Clear[x, y, z, sol]

        z = -x^3 + 9  x y - y^3;

        sol = N[Solve[{D[z, x] == 0, D[z, y] == 0}, {x, y}]]
{{x -> 0.`, y -> 0.`}}
z /. sol
{0.`}
Eigenvalues[(({{D[D[z,  x],  x], D[D[z,  x],  y]}, {D[D[z,  y],  x], D[D[z,  y],  y]}}))]/.{sol}
{{{-2, 2}}}
Plot3D[z, {x, -5, 5}, {y, -5, 5}, 
          AxesLabel -> {"X", "Y", "Z"}]
The eigenvalues test shows that at (0, 0, 0) the eigenvalues are -9 and +9.  Therefore, at this point the function has a saddle point.  At (3, 3, 27), the eigenvalues are -27 and -9.  Since both eigenvalues are negative, H is negative definite and the function has a maximum at this point.

Example:  Utility Function
A consumer has the utility function U = u(x, y), where x and y are the quantities of two consumption goods. Maximize the consumer utility, assuming that the consumer is not bound by the budget (has unlimited budget). 
Solution:  The first order condition for utility maximization yields Ux = Uy = 0, where Ux and Uy are the marginal utilities of x and y, respectively.  Therefore, for an unconstrained maximization of utility, consumer consumes x and y up to the level that marginal utilities of the goods are zero, or the consumer is satiated.   That is, with no budget constraint or with no prices paid for x and y, to maximize utility, the consumer consumes the goods as long as the marginal utilities received from the goods are positive.  The second order condition requires that (({{Uxx, Uxy}, {Uyx, Uyy}})) to be negative definite.  Since Uxy = Uyx, the principal minors rule for the second order condition requires Uxx < 0  and (UxxUyy- Uxy\(TraditionalForm\`\^2\)) > 0.  These two conditions together imply that  Uyy is also negative  (Uyy < 0). That is, the marginal utility of x and y decrease as the consumer consumes more and more of x and y.  In economics this is called the law of diminishing marginal utility.     

Problems:
1.  A consumer has a hypothetical utility function U = lnxy, where x and y are quantities of two goods sold  at market prices of $2 and $3 respectively.  Suppose that the consumer's budget is non-binding (unlimited budget).
      a)   Set up the consumer utility maximizing problem and find the optimal solution.   
      b)   Test for the second order condition.
 2.   The production function of a firm in a perfectly competitive market is given as Q = Q(K, L).
       a)   Prove that, to maximize profit, the firm will hire inputs up to the level where the value of the marginal 	product of each input is equal to its  price.             
       b)   Prove that the firm  will have a profit if and only if the degree of homogeneity of production function is 	higher than one.       
3.     For the Cob-Douglas production function Q = A\(TraditionalForm\`L\^ .75\)\(TraditionalForm\`K\^ .25\)
        a)    Find the marginal rate of technical substitution of labor for capital. (Hint: Marginal rate of technical substitution of labor for capital,  MRTSLK = ((MPK)/(MPL)) where, MPK and MPL are the marginal products of capital and labor, respectively. MRTS measures the reduction in one input per unit increase in the other input that is just sufficient to maintain a constant level of output).
         b)    Show that, as capital is substituted for labor, MRTSLK declines.
4.  For each of the following hypothetical utility functions:
1-	U = lnxy
2-	U = 100lnxy - (x + y)
a)	Find the values of x and y that will maximize utility.
b)	Test for the second order conditions.
c)	If the market price of x and y are given as px and py respectively, find the elasticity of substitution of  y for x.