In short

An optimization problem asks: what is the largest (or smallest) value a quantity can take, subject to some constraint? The method is always the same — express the quantity as a function of one variable using the constraint, take the derivative, set it to zero, and verify the critical point is the extremum you want. Calculus turns every such problem into algebra.

A farmer has 200 metres of fencing and wants to enclose the largest possible rectangular area against a straight river (so the fence is only needed on three sides). What dimensions should the rectangle be?

You could try a few values. If the rectangle is 90 m wide and 55 m deep, that uses 90 + 55 + 55 = 200 m of fencing and encloses 90 \times 55 = 4950 m^2. If it is 100 m wide and 50 m deep, that uses 100 + 50 + 50 = 200 m and encloses 100 \times 50 = 5000 m^2. Better. If it is 120 m wide and 40 m deep, that is 120 + 40 + 40 = 200 m and 120 \times 40 = 4800 m^2. Worse again.

So there is a sweet spot somewhere. The area climbs, peaks, and then drops. You could keep guessing and get close to the answer — or you could use calculus and find it exactly.

The general strategy

Every optimization problem follows the same five-step recipe:

Step 1. Draw a picture and label variables. Identify what you are trying to maximize or minimize (the objective), and what constraint connects the variables.

Step 2. Write the objective as a formula. Express the quantity you want to optimize as a function of the variables you labelled.

Step 3. Use the constraint to reduce to one variable. The constraint is an equation relating your variables. Solve for one variable in terms of the other and substitute into the objective. You should end up with a function of a single variable.

Step 4. Differentiate and find critical points. Take the derivative of the single-variable function, set it equal to zero, and solve.

Step 5. Verify and interpret. Confirm that the critical point is a maximum (or minimum, depending on the problem) using the second derivative test or the closed interval method. Then answer the original question in words.

Now let's solve the farmer's problem using this recipe.

The farmer's fence: a complete walkthrough

Step 1. Let x be the width of the rectangle (along the river) and y be the depth (perpendicular to the river). The fence covers two sides of length y and one side of length x, so the constraint is x + 2y = 200. The objective is to maximize the area A = xy.

Step 2. The area is A = xy.

Step 3. From the constraint, x = 200 - 2y. Substitute:

A(y) = (200 - 2y) \cdot y = 200y - 2y^2

This is a function of the single variable y. The domain is 0 \leq y \leq 100 (since x and y must both be non-negative).

Step 4. Differentiate:

A'(y) = 200 - 4y

Set A'(y) = 0: y = 50.

Step 5. Check: A''(y) = -4 < 0, so the critical point is a maximum. At y = 50: x = 200 - 2(50) = 100 and A = 100 \times 50 = 5000 m^2.

The optimal rectangle is 100 m wide and 50 m deep, enclosing 5000 m^2. This is exactly the value you stumbled on by trial earlier — but now you know it is the best possible, not just a good guess.

The area $A(y) = 200y - 2y^2$ as a function of the depth $y$. The parabola peaks at $y = 50$, confirming the maximum area of 5000 m$^2$. At the endpoints $y = 0$ and $y = 100$, the area is zero — a degenerate rectangle with no fence or no width.

Geometry problems

Geometry is where optimization problems feel most natural. The shapes impose constraints, and calculus finds the best configuration.

Classic problem: the inscribed rectangle

What is the largest rectangle that can be inscribed in a semicircle of radius r?

Place the semicircle with its diameter along the x-axis, centered at the origin: the equation is x^2 + y^2 = r^2, y \geq 0. A rectangle inscribed in this semicircle has its base on the x-axis from (-a, 0) to (a, 0), and its top corners touching the semicircle at (-a, b) and (a, b), where a^2 + b^2 = r^2.

The area is A = 2a \cdot b (width 2a, height b).

The constraint a^2 + b^2 = r^2 gives b = \sqrt{r^2 - a^2}. Substituting:

