Skip to main content
Mathematics LibreTexts

10.7: Optimization

  • Page ID
    108018
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Motivating Questions
    • How can we find the points at which \(f(x,y)\) has a local maximum or minimum?
    • How can we determine whether critical points of \(f(x,y)\) are local maxima or minima?
    • How can we find the absolute maximum and minimum of \(f(x,y)\) on a closed and bounded domain?

    We learn in single-variable calculus that the derivative is a useful tool for finding the local maxima and minima of functions, and that these ideas may often be employed in applied settings. In particular, if a function \(f\text{,}\) such as the one shown in Figure \(\PageIndex{1}\) is everywhere differentiable, we know that the tangent line is horizontal at any point where \(f\) has a local maximum or minimum. This, of course, means that the derivative \(f'\) is zero at any such point. Hence, one way that we seek extreme values of a given function is to first find where the derivative of the function is zero.

    fig_10_7_preview_1.svg

    Figure \(\PageIndex{1}\). The graph of \(y=f(x)\text{.}\)

    In multivariable calculus, we are often similarly interested in finding the greatest and/or least value(s) that a function may achieve. Moreover, there are many applied settings in which a quantity of interest depends on several different variables. In the following preview activity, we begin to see how some key ideas in multivariable calculus can help us answer such questions by thinking about the geometry of the surface generated by a function of two variables.

    Preview Activity \(\PageIndex{1}\)

    Let \(z = f(x,y)\) be a differentiable function, and suppose that at the point \((x_0, y_0)\text{,}\) \(f\) achieves a local maximum. That is, the value of \(f(x_0,y_0)\) is greater than the value of \(f(x,y)\) for all \((x,y)\) nearby \((x_0,y_0)\text{.}\) You might find it helpful to sketch a rough picture of a possible function \(f\) that has this property.

    1. If we consider the trace given by holding \(y=y_0\) constant, then the single-variable function defined by \(f(x, y_0)\) must have a local maximum at \(x_0\text{.}\) What does this say about the value of the partial derivative \(f_x(x_0,y_0)\text{?}\)
    2. In the same way, the trace given by holding \(x=x_0\) constant has a local maximum at \(y=y_0\text{.}\) What does this say about the value of the partial derivative \(f_y(x_0,y_0)\text{?}\)
    3. What may we now conclude about the gradient \(\nabla f(x_0,y_0)\) at the local maximum? How is this consistent with the statement “\(f\) increases most rapidly in the direction \(\nabla f(x_0,y_0)\text{?}\)”
    4. How will the tangent plane to the surface \(z = f(x,y)\) appear at the point \((x_0, y_0, f(x_0,y_0))\text{?}\)
    5. By first computing the partial derivatives, find any points at which \(f(x,y) = 2x - x^2 - (y + 2)^2\) may have a local maximum.

    Extrema and Critical Points

    One of the important applications of single-variable calculus is the use of derivatives to identify local extremes of functions (that is, local maxima and local minima). Using the tools we have developed so far, we can naturally extend the concept of local maxima and minima to several-variable functions.

    Definition \(\PageIndex{1}\)

    Let \(f\) be a function of two variables \(x\) and \(y\text{.}\)

    • The function \(f\) has a local maximum at a point \((x_0,y_0)\) provided that \(f(x,y) \leq f(x_0,y_0)\) for all points \((x,y)\) near \((x_0,y_0)\text{.}\) In this situation we say that \(f(x_0, y_0)\) is a local maximum value.
    • The function \(f\) has a local minimum at a point \((x_0,y_0)\) provided that \(f(x,y) \geq f(x_0,y_0)\) for all points \((x,y)\) near \((x_0,y_0)\text{.}\) In this situation we say that \(f(x_0, y_0)\) is a local minimum value.
    • An absolute maximum point is a point \((x_0,y_0)\) for which \(f(x,y)\leq f(x_0,y_0)\) for all points \((x,y)\) in the domain of \(f\text{.}\) The value of \(f\) at an absolute maximum point is the maximum value of \(f\text{.}\)
    • An absolute minimum point is a point such that \(f(x,y) \geq f(x_0,y_0)\) for all points \((x,y)\) in the domain of \(f\text{.}\) The value of \(f\) at an absolute minimum point is the minimum value of \(f\text{.}\)

    We use the term extremum point to refer to any point \((x_0,y_0)\) at which \(f\) has a local maximum or minimum. In addition, the function value \(f(x_0,y_0)\) at an extremum is called an extremal value. Figure \(\PageIndex{2}\) illustrates the graphs of two functions that have an absolute maximum and minimum, respectively, at the origin \((x_0,y_0) = (0,0)\text{.}\)

    zis4r2.svg zisr2.svg

    Figure \(\PageIndex{2}\). An absolute maximum and an absolute minimum

    In single-variable calculus, we saw that the extrema of a continuous function \(f\) always occur at critical points, values of \(x\) where \(f\) fails to be differentiable or where \(f'(x) = 0\text{.}\) Said differently, critical points provide the locations where extrema of a function may appear. Our work in Preview Activity \(\PageIndex{1}\) suggests that something similar happens with two-variable functions.

    Suppose that a continuous function \(f\) has an extremum at \((x_0,y_0)\text{.}\) In this case, the trace \(f(x,y_0)\) has an extremum at \(x_0\text{,}\) which means that \(x_0\) is a critical value of \(f(x,y_0)\text{.}\) Therefore, either \(f_x(x_0,y_0)\) does not exist or \(f_x(x_0,y_0) = 0\text{.}\) Similarly, either \(f_y(x_0,y_0)\) does not exist or \(f_y(x_0,y_0) = 0\text{.}\) This implies that the extrema of a two-variable function occur at points that satisfy the following definition.

    Definition \(\PageIndex{2}\)

    A critical point \((x_0,y_0)\) of a function \(f=f(x,y)\) is a point in the domain of \(f\) at which \(f_x(x_0,y_0) = 0\) and \(f_y(x_0,y_0) = 0\text{,}\) or such that one of \(f_x(x_0,y_0)\) or \(f_y(x_0,y_0)\) fails to exist.

    We can therefore find critical points of a function \(f\) by computing partial derivatives and identifying any values of \((x,y)\) for which one of the partials doesn't exist or for which both partial derivatives are simultaneously zero. For the latter, note that we have to solve the system of equations

    \begin{align*} f_x(x,y) & = 0\\[4pt] f_y(x,y) & = 0. \end{align*}

    Activity \(\PageIndex{2}\)

    Find the critical points of each of the following functions. Then, using appropriate technology, plot the graphs of the surfaces near each critical point and compare the graph to your work.

    1. \(\displaystyle f(x,y) = 2+x^2+y^2\)
    2. \(\displaystyle f(x,y) = 2 + x^2 - y^2\)
    3. \(\displaystyle f(x,y) = 2x-x^2-\frac{1}{4}y^2\)
    4. \(\displaystyle f(x,y) = |x| + |y|\)
    5. \(f(x,y) = 2xy - 4x + 2y - 3\text{.}\)

    Classifying Critical Points: The Second Derivative Test

    While the extrema of a continuous function \(f\) always occur at critical points, it is important to note that not every critical point leads to an extremum. Recall, for instance, \(f(x) = x^3\) from single variable calculus. We know that \(x_0=0\) is a critical point since \(f'(x_0) = 0\text{,}\) but \(x_0 = 0\) is neither a local maximum nor a local minimum of \(f\text{.}\)

    A similar situation may arise in a multivariable setting. Consider the function \(f\) defined by \(f(x,y) = x^2 - y^2\) whose graph and contour plot are shown in Figure \(\PageIndex{3}\). Because \(\nabla f = \langle 2x, -2y\rangle\text{,}\) we see that the origin \((x_0,y_0)=(0,0)\) is a critical point. However, this critical point is neither a local maximum or minimum; the origin is a local minimum on the trace defined by \(y=0\text{,}\) while the origin is a local maximum on the trace defined by \(x=0\text{.}\) We call such a critical point a saddle point due to the shape of the graph near the critical point.

    saddle.svg saddle_contours.svg

    Figure \(\PageIndex{3}\). A saddle point.

    As in single-variable calculus, we would like to have some sort of test to help us identify whether a critical point is a local maximum, local maximum, or neither.

    Activity \(\PageIndex{3}\)

    Recall that the Second Derivative Test for single-variable functions states that if \(x_0\) is a critical point of a function \(f\) so that \(f'(x_0)=0\) and if \(f''(x_0)\) exists, then

    • if \(f''(x_0) \lt 0\text{,}\) \(x_0\) is a local maximum,
    • if \(f''(x_0) > 0\text{,}\) \(x_0\) is a local minimum, and
    • if \(f''(x_0) = 0\text{,}\) this test yields no information.

    Our goal in this activity is to understand a similar test for classifying extreme values of functions of two variables. Consider the following three functions:

    \[ f_1(x,y) = 4-x^2-y^2, \ \ f_2(x,y) = x^2+y^2, \ \ f_3(x,y) = x^2-y^2. \nonumber \]

    You can verify that each function has a critical point at the origin \((0,0)\text{.}\) You should check this.

    zis4r2-1.svg zisr2-1.svg saddle-1.svg

    Figure \(\PageIndex{4}\). Three surfaces.
    1. The graphs of these three functions are shown in Figure \(\PageIndex{4}\), with \(z=4-x^2-y^2\) at left, \(z=x^2+y^2\) in the middle, and \(z=x^2-y^2\) at right. Use the graphs to decide if a function has a local maximum, local minimum, saddle point, or none of the above at the origin.
    2. There is no single second derivative of a function of two variables, so we consider a quantity that combines the second order partial derivatives. Let \(D = f_{xx}f_{yy} - f_{xy}^2\text{.}\) Calculate \(D\) at the origin for each of the functions \(f_1\text{,}\) \(f_2\text{,}\) and \(f_3\text{.}\) What difference do you notice between the values of \(D\) when a function has a maximum or minimum value at the origin versus when a function has a saddle point at the origin?
    3. Now consider the cases where \(D \gt 0\text{.}\) It is in these cases that a function has a local maximum or minimum at a point. What is necessary in these cases is to find a condition that will distinguish between a maximum and a minimum. In the cases where \(D \gt 0\) at the origin, evaluate \(f_{xx}(0,0)\text{.}\) What value does \(f_{xx}(0,0)\) have when \(f\) has a local maximum value at the origin? When \(f\) has a local minimum value at the origin? Explain why. (Hint: This should look very similar to the Second Derivative Test for functions of a single variable.) What would happen if we considered the values of \(f_{yy}(0,0)\) instead?

    Activity \(\PageIndex{3}\) provides the basic ideas for the Second Derivative Test for functions of two variables.

    The Second Derivative Test

    Suppose \((x_0,y_0)\) is a critical point of the function \(f\) for which \(f_x(x_0,y_0) = 0\) and \(f_y(x_0,y_0) = 0\text{.}\) Let \(D\) be the quantity defined by

    \[ D = f_{xx}(x_0,y_0) f_{yy}(x_0,y_0) - f_{xy}(x_0,y_0)^2. \nonumber \]
    • If \(D>0\) and \(f_{xx}(x_0,y_0) \lt 0\text{,}\) then \(f\) has a local maximum at \((x_0,y_0)\text{.}\)
    • If \(D>0\) and \(f_{xx}(x_0,y_0) > 0\text{,}\) then \(f\) has a local minimum at \((x_0,y_0)\text{.}\)
    • If \(D \lt 0\text{,}\) then \(f\) has a saddle point at \((x_0,y_0)\text{.}\)
    • If \(D = 0\text{,}\) then this test yields no information about what happens at \((x_0,y_0)\text{.}\)

    The quantity \(D\) is called the discriminant of the function \(f\) at \((x_0,y_0)\text{.}\)

    To properly understand the origin of the Second Derivative Test, we could introduce a “second-order directional derivative.” If this second-order directional derivative were negative in every direction, for instance, we could guarantee that the critical point is a local maximum. A complete justification of the Second Derivative Test requires key ideas from linear algebra that are beyond the scope of this course, so instead of presenting a detailed explanation, we will accept this test as stated. In Activity \(\PageIndex{4}\), we apply the test to more complicated examples.

    Activity \(\PageIndex{4}\)

    Find the critical points of the following functions and use the Second Derivative Test to classify the critical points.

    1. \(\displaystyle f(x,y) = 3x^3+y^2-9x+4y\)
    2. \(\displaystyle f(x,y) = xy + \frac{2}{x} + \frac{4}{y}\)
    3. \(f(x,y) = x^3 + y^3 - 3xy\text{.}\)

    As we learned in single-variable calculus, finding extremal values of functions can be particularly useful in applied settings. For instance, we can often use calculus to determine the least expensive way to construct something or to find the most efficient route between two locations. The same possibility holds in settings with two or more variables.

    Activity \(\PageIndex{5}\)

    While the quantity of a product demanded by consumers is often a function of the price of the product, the demand for a product may also depend on the price of other products. For instance, the demand for blue jeans at Old Navy may be affected not only by the price of the jeans themselves, but also by the price of khakis.

    Suppose we have two goods whose respective prices are \(p_1\) and \(p_2\text{.}\) The demand for these goods, \(q_1\) and \(q_2\text{,}\) depend on the prices as

    \begin{align} q_1 & = 150 - 2p_1 - p_2 \label{eq_good1}\\[4pt] q_2 & = 200 - p_1 - 3p_2. \label{eq_good2}} \end{align}

    The seller would like to set the prices \(p_1\) and \(p_2\) in order to maximize revenue. We will assume that the seller meets the full demand for each product. Thus, if we let \(R\) be the revenue obtained by selling \(q_1\) items of the first good at price \(p_1\) per item and \(q_2\) items of the second good at price \(p_2\) per item, we have

    \[ R = p_1q_1 + p_2q_2. \nonumber \]

    We can then write the revenue as a function of just the two variables \(p_1\) and \(p_2\) by using Equations \ref{eq_good1} and \ref{eq_good2}, giving us

    \begin{align*} R(p_1,p_2) & = p_1(150 - 2p_1 - p_2) + p_2(200 - p_1 - 3p_2)\\[4pt] & = 150p_1 + 200p_2 - 2p_1p_2 -2p_1^2 - 3p_2^2. \end{align*}

    A graph of \(R\) as a function of \(p_1\) and \(p_2\) is shown in Figure \(\PageIndex{5}\).

    fig_10_7_revenue.svg

    Figure \(\PageIndex{5}\). A revenue function.
    1. Find all critical points of the revenue function, \(R\text{.}\) (Hint: You should obtain a system of two equations in two unknowns which can be solved by elimination or substitution.)
    2. Apply the Second Derivative Test to determine the type of any critical point(s).
    3. Where should the seller set the prices \(p_1\) and \(p_2\) to maximize the revenue?

    Optimization on a Restricted Domain

    The Second Derivative Test helps us classify critical points of a function, but it does not tell us if the function actually has an absolute maximum or minimum at each such point. For single-variable functions, the Extreme Value Theorem told us that a continuous function on a closed interval \([a, b]\) always has both an absolute maximum and minimum on that interval, and that these absolute extremes must occur at either an endpoint or at a critical point. Thus, to find the absolute maximum and minimum, we determine the critical points in the interval and then evaluate the function at these critical points and at the endpoints of the interval. A similar approach works for functions of two variables.

    For functions of two variables, closed and bounded regions play the role that closed intervals did for functions of a single variable. A closed region is a region that contains its boundary (the unit disk \(x^2+y^2 \leq 1\) is closed, while its interior \(x^2+y^2 \lt 1\) is not, for example), while a bounded region is one that does not stretch to infinity in any direction. Just as for functions of a single variable, continuous functions of several variables that are defined on closed, bounded regions must have absolute maxima and minima in those regions.

    The Extreme Value Theorem

    Let \(f= f(x,y)\) be a continuous function on a closed and bounded region \(R\text{.}\) Then \(f\) has an absolute maximum and an absolute minimum in \(R\text{.}\)

    The absolute extremes must occur at either a critical point in the interior of \(R\) or at a boundary point of \(R\text{.}\) We therefore must test both possibilities, as we demonstrate in the following example.

    Example \(\PageIndex{1}\)

    Suppose the temperature \(T\) at each point on the circular plate \(x^2+y^2 \leq 1\) is given by

    \[ T(x,y) = 2x^2+y^2-y. \nonumber \]

    The domain \(R=\{(x,y):x^2+y^2 \leq 1\}\) is a closed and bounded region, as shown on the left of Figure \(\PageIndex{9}\), so the Extreme Value Theorem assures us that \(T\) has an absolute maximum and minimum on the plate. The graph of \(T\) over its domain \(R\) is shown in Figure \(\PageIndex{6}\). We will find the hottest and coldest points on the plate.

    fig_10_7_temperature_domain.svg fig_10_7_temperature.svg

    Figure \(\PageIndex{6}\). Domain of the temperature \(T(x,y) = 2x^2+y^2-y\) and its graph.

    If the absolute maximum or minimum occurs inside the disk, it will be at a critical point so we begin by looking for critical points inside the disk. To do this, notice that critical points are given by the conditions \(T_x= 4x=0\) and \(T_y=2y - 1=0\text{.}\) This means that there is one critical point of the function at the point \((x_0,y_0) =(0,1/2)\text{,}\) which lies inside the disk.

    We now find the hottest and coldest points on the boundary of the disk, which is the circle of radius 1. As we have seen, the points on the unit circle can be parametrized as

    \[ x(t) = \cos(t), \ y(t) = \sin(t), \nonumber \]

    where \(0\leq t \leq 2\pi\text{.}\) The temperature at a point on the circle is then described by

    \[ T(x(t), y(t)) = 2\cos^2(t) + \sin^2(t) - \sin(t). \nonumber \]

    To find the hottest and coldest points on the boundary, we look for the critical points of this single-variable function on the interval \(0\leq t\leq 2\pi\text{.}\) We have

    \begin{align*} \frac{dT}{dt} & = -4\cos(t)\sin(t) + 2\cos(t)\sin(t) -\cos(t)\\[4pt] & = -2\cos(t)\sin(t) - \cos(t) = \cos(t) (-2\sin(t) - 1) \\[4pt] & = 0. \end{align*}

    This shows that we have critical points when \(\cos(t) = 0\) or \(\sin(t) = -1/2\text{.}\) This occurs when \(t=\pi/2\text{,}\) \(3\pi/2\text{,}\) \(7\pi/6\text{,}\) and \(11\pi/6\text{.}\) Since we have \(x(t) = \cos(t)\) and \(y(t) = \sin(t)\text{,}\) the corresponding points are

    \(\bullet\ \ (x,y) = (0,1)\) when \(t = \frac{\pi}{2}\text{,}\)
    \(\bullet\ \ (x,y) = \left(\frac{\sqrt{3}}{2},-\frac{1}{2}\right)\) when \(t = \frac{11\pi}{6}\text{.}\)
    \(\bullet\ \ (x,y) = (0,-1)\) when \(t = \frac{3\pi}{2}\text{,}\)
    \(\bullet\ \ (x,y) = \left(-\frac{\sqrt{3}}{2},-\frac{1}{2}\right)\) when \(t = \frac{7\pi}{6}\text{.}\)

    These are the critical points of \(T\) on the boundary and so this collection of points includes the hottest and coldest points on the boundary.

    We now have a list of candidates for the hottest and coldest points: the critical point in the interior of the disk and the critical points on the boundary. We find the hottest and coldest points by evaluating the temperature at each of these points, and find that

    \(\bullet\ \ T\left(0,\frac{1}{2}\right) = -\frac{1}{4}\text{,}\)
    \(\bullet\ \ T\left(-\frac{\sqrt{3}}{2},-\frac{1}{2}\right) = \frac{9}{4}\text{,}\)
    \(\bullet\ \ T\left(0,1\right) = 0\text{,}\)
    \(\bullet\ \ T\left(-\frac{\sqrt{3}}{2},-\frac{1}{2}\right) = \frac{9}{4}\text{.}\)
    \(\bullet\ \ T\left(0,-1\right) = 2\text{,}\)

    So the maximum value of \(T\) on the disk \(x^2+y^2\leq 1\) is \(\frac{9}{4}\text{,}\) which occurs at the two points \(\left(\pm\frac{\sqrt{3}}{2},-\frac{1}{2}\right)\) on the boundary, and the minimum value of \(T\) on the disk is \(-\frac{1}{4}\) which occurs at the critical point \(\left(0,\frac{1}{2}\right)\) in the interior of \(R\text{.}\)

    From this example, we see that we use the following procedure for determining the absolute maximum and absolute minimum of a function on a closed and bounded domain.

    • Find all critical points of the function in the interior of the domain.
    • Find all the critical points of the function on the boundary of the domain. Working on the boundary of the domain reduces this part of the problem to one or more single variable optimization problems. Note that there may be endpoints on portions of the boundary that need to be considered.
    • Evaluate the function at each of the points found in Steps 1 and 2.
    • The maximum value of the function is the largest value obtained in Step 3, and the minimum value of the function is the smallest value obtained in Step 3.
    Activity \(\PageIndex{6}\)

    Let \(f(x,y) = x^2-3y^2-4x+6y\) with triangular domain \(R\) whose vertices are at \((0,0)\text{,}\) \((4,0)\text{,}\) and \((0,4)\text{.}\) The domain \(R\) and a graph of \(f\) on the domain appear in Figure \(\PageIndex{7}\).

    fig_10_7_activity_optim_domain.svg fig_10_7_activity_optim.svg

    Figure \(\PageIndex{7}\). The domain of \(f(x,y) = x^2-3y^2-4x+6y\) and its graph.
    1. Find all of the critical points of \(f\) in \(R\text{.}\)
    2. Parameterize the horizontal leg of the triangular domain, and find the critical points of \(f\) on that leg. (Hint: You may need to consider endpoints.)
    3. Parameterize the vertical leg of the triangular domain, and find the critical points of \(f\) on that leg. (Hint: You may need to consider endpoints.)
    4. Parameterize the hypotenuse of the triangular domain, and find the critical points of \(f\) on the hypotenuse. (Hint: You may need to consider endpoints.)
    5. Find the absolute maximum and absolute minimum values of \(f\) on \(R\text{.}\)

    Summary

    • To find the extrema of a function \(f=f(x,y)\text{,}\) we first find the critical points, which are points where one of the partials of \(f\) fails to exist, or where \(f_x = 0\) and \(f_y=0\text{.}\)
    • The Second Derivative Test helps determine whether a critical point is a local maximum, local minimum, or saddle point.
    • If \(f\) is defined on a closed and bounded domain, we find the absolute maxima and minima by finding the critical points in the interior of the domain, finding the critical points on the boundary, and testing the value of \(f\) at both sets of critical points.

    This page titled 10.7: Optimization is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Matthew Boelkins, David Austin & Steven Schlicker (ScholarWorks @Grand Valley State University) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.