Optimization with Calculus
Optimization finding the best value a function can achieve, is what derivatives were invented for. The logic rests on one observation: at an interior maximum or minimum of a smooth function, the tangent is horizontal, so f′ = 0. Combine that with the Extreme Value Theorem, a continuous function on a closed interval [a, b] must attain a global max and min, and the whole search collapses to a short list:
Candidates = endpoints a, b + critical points where f′(x) = 0. Evaluate f at each; the largest wins, the smallest loses.
No cleverness, no luck: the global optimum is guaranteed to be in the candidate table. This closed-interval method is the most reliable algorithm in elementary calculus, and this page runs it end to end.
How to Use This Calculator
Enter the objective function and the interval of allowed values (the practical domain lengths can't be negative, budgets have ceilings). The calculator differentiates symbolically, hunts down every root of f′ inside the interval numerically, builds the full candidate table, and declares the global maximum and minimum with both marked on the graph. The steps mirror exactly what an exam expects: derivative, critical points, table, conclusion.
Worked Example: the Classic Fence
A farmer has 100 m of fencing for a rectangular pen against a barn wall (no fence needed on that side). Width x on the two sides leaves 100 − 2x for the front, so the area is A(x) = x(100 − 2x) on [0, 50]. Differentiate: A′ = 100 − 4x, zero at x = 25. The candidate table:
A(0) = 0, A(25) = 25·50 = 1250, A(50) = 0 → maximum area 1250 m² at x = 25
The optimal pen is 25 by 50, twice as long as deep, and the endpoints' zeros confirm the interior candidate is the true winner. Note the shape of the answer: half the fencing goes to the side parallel to the barn. Optimization answers often carry such tidy structure, and noticing it is the fastest error check there is.
Building the Objective: the Real Skill
The calculus in optimization is routine; the modeling is not. Word problems supply two ingredients: a quantity to optimize (area, cost, time) and a constraint (fixed fencing, fixed volume). The constraint eliminates one variable, turning a two-variable dream into a one-variable function, exactly what happened when 100 m of fencing forced the front to be 100 − 2x. The second chip encodes an open-top box of fixed volume whose material S(x) = x² + 16/x (base plus sides after the volume constraint eliminates the height); its minimum at x = 2 exhibits the other classic answer-shape, base width matching a natural proportion of the height. When the constraint won't eliminate a variable cleanly, that's the signal you've outgrown one dimension, Lagrange multipliers take over from there.
Common Mistakes to Avoid
- Forgetting the endpoints. On a closed interval the winner is often at the boundary, a cubic's interior critical points can all lose to f(b), as the third chip demonstrates (max at the endpoint x = 5, not the local max at x = 1). Interior-only searches are wrong by design.
- Optimizing before eliminating. Differentiating an objective that still contains two variables produces nonsense. Constraint first, then derivative.
- Using an unrealistic domain. The algebraic domain of x(100 − 2x) is all reals; the fence exists only on [0, 50]. Practical domains come from the story, and forgetting them yields "optimal" negative lengths.
- Stopping at f′ = 0 without classifying. A critical point can be the minimum you weren't asked for, or a saddle-flat. The candidate table settles global questions without any second-derivative ceremony, that's its virtue.
Real-World Applications
Industrial optimization began exactly here: minimal-material packaging (the soda can whose height equals its diameter, a first-year problem run at billions of units), maximal-strength beams cut from logs, minimal-cost pipeline routes crossing rivers (the classic time/cost minimization that also derives Snell's law of refraction, light itself solves an optimization problem). Airlines optimize cruise speed against fuel burn curves; power companies dispatch generators along marginal-cost curves; and every pricing team maximizes revenue x·D(x) against a demand curve, the fence problem wearing a suit.
The closed-interval method also anchors modern practice: machine learning's training loop is optimization at scale (gradient descent is "follow f′ downhill" when the candidate table is too big to enumerate), operations research extends the constraint-elimination idea into linear and convex programming, and engineering design codes wrap the same evaluate-candidates logic in automated search. The one-variable version this page runs isn't a toy, it's the exact template those fields industrialized, and the place where their intuition is built.
Frequently Asked Questions
What if my interval is open or infinite?
The Extreme Value guarantee evaporates, an optimum may not exist (1/x on (0, 1] has no max). Analyze limits toward the open ends: if f falls away at both, an interior critical point is the global max. The first-derivative sign pattern substitutes for the candidate table.
Do I need the second derivative test?
Not for global questions on closed intervals, the table already compares actual values, which is stronger than local classification. The second-derivative test earns its keep on open domains and in theoretical arguments where evaluating isn't possible.
What about critical points where f′ doesn't exist?
They're candidates too, |x − 2| has its minimum at a corner where f′ is undefined, not zero. Include every interior point where f′ fails to exist alongside the f′ = 0 roots; this tool's sign-change root finder locates the corner points of such objectives as well.
How do I handle two constraints at once?
Each equality constraint eliminates one variable; two constraints on three variables still leave a one-variable problem. If constraints are inequalities (budgets, capacities), they typically become interval endpoints, which is precisely why endpoint checking is non-negotiable.
Why does the answer to so many textbook problems have symmetric shape?
Because symmetric objectives under symmetric constraints optimize at symmetric configurations (squares, cubes, half-splits), a soft form of the principle that optima inherit the problem's symmetry. Asymmetric answers (the barn pen's 2:1) trace to asymmetric constraints (the free wall). Reading the answer's shape against the problem's symmetry is a professional-grade sanity check.
Can this find all local optima, not just global ones?
The steps list every critical point with its value, the local story is all there. For a dedicated local analysis with increasing/decreasing intervals and classification, the curve sketching tool presents the same information organized around shape rather than optimality.