A(a) = 2a\sqrt{r^2 - a^2}, \qquad 0 \leq a \leq r

Differentiate using the product rule:

A'(a) = 2\sqrt{r^2 - a^2} + 2a \cdot \frac{-2a}{2\sqrt{r^2 - a^2}} = 2\sqrt{r^2 - a^2} - \frac{2a^2}{\sqrt{r^2 - a^2}}
= \frac{2(r^2 - a^2) - 2a^2}{\sqrt{r^2 - a^2}} = \frac{2r^2 - 4a^2}{\sqrt{r^2 - a^2}}

Set the numerator to zero: 2r^2 - 4a^2 = 0, so a^2 = r^2/2, giving a = r/\sqrt{2}.

Then b = \sqrt{r^2 - r^2/2} = r/\sqrt{2}. The rectangle's width is 2a = r\sqrt{2} and height is b = r/\sqrt{2}.

The maximum area is A = 2 \cdot \frac{r}{\sqrt{2}} \cdot \frac{r}{\sqrt{2}} = 2 \cdot \frac{r^2}{2} = r^2.

A clean result: the largest inscribed rectangle has area exactly r^2 — which is 2/\pi times the area of the semicircle.

Physics problems

In physics, optimization often involves time, distance, or energy. The constraint comes from the physical setup.

