In mathematics and also in applications, we often encounter problems that require to maximize or minimize the value of a certain quantity. The general procedure can be summarized as:

- Express the quantity to be maximized or minimized in terms of a single variable. The quantity may be described in terms of two variables however with given constraint it could be reduced to a single variable.
- Differentiate the function obtained in step 1 and set the derivative equal to 0.
- Solve the equation from step 2 to obtain critical values and determine whether they maximize or minimize the given quantity. Usually the first or second derivative test is a convenient tool for the required inspection.

*Example*. A farmer has 2400 ft of fencing and wants to fence off a rectangular field that borders a straight river. He needs no fence along the river. What are the dimensions of the field that has the largest area?

*Solution*. Let $x$ and $y$ denote the length and the width of the rectangular field. Suppose that the side along the river has the length $x$. Then the area is $A=xy$ and the required fencing in terms $x$ and $y$ is $x+2y=2400$. This fencing is a constraint and solve it for $y$ to obtain $y=1200-\frac{x}{2}$. Plugging this into $A$ for $y$, the area can be written as a function of a single variable $x$: $$A(x)=1200x-\frac{x^2}{2}$$ $A'(x)=1200-x$ and setting this equal to 0, we find $x=1200$. Since $A^{\prime\prime}(x)=-1<0$, by the second derivative test $x=1200$ gives rise to the absolute maximum of $A(x)$. The required dimensions are $1200\ \mbox{ft}\times 600\ \mbox{ft}$ where the side that borders the river is 1200 ft and the resulting largest area is 720,000 $\mbox{ft}^2$.

*Example*. A box with a square base and open top must have a volume of 32,000 $\mbox{cm}^3$. Find the dimensions of the box that minimize the amount of material used.

*Solution*. Let $x$ and $h$ be the length and the height of the box, respectively. Then $x^2h=32000$ and we want to minimize the surface area $A=x^2+4xh$. Solve the volume constraint for $h$ to obtain $h=\frac{32000}{x^2}$. Plugging this into $A$ for $h$, we write $A$ as a function of a single variable $x$: $$A(x)=x^2+\frac{128000}{x}$$ $A'(x)=2x-\frac{128000}{x^2}$ and setting it equalto 0, we find $x=40$. Since $A^{\prime\prime}(x)=2+\frac{256000}{x^3}>0$ for all $x>0$, $A(40)$ is the absolute minimum. Therefore the required dimensions are $40\ \mbox{cm}\times 40\ \mbox{cm}\times 20\ \mbox{cm}$.

*Example*. If 1200 $\mbox{cm}^2$ of material is available to make a box with a square base and an open top, find the largest possible volume of the box.

*Solution*. Let $x$ and $h$ be the length and the height of the box, respectively. Then $x^2+4xh=1200$ and we want to maximize $V=x^2h$. Solve the area for $h$ to obtain $h=\frac{1200-x^2}{4x}$. Plugging this into $V$, we write the volume as a function of a single variable $x$: $$V(x)=300x-\frac{1}{4}x^3$$ $V'(x)=300-\frac{3}{4}x^2$ and setting it equal to 0, we find $x=20$. Since $V'(x)$ is a quadratic polynomial with a negative leading coefficient, $V(2)=4000\ \mbox{cm}^3$ is the largest possible volume of the box.

*Example*. Find the point on the parabola $y^2=2x$ that is the closest to the point $(1,4)$.

*Solution*. Let $(x,y)$ denote a point on the parabola $y^2=2x$. The distance between $(x,y)$ and $(1,4)$ is $d=\sqrt{(x-1)^2+(y-4)^2}$ and we want to minimize this. Note minimizing $d$ is equivalent to minimizing $d^2=(x-1)^2+(y-4)^2$. Solve the equation of parabola for $x$ to obtain $x=\frac{y^2}{2}$. Plugging this into $d^2$, we can write it as a function of a single variable $y$: $$f(y)=\left(\frac{y^2}{2}-1\right)^2+(y-4)^2=\frac{y^4}{4}-8y+17$$ $f'(y)=y^3-8$ and setting it equal to 0, we find $y=2$. Since $f^{\prime\prime}(y)=3y^2>0$ for all $y\ne 0$, $(x,y)=(2,2)$ is the point on the parabola $y^2=2x$ that is the closest to (1,4)$.

*Remark*. The above problem also can be solved using a simple geometric fact that the shortest path from $(1,4)$ to the parabola $y^2=2x$ would be normal to the tangent line (i.e. the path is perpendicular to the tangent line). Let $(a,b)$ be the point on the parabola that is closest to $(1,4)$. By implicit differentiation we find $\frac{dy}{dx}=\frac{1}{y}$ and so the normal line at $(a,b)$ has the slope $-b$. The equation of the normal line is then $y-4=-b(x-1)$. Since this line is passing through $(a,b)$, $b-a=-b(a-1)$ or $ab=4$. $(a,b)$ is also on the parabola so we have $b^2=2a$. Solve the two equations simultaneously to obtain $b=2$ and hence $a=2$. Therefore, $(a,b)=(2,2)$.