# 6.1: Optimization

- Page ID
- 449

Many important applied problems involve finding the best way to accomplish some task. Often this involves finding the maximum or minimum value of some function: the minimum time to make a certain journey, the minimum cost for doing a task, the maximum power that can be generated by a device, and so on. Many of these problems can be solved by finding the appropriate function and then using techniques of calculus to find the maximum or the minimum value required.

Generally such a problem will have the following mathematical form: Find the largest (or smallest) value of \(f(x)\) when \(a\le x\le b\). Sometimes \(a\) or \(b\) are infinite, but frequently the real world imposes some constraint on the values that \(x\) may have.

Such a problem differs in two ways from the local maximum and minimum problems we encountered when graphing functions: We are interested only in the function between \(a\) and \(b\), and we want to know the largest or smallest value that \(f(x)\) takes on, not merely values that are the largest or smallest in a small interval. That is, we seek not a local maximum or minimum but a **global** maximum or minimum, sometimes also called an **absolute** maximum or minimum.

Any global maximum or minimum must of course be a local maximum or minimum. If we find all possible local extrema, then the global maximum, *if it exists*, must be the largest of the local maxima and the global minimum, *if it exists*, must be the smallest of the local minima. We already know where local extrema can occur: only at those points at which \(f'(x)\) is zero or undefined. Actually, there are two additional points at which a maximum or minimum can occur if the endpoints \(a\) and \(b\) are not infinite, namely, at \(a\) and \(b\). We have not previously considered such points because we have not been interested in limiting a function to a small interval. An example should make this clear.

Example 6.1.1

Find the maximum and minimum values of \( f(x)=x^2\) on the interval \([-2,1]\), shown in figure __6.1.1__. We compute \( f'(x)=2x\), which is zero at \(x=0\) and is always defined.

*Figure 6.1.1. **The function \(f(x)=x^2\) restricted to \([-2,1]\)*

**Solution**

Since \(f'(1)=2\) we would not normally flag \(x=1\) as a point of interest, but it is clear from the graph that *when \(f(x)\) is restricted to \([-2,1]\) there is a local maximum at \(x=1\).* Likewise we would not normally pay attention to \(x=-2\), but since we have truncated \(f\) at \(-2\) we have introduced a new local maximum there as well. In a technical sense nothing new is going on here: When we truncate \(f\) we actually create a new function, let's call it \(g\), that is defined only on the interval \([-2,1]\). If we try to compute the derivative of this new function we actually find that it does not have a derivative at \(-2\) or \(1\). Why? Because to compute the derivative at 1 we must compute the limit $$\lim_{\Delta x\to 0} {g(1+\Delta x)-g(1)\over \Delta x}.$$ This limit does not exist because when \(\Delta x>0\), \(g(1+\Delta x)\) is not defined. It is simpler, however, simply to remember that we must always check the endpoints.

So the function \(g\), that is, \(f\) restricted to \([-2,1]\), has one critical value and two finite endpoints, any of which might be the global maximum or minimum. We could first determine which of these are local maximum or minimum points (or neither); then the largest local maximum must be the global maximum and the smallest local minimum must be the global minimum. It is usually easier, however, to compute the value of \(f\) at every point at which the global maximum or minimum might occur; the largest of these is the global maximum, the smallest is the global minimum.

So we compute \(f(-2)=4\), \(f(0)=0\), \(f(1)=1\). The global maximum is 4 at \(x=-2\) and the global minimum is 0 at \(x=0\).

It is possible that there is no global maximum or minimum. It is difficult, and not particularly useful, to express a complete procedure for determining whether this is the case. Generally, the best approach is to gain enough understanding of the shape of the graph to decide. Fortunately, only a rough idea of the shape is usually needed.

There are some particularly nice cases that are easy. A continuous function on a closed interval \([a,b]\) *always* has both a global maximum and a global minimum, so examining the critical values and the endpoints is enough:

Theorem 6.1.2: Extreme Value Theorem

If \(f\) is continuous on a closed interval \([a,b]\), then it has both a minimum and a maximum point. That is, there are real numbers \(c\) and \(d\) in \([a,b]\) so that for every \(x\) in \([a,b]\), \(f(x)\le f(c)\) and \(f(x)\ge f(d)\).

Another easy case: If a function is continuous and has a single critical value, then if there is a local maximum at the critical value it is a global maximum, and if it is a local minimum it is a global minimum. There may also be a global minimum in the first case, or a global maximum in the second case, but that will generally require more effort to determine.

Example 6.1.3

Let \( f(x)=-x^2+4x-3\). Find the maximum value of \(f(x)\) on the interval \([0,4]\).

**Solution**

First note that \(f'(x)= -2 x +4=0\) when \(x=2\), and \(f(2)= 1\). Next observe that \(f'(x)\) is defined for all \(x\), so there are no other critical values. Finally, \(f(0) = -3\) and \(f(4)= -3\). The largest value of \(f(x)\) on the interval \([0,4]\) is \(f(2)=1\)

Example 6.1.4

Let \(f(x)=-x^2+4x-3\). Find the maximum value of \(f(x)\) on the interval \([-1,1]\).

**Solution**

First note that \(f'(x)= -2 x +4=0\) when \(x=2\). But \(x=2\) is not in the interval, so we don't use it. Thus the only two points to be checked are the endpoints; \(f(-1) = -8\) and \(f(1)= 0\). So the largest value of \(f(x)\) on \([-1,1]\) is \(f(1)=0\).

Example 6.1.5

Find the maximum and minimum values of the function \(f(x)= 7+|x-2|\) for \(x\) between \(1\) and \(4\) inclusive.

**Solution**

The derivative \(f'(x)\) is never zero, but \(f'(x)\) is undefined at \(x=2\), so we compute \(f(2)= 7\). Checking the end points we get \(f(1)=8\) and \(f(4)=9\). The smallest of these numbers is \(f(2)=7\), which is, therefore, the minimum value of \(f(x)\) on the interval \(1 \le x \le 4\), and the maximum is \(f(4)=9\).

Example 6.1.6

Find all local maxima and minima for \(f(x)=x^3-x\), and determine whether there is a global maximum or minimum on the open interval \((-2,2)\).

**Figure 6.1.2. **\(f(x)=x^3-x\)

**Solution**

In example __5.1.2__ we found a local maximum at \((-\sqrt3/3,2\sqrt{3}/9)\) and a local minimum at \((\sqrt3/3,-2\sqrt{3}/9)\). Since the endpoints are not in the interval \((-2,2)\) they cannot be considered. Is the lone local maximum a global maximum? Here we must look more closely at the graph. We know that on the closed interval \( [-\sqrt3/3,\sqrt3/3]\) there is a global maximum at \( x=-\sqrt3/3\) and a global minimum at \( x=\sqrt3/3\). So the question becomes: what happens between \(-2\) and \( -\sqrt3/3\), and between \( \sqrt3/3\) and \(2\)? Since there is a local minimum at \( x=\sqrt3/3\), the graph must continue up to the right, since there are no more critical values. This means no value of \(f\) will be less than \( -2\sqrt{3}/9\) between \( \sqrt3/3\) and \(2\), but it says nothing about whether we might find a value larger than the local maximum \(2\sqrt{3}/9\).

How can we tell? Since the function increases to the right of \( \sqrt3/3\), we need to know what the function values do "close to'' \(2\). Here the easiest test is to pick a number and do a computation to get some idea of what's going on. Since \( f(1.9)=4.959>2\sqrt{3}/9\), there is no global maximum at \( -\sqrt3/3\), and hence no global maximum at all. (How can we tell that \(4.959>2\sqrt{3}/9\)? We can use a calculator to approximate the right hand side; if it is not even close to 4.959 we can take this as decisive. Since \( 2\sqrt{3}/9\approx 0.3849\), there's really no question. Funny things can happen in the rounding done by computers and calculators, however, so we might be a little more careful, especially if the values come out quite close. In this case we can convert the relation \(4.959>2\sqrt{3}/9\) into \((9/2) 4.959>\sqrt{3}\) and ask whether this is true. Since the left side is clearly larger than \(4\cdot 4\) which is clearly larger than \( \sqrt3\), this settles the question.)

A similar analysis shows that there is also no global minimum. The graph of \(f(x)\) on \((-2,2)\) is shown in figure __6.1.2__.

Example 6.1.7

Of all rectangles of area 100, which has the smallest perimeter?

**Solution**

First we must translate this into a purely mathematical problem in which we want to find the minimum value of a function. If \(x\) denotes one of the sides of the rectangle, then the adjacent side must be \(100/x\) (in order that the area be 100). So the function we want to minimize is $$ f(x)=2x+2{100\over x} $$ since the perimeter is twice the length plus twice the width of the rectangle. Not all values of \(x\) make sense in this problem: lengths of sides of rectangles must be positive, so \(x>0\). If \(x>0\) then so is \(100/x\), so we need no second condition on \(x\).

We next find \(f'(x)\) and set it equal to zero: \(0=f'(x)=2-200/x^2\). Solving \(f'(x)=0\) for \(x\) gives us \(x=\pm 10\). We are interested only in \(x>0\), so only the value \(x=10\) is of interest. Since \(f'(x)\) is defined everywhere on the interval \((0,\infty)\), there are no more critical values, and there are no endpoints. Is there a local maximum, minimum, or neither at \(x=10\)? The second derivative is \(f''(x)=400/x^3\), and \(f''(10)>0\), so there is a local minimum. Since there is only one critical value, this is also the global minimum, so the rectangle with smallest perimeter is the \(10\times10\) square.

Example 6.1.8

You want to sell a certain number \(n\) of items in order to maximize your profit. Market research tells you that if you set the price at $1.50, you will be able to sell 5000 items, and for every 10 cents you lower the price below $1.50 you will be able to sell another 1000 items. Suppose that your fixed costs ("start-up costs'') total $2000, and the per item cost of production ("marginal cost'') is $0.50. Find the price to set per item and the number of items sold in order to maximize profit, and also determine the maximum profit you can get.

**Solution**

The first step is to convert the problem into a function maximization problem. Since we want to maximize profit by setting the price per item, we should look for a function \(P(x)\) representing the profit when the price per item is \(x\). Profit is revenue minus costs, and revenue is number of items sold times the price per item, so we get \(P=nx-2000-0.50n\). The number of items sold is itself a function of \(x\), \(n=5000+1000(1.5-x)/0.10\), because \((1.5-x)/0.10\) is the number of multiples of 10 cents that the price is below $1.50. Now we substitute for \(n\) in the profit function: $$ \eqalign{ P(x)&=(5000+1000(1.5-x)/0.10)x-2000- 0.5(5000+1000(1.5-x)/0.10)\cr& =-10000x^2+25000x-12000\cr} $$ We want to know the maximum value of this function when \(x\) is between 0 and \(1.5\). The derivative is \(P'(x)=-20000x+25000\), which is zero when \(x=1.25\). Since \(P''(x)=-20000 < 0\), there must be a local maximum at \(x=1.25\), and since this is the only critical value it must be a global maximum as well. (Alternately, we could compute \(P(0)=-12000\), \(P(1.25)=3625\), and \(P(1.5)=3000\) and note that \(P(1.25)\) is the maximum of these.) Thus the maximum profit is $3625, attained when we set the price at $1.25 and sell 7500 items.

Example 6.1.9

Find the largest rectangle (that is, the rectangle with largest area) that fits inside the graph of the parabola \( y=x^2\) below the line \(y=a\) (\(a\) is an unspecified constant value), with the top side of the rectangle on the horizontal line \(y=a\); see figure __6.1.3__.)

**Figure 6.1.3. **Rectangle in a Parabola

We want to find the maximum value of some function \(A(x)\) representing area. Perhaps the hardest part of this problem is deciding what \(x\) should represent. The lower right corner of the rectangle is at \((x,x^2)\), and once this is chosen the rectangle is completely determined. So we can let the \(x\) in \(A(x)\) be the \(x\) of the parabola \(f(x)=x^2\). Then the area is \(A(x)=(2x)(a-x^2)=-2x^3+2ax\). We want the maximum value of \(A(x)\) when \(x\) is in \([0,\sqrt{a}]\). (You might object to allowing \(x=0\) or \(x=\sqrt{a}\), since then the "rectangle'' has either no width or no height, so is not "really'' a rectangle. But the problem is somewhat easier if we simply allow such rectangles, which have zero area.)

Setting \(0=A'(x)=6x^2+2a\) we get \( x=\sqrt{a/3}\) as the only critical value. Testing this and the two endpoints, we have \(A(0)=A(\sqrt{a})=0\) and \( A(\sqrt{a/3})=(4/9)\sqrt{3}a^{3/2}\). The maximum area thus occurs when the rectangle has dimensions \( 2\sqrt{a/3}\times (2/3)a\).

Example 6.1.10

If you fit the largest possible cone inside a sphere, what fraction of the volume of the sphere is occupied by the cone? (Here by "cone'' we mean a right circular cone, i.e., a cone for which the base is perpendicular to the axis of symmetry, and for which the cross-section cut perpendicular to the axis of symmetry at any point is a circle.)

**Solution**

Let \(R\) be the radius of the sphere, and let \(r\) and \(h\) be the base radius and height of the cone inside the sphere. What we want to maximize is the volume of the cone: \(\pi r^2h/3\). Here \(R\) is a fixed value, but \(r\) and \(h\) can vary. Namely, we could choose \(r\) to be as large as possible---equal to \(R\)---by taking the height equal to \(R\); or we could make the cone's height \(h\) larger at the expense of making \(r\) a little less than \(R\). See the cross-section depicted in figure __6.1.4__. We have situated the picture in a convenient way relative to the \(x\) and \(y\) axes, namely, with the center of the sphere at the origin and the vertex of the cone at the far left on the \(x\)-axis.

**Figre 6.1.4. **Cone in a sphere

Notice that the function we want to maximize, \( \pi r^2h/3\), depends on *two* variables. This is frequently the case, but often the two variables are related in some way so that "really'' there is only one variable. So our next step is to find the relationship and use it to solve for one of the variables in terms of the other, so as to have a function of only one variable to maximize. In this problem, the condition is apparent in the figure: the upper corner of the triangle, whose coordinates are \((h-R,r)\), must be on the circle of radius \(R\). That is, $$ (h-R)^2+r^2=R^2. $$ We can solve for \(h\) in terms of \(r\) or for \(r\) in terms of \(h\). Either involves taking a square root, but we notice that the volume function contains \( r^2\), not \(r\) by itself, so it is easiest to solve for \( r^2\) directly: \(r^2=R^2-(h-R)^2\). Then we substitute the result into \( \pi r^2h/3\): $$ \eqalign{ V(h)&=\pi(R^2-(h-R)^2)h/3\cr& =-{\pi\over3}h^3+{2\over3}\pi h^2R\cr }$$ We want to maximize \(V(h)\) when \(h\) is between 0 and \(2R\). Now we solve \( 0=f'(h)=-\pi h^2+(4/3)\pi h R\), getting \(h=0\) or \(h=4R/3\). We compute \(V(0)=V(2R)=0\) and \(V(4R/3)=(32/81)\pi R^3\). The maximum is the latter; since the volume of the sphere is \((4/3)\pi R^3\), the fraction of the sphere occupied by the cone is $${(32/81)\pi R^3\over (4/3)\pi R^3}={8\over 27}\approx 30%.$$

Example 6.1.11

You are making cylindrical containers to contain a given volume. Suppose that the top and bottom are made of a material that is \(N\) times as expensive (cost per unit area) as the material used for the lateral side of the cylinder. Find (in terms of \(N\)) the ratio of height to base radius of the cylinder that minimizes the cost of making the containers.

**Solution**

Let us first choose letters to represent various things: \(h\) for the height, \(r\) for the base radius, \(V\) for the volume of the cylinder, and \(c\) for the cost per unit area of the lateral side of the cylinder; \(V\) and \(c\) are constants, \(h\) and \(r\) are variables. Now we can write the cost of materials: $$ c(2\pi rh)+Nc(2\pi r^2). $$ Again we have two variables; the relationship is provided by the fixed volume of the cylinder: \( V=\pi r^2h\). We use this relationship to eliminate \(h\) (we could eliminate \(r\), but it's a little easier if we eliminate \(h\), which appears in only one place in the above formula for cost). The result is $$ f(r)=2c\pi r{V\over\pi r^2}+2Nc\pi r^2={2cV\over r}+2Nc\pi r^2. $$ We want to know the minimum value of this function when \(r\) is in \((0,\infty)\). We now set \( 0=f'(r)=-2cV/r^2+4Nc\pi r\), giving \(r={\root 3 \of {V/(2N\pi)}}\). Since \(f''(r)=4cV/r^3+4Nc\pi\) is positive when \(r\) is positive, there is a local minimum at the critical value, and hence a global minimum since there is only one critical value.

Finally, since \( h=V/(\pi r^2)\), $$ {h\over r}={V\over\pi r^3}={V\over \pi(V/(2N\pi))}=2N, $$ so the minimum cost occurs when the height \(h\) is \(2N\) times the radius. If, for example, there is no difference in the cost of materials, the height is twice the radius (or the height is equal to the diameter).

Example 6.1.12

Suppose you want to reach a point \(A\) that is located across the sand from a nearby road (see figure __6.1.5__). Suppose that the road is straight, and \(b\) is the distance from \(A\) to the closest point \(C\) on the road. Let \(v\) be your speed on the road, and let \(w\), which is less than \(v\), be your speed on the sand. Right now you are at the point \(D\), which is a distance \(a\) from \(C\). At what point \(B\) should you turn off the road and head across the sand in order to minimize your travel time to \(A\)?

**Figure 6.1.5****. **Minimizing travel time.

**Solution**

Let \(x\) be the distance short of \(C\) where you turn off, i.e., the distance from \(B\) to \(C\). We want to minimize the total travel time. Recall that when traveling at constant velocity, time is distance divided by velocity.

You travel the distance \( \overline{DB}\) at speed \(v\), and then the distance \(\overline{BA}\) at speed \(w\). Since \(\overline{DB}=a-x\) and, by the Pythagorean theorem, \( \overline{BA}=\sqrt{x^2+b^2}\), the total time for the trip is $$ f(x)={a-x\over v}+{\sqrt{x^2+b^2}\over w}. $$ We want to find the minimum value of \(f\) when \(x\) is between 0 and \(a\). As usual we set \(f'(x)=0\) and solve for \(x\): $$ \displaylines{ 0=f'(x)=-{1\over v}+{x\over w\sqrt{x^2+b^2}}\cr w\sqrt{x^2+b^2}=vx\cr w^2(x^2+b^2) = v^2x^2\cr w^2b^2=(v^2-w^2)x^2\cr x={wb\over\sqrt{v^2-w^2}} }$$ Notice that \(a\) does not appear in the last expression, but \(a\) is not irrelevant, since we are interested only in critical values that are in \([0,a]\), and \(wb/\sqrt{v^2-w^2}\) is either in this interval or not. If it is, we can use the second derivative to test it: $$ f''(x) = {b^2\over (x^2+b^2)^{3/2}w}. $$ Since this is always positive there is a local minimum at the critical point, and so it is a global minimum as well.

If the critical value is not in \([0,a]\) it is larger than \(a\). In this case the minimum must occur at one of the endpoints. We can compute $$ \eqalign{ f(0)&={a\over v}+{b\over w}\cr f(a)&={\sqrt{a^2+b^2}\over w}\cr }$$ but it is difficult to determine which of these is smaller by direct comparison. If, as is likely in practice, we know the values of \(v\), \(w\), \(a\), and \(b\), then it is easy to determine this. With a little cleverness, however, we can determine the minimum in general. We have seen that \(f''(x)\) is always positive, so the derivative \(f'(x)\) is always increasing. We know that at \(wb/\sqrt{v^2-w^2}\) the derivative is zero, so for values of \(x\) less than that critical value, the derivative is negative. This means that \(f(0)>f(a)\), so the minimum occurs when \(x=a\).

So the upshot is this: If you start farther away from \(C\) than \( wb/\sqrt{v^2-w^2}\) then you always want to cut across the sand when you are a distance \(wb/\sqrt{v^2-w^2}\) from point \(C\). If you start closer than this to \(C\), you should cut directly across the sand.

## Summary: Steps to solve an optimization problem

- Decide what the variables are and what the constants are, draw a diagram if appropriate, understand clearly what it is that is to be maximized or minimized.
- Write a formula for the function for which you wish to find the maximum or minimum.
- Express that formula in terms of only one variable, that is, in the form \(f(x)\).
- Set \(f'(x)=0\) and solve. Check all critical values and endpoints to determine the extreme value.