The fastest path (Snell's law motivation)

A lifeguard is standing at point A on the beach, 60 m from the waterline. A swimmer in trouble is at point B in the water, 40 m from the waterline and 100 m along the shore from the lifeguard. The lifeguard runs at 6 m/s on sand and swims at 2 m/s in water. At what point on the waterline should the lifeguard enter the water to reach the swimmer as quickly as possible?

Let x be the distance along the waterline from the point directly below the lifeguard to the entry point. The distance on sand is \sqrt{60^2 + x^2} = \sqrt{3600 + x^2}. The distance in water is \sqrt{40^2 + (100 - x)^2} = \sqrt{1600 + (100-x)^2}.

The total time is:

T(x) = \frac{\sqrt{3600 + x^2}}{6} + \frac{\sqrt{1600 + (100-x)^2}}{2}, \qquad 0 \leq x \leq 100

Differentiate:

T'(x) = \frac{x}{6\sqrt{3600 + x^2}} - \frac{100 - x}{2\sqrt{1600 + (100-x)^2}}

Setting T'(x) = 0:

\frac{x}{6\sqrt{3600 + x^2}} = \frac{100 - x}{2\sqrt{1600 + (100-x)^2}}

This looks complicated, but there is a beautiful geometric interpretation. If you let \theta_1 be the angle the sand path makes with the perpendicular to the waterline, then \sin\theta_1 = x/\sqrt{3600 + x^2}. Similarly, if \theta_2 is the angle the water path makes, then \sin\theta_2 = (100-x)/\sqrt{1600 + (100-x)^2}.

The equation becomes:

\frac{\sin\theta_1}{6} = \frac{\sin\theta_2}{2}

This is Snell's law — the same law that governs how light bends when it passes from one medium to another. Light, like the lifeguard, takes the fastest path.

Economics problems

In economics, optimization is everywhere: maximising profit, minimising cost, finding the optimal production level.

Profit maximisation

A company sells widgets at a price p = 120 - 2q rupees per unit, where q is the number of units sold (this is the demand curve — as they produce more, they must lower the price to sell it all). The cost of producing q units is C(q) = 200 + 20q rupees.

The revenue is R(q) = p \cdot q = (120 - 2q)q = 120q - 2q^2.

The profit is \Pi(q) = R(q) - C(q) = 120q - 2q^2 - 200 - 20q = -2q^2 + 100q - 200.

Differentiate: \Pi'(q) = -4q + 100. Set to zero: q = 25.

Check: \Pi''(q) = -4 < 0, confirming this is a maximum.

The maximum profit is \Pi(25) = -2(625) + 100(25) - 200 = -1250 + 2500 - 200 = 1050 rupees.

The optimal production level is 25 units, yielding a profit of 1050 rupees. Produce fewer and you are leaving money on the table; produce more and the falling price eats into your margins faster than the extra sales help.

Constraints

The examples above all have a single equation as the constraint. Here are the main types you will encounter:

Geometric constraints. These come from the shape: perimeter is fixed, area is fixed, a point lies on a curve. Example: "the sum of two sides of a triangle is 10 cm" or "a point lies on the circle x^2 + y^2 = 25."

Physical constraints. These come from conservation laws or physical limits: total material is fixed, speed is constant in each medium. Example: "the total surface area of the box is 600 cm^2."

Algebraic constraints. These come from definitions: x + y = k for some constant k, or xy = k. Many AM-GM inequality problems are secretly optimization problems with algebraic constraints.

The key technique: substitution

Every optimization problem with one constraint and two variables can be reduced to a single-variable problem. The constraint gives you one equation in two unknowns — solve for one unknown and substitute into the objective.

If you have two constraints and three variables, solve both constraints to eliminate two variables, leaving one. The pattern generalises.

When the domain is open: verifying the answer

On a closed interval, the closed interval method guarantees you find the global extremum. On an open or infinite domain — which is common in physics and economics — you need a different verification strategy.

Three options:

  1. Second derivative test. If f''(c) < 0 at the critical point, it is a local maximum. If there is only one critical point and the function goes to -\infty (or 0) at both ends of the domain, then the local maximum is also the global maximum.

  2. First derivative test. Check that f' changes from positive to negative at the critical point (for a maximum) or negative to positive (for a minimum).

  3. Physical reasoning. In many applied problems, it is obvious from the context that a maximum or minimum exists. The area of the farmer's rectangle is zero at both extremes of the domain and positive in between — so a maximum must exist, and the one critical point must be it.

Worked examples

Example 1: Minimising material for an open-top box

A manufacturer wants to make an open-top rectangular box with a square base and a volume of 500 cm^3. What dimensions minimise the amount of material used (the total surface area)?

Step 1. Let the base have side length x and the height be h. The constraint is x^2 h = 500. The objective is to minimise the surface area S = x^2 + 4xh (square base plus four sides, no top).

Why: the base is x \times x = x^2. Each of the four sides is x \times h. There is no top.

Step 2. From the constraint, h = 500/x^2. Substitute:

S(x) = x^2 + 4x \cdot \frac{500}{x^2} = x^2 + \frac{2000}{x}, \qquad x > 0

Why: eliminating h reduces the problem to one variable. The domain is x > 0 since a side length must be positive.

Step 3. Differentiate.

S'(x) = 2x - \frac{2000}{x^2}

Set S'(x) = 0:

2x = \frac{2000}{x^2} \implies 2x^3 = 2000 \implies x^3 = 1000 \implies x = 10

Why: setting the derivative to zero and solving gives the critical point. The cube root of 1000 is 10.

Step 4. Verify this is a minimum.

S''(x) = 2 + \frac{4000}{x^3}

At x = 10: S''(10) = 2 + 4 = 6 > 0. Since the second derivative is positive, the critical point is a local minimum. Since this is the only critical point on (0, \infty) and S(x) \to \infty as x \to 0^+ and as x \to \infty, it is also the global minimum.

Why: as x \to 0^+, the term 2000/x dominates and goes to infinity. As x \to \infty, the term x^2 dominates and goes to infinity. The function must have a global minimum somewhere in between, and the one critical point is it.

Step 5. Compute dimensions and surface area.

x = 10 \text{ cm}, \quad h = \frac{500}{100} = 5 \text{ cm}, \quad S = 100 + 200 = 300 \text{ cm}^2

Result: The optimal box has a 10 \times 10 cm base and is 5 cm tall, using 300 cm^2 of material.

The surface area $S(x) = x^2 + 2000/x$ as a function of the base side length $x$. The curve dives steeply from the left (tiny base, very tall box, huge side area) and rises on the right (huge base, tiny height, wasted base area). The minimum at $x = 10$ balances both terms.

Notice the pattern: the base is a square (10 \times 10), and the height is exactly half the base side (h = 5). This is characteristic of open-top box problems — the optimal height is always half the base side when the base is square.

Example 2: Maximum product with a fixed sum

Find two positive numbers whose sum is 24 and whose product is as large as possible.

Step 1. Let the two numbers be x and y. The constraint is x + y = 24. The objective is to maximise P = xy.

Why: a clean algebraic constraint. No geometry, no physics — just two numbers and a sum.

Step 2. From the constraint, y = 24 - x. Substitute:

P(x) = x(24 - x) = 24x - x^2, \qquad 0 < x < 24

Why: the domain excludes 0 and 24 because both numbers must be positive.

Step 3. Differentiate and solve.

P'(x) = 24 - 2x = 0 \implies x = 12

So y = 24 - 12 = 12.

Why: the critical point is at x = 12, and symmetry already suggests the answer — the two numbers are equal.

Step 4. Verify.

P''(x) = -2 < 0

Concave down everywhere, so the critical point is a maximum. P = 12 \times 12 = 144.

Why: the negative second derivative confirms the parabola opens downward, so the vertex is a maximum.

Result: The maximum product is 144, achieved when both numbers are 12.

The product $P(x) = x(24 - x)$ as a function of $x$. The downward-opening parabola peaks at the midpoint $x = 12$, where both numbers are equal. The product drops to zero when either number is zero (all the sum goes to one number, leaving nothing for the other).

This result is the AM-GM inequality in disguise. For two positive numbers with a fixed sum, the product is maximised when the numbers are equal. The AM-GM inequality says the same thing from the other direction: for a fixed product, the sum is minimised when the numbers are equal. Calculus proves both in one stroke.

Common confusions

Going deeper

If you came here to learn how to solve optimization problems with calculus, you have the full recipe — you can stop here. What follows covers Lagrange multipliers (for problems with constraints that are hard to solve explicitly), the AM-GM connection, and a surprising geometric result.

The AM-GM inequality via calculus

The result of Example 2 generalises. For n positive numbers with a fixed sum S, the product is maximised when all numbers are equal. That is the AM-GM inequality:

\frac{x_1 + x_2 + \cdots + x_n}{n} \geq \sqrt[n]{x_1 x_2 \cdots x_n}

with equality if and only if x_1 = x_2 = \cdots = x_n.

The calculus proof for n = 2 is what you just saw. For general n, you can use Lagrange multipliers or mathematical induction on the calculus argument.

Lagrange multipliers (preview)

In all the examples above, you solved the constraint for one variable and substituted. But sometimes the constraint is not easy to solve explicitly — for instance, "find the point on the curve x^3 + y^3 = 1 closest to the origin."

Lagrange multipliers give you an alternative: instead of substituting, you write down a system of equations that the solution must satisfy. The key equation is

\nabla f = \lambda \nabla g

where f is the objective, g is the constraint (written as g(x, y) = 0), and \lambda is an auxiliary variable called the Lagrange multiplier. This is a powerful technique that you will meet in multivariable calculus.

The isoperimetric inequality

Of all closed curves in the plane with a given perimeter P, the one that encloses the maximum area is the circle, with area P^2 / (4\pi).

This is the ultimate optimization result in geometry, and it has been known since antiquity — the ancient Indians and Greeks both knew that the circle was the "best" shape. Proving it rigorously requires either the calculus of variations (a generalization of ordinary calculus to functions of functions) or clever rearrangement arguments. It sits behind many of the specific optimization problems you solve in school: whenever you find that the optimal shape has some symmetry (square base, equal sides, maximum at a midpoint), you are seeing a shadow of this deeper result.

Where this leads next