Tutorials › Calculus I › Optimizing With Piecewise Constraints

Optimization and Newton's Method · Tutorial 880 of 1495

Optimizing With Piecewise Constraints

Learn a careful method for finding global extrema when the objective or feasible interval is defined piece by piece.

Advanced 10 min read

What You'll Learn

  • Translate case-based constraints into the feasible set, including which boundaries are attained.
  • Check objective values and continuity at every breakpoint.
  • Find critical points within each smooth feasible piece.
  • Use a global-extrema argument without assuming there are finitely many critical points.
  • Distinguish an attained maximum or minimum from an unattained limiting value.

Why Piecewise Optimization Needs Care

A one-variable optimization problem may use different formulas in different ranges, or its constraints may allow different ranges of the variable in different cases. The resulting problem is still about finding the largest or smallest feasible objective value, but the case boundaries need special attention.

A point where the formula changes may be an endpoint of one piece and the start of another. It can be a global optimum even when the derivative is nonzero on both sides, or when the derivative does not exist there. A constraint can also exclude a boundary, in which case a nearby limiting value need not be attained.

The reliable approach is to identify the feasible set first, split it into its smooth pieces, and account for endpoints and breakpoints as well as critical points. Continuity matters: it is one of the conditions that guarantees global extrema exist on a closed bounded feasible set.

Definition: A one-variable optimization problem has an objective function \(f\) and a feasible set \(D\), the set of allowed values of \(x\). A global maximum is a value \(f(x_*)\) such that \(x_*\in D\) and \(f(x_*)\ge f(x)\) for every \(x\in D\). A global minimum is defined by reversing the inequality.

Translate the Cases into a Feasible Set

Before differentiating, write down exactly which values of \(x\) are allowed. For example, if a case-based constraint permits \(0\le x\le1\) or \(2\le x\le4\), then the feasible set is \(D=[0,1]\cup[2,4]\). The gap \((1,2)\) is not feasible, so there is no reason to search it for an optimum.

Record whether each boundary is included. A closed endpoint, such as \(x=1\) in \([0,1]\), can be a candidate for an attained optimum. An excluded boundary is not itself a feasible candidate, even if objective values approach a limiting value there. The earlier material on endpoints and critical points and on feasible boundaries that are not attained addresses these distinctions; here they are essential because different cases often produce different boundary behavior.

Next, list the points where either the objective formula or the description of the feasible set changes. At each such breakpoint, determine whether the point is feasible, evaluate the objective at the point if it is, and compare that value with the behavior on both sides. Do not assume the two formulas give the same value there.

Candidate Points for a Continuous Piecewise-Smooth Objective

Suppose the feasible set is a finite union of closed, bounded intervals, and \(f\) is continuous on that set. Suppose also that the intervals can be divided at finitely many breakpoints so that \(f\) is differentiable on the interior of each resulting piece. Then the Extreme Value Theorem guarantees that \(f\) attains both a global maximum and a global minimum on the feasible set.

Every point where either global extremum is attained must be an endpoint, a breakpoint, or an interior critical point of a smooth feasible piece. An interior critical point means a point in that piece where \(f'(x)=0\); if differentiability fails at an interior point, that point must also be treated as a candidate. For a piecewise-smooth objective whose only interior failures of differentiability are the listed breakpoints, the breakpoint list already accounts for them.

Theorem: Let \(D\) be a finite union of closed, bounded intervals and let \(f\) be continuous on \(D\). Suppose there are finitely many breakpoints such that \(f\) is differentiable on the interior of each smooth piece. Global extrema exist, and every point where one is attained is an endpoint, a breakpoint, or an interior point of a smooth piece where \(f'(x)=0\).

This theorem identifies where to look; it does not guarantee that the candidate set is finite. A differentiable function can have infinitely many critical points, and the set of critical values can also be infinite. You may compare a finite list only when an additional fact ensures that there are finitely many candidates. Otherwise, use the existence result and analyze the candidate set without treating it as a finite list.

Why These Are the Right Candidates

The reasoning combines existence of extrema with Fermat’s theorem. The Extreme Value Theorem says that a continuous function on a closed, bounded feasible set attains a maximum and a minimum. Take a point \(x_*\) where either is attained. If it is an endpoint or breakpoint, it is already on the list. Otherwise, it lies inside a smooth piece, so there is a small open interval around \(x_*\) that remains inside that piece. There, \(x_*\) is a local extremum of a differentiable function.

Fermat’s theorem says that if a differentiable function has a local maximum or minimum at an interior point, its derivative there is zero. Thus \(f'(x_*)=0\). This proves the candidate-location claim. It does not prove that the list is finite: neither the Extreme Value Theorem nor Fermat’s theorem limits how many critical points there can be.

1
Describe feasibility.
Write the allowed values as a set, preserving included and excluded boundaries.
2
Mark the cases.
List the endpoints and every point where the formula or feasible-set description changes.
3
Analyze smooth pieces.
Differentiate each formula on the interior of its feasible piece and find its critical points.
4
Check boundaries and continuity.
Evaluate the actual objective at feasible endpoints and breakpoints; compare with one-sided behavior where needed.
5
Establish the global conclusion.
Use continuity and compactness when their hypotheses hold. Compare values directly only when the candidate set is known to be finite.

Worked Example: A Continuous Objective with a Breakpoint

Worked Example: A Continuous Objective with a Breakpoint

Find the global maximum and minimum of \(f\) on \([0,4]\), where

$$ f(x)= \begin{cases} x^2, & 0\le x\le 2,\\ 4-(x-2)^2, & 2<x\le4. \end{cases} $$

At the breakpoint \(x=2\), the first formula gives \(f(2)=2^2=4\). The right-hand formula approaches \(4-(2-2)^2=4\), so \(f\) is continuous there. It is continuous on the entire closed interval, so global extrema exist.

On the first piece, \(f'(x)=2x\). The equation \(2x=0\) gives \(x=0\), an endpoint, so there are no interior critical points in \((0,2)\). On the second piece, \(f'(x)=-2(x-2)\). Setting this equal to zero gives \(x=2\), which is the breakpoint, not an interior point of \((2,4)\). Thus we check \(x=0,2,4\).

The values are \(f(0)=0^2=0\), \(f(2)=4\), and \(f(4)=4-(4-2)^2=4-4=0\). Therefore the global maximum is \(4\), attained at \(x=2\), and the global minimum is \(0\), attained at \(x=0\) and \(x=4\). Substituting each point into its applicable formula confirms the values.

Worked Example: A Feasible Set with a Gap

Worked Example: A Feasible Set with a Gap

Find the global maximum and minimum of \(f(x)=5-(x-3)^2\) on the feasible set \(D=[0,1]\cup[2,4]\).

The feasible set has two closed components. The objective is a polynomial, hence continuous on \(D\), so it attains both extrema. Its derivative is \(f'(x)=-2(x-3)\), and the only critical point is \(x=3\), which belongs to \([2,4]\).

Check the endpoints of both components and the critical point: \(f(0)=5-(0-3)^2=5-9=-4\); \(f(1)=5-(1-3)^2=5-4=1\); \(f(2)=5-(2-3)^2=5-1=4\); \(f(3)=5-(3-3)^2=5\); and \(f(4)=5-(4-3)^2=5-1=4\).

The largest of these values is \(5\), attained at \(x=3\), and the smallest is \(-4\), attained at \(x=0\). The gap \((1,2)\) contributes no candidates because its points are infeasible. Direct substitution verifies both reported values.

Worked Example: A Discontinuous Breakpoint Can Prevent a Maximum

Worked Example: A Discontinuous Breakpoint Can Prevent a Maximum

Consider \(f\) on \([0,2]\), defined by

$$ f(x)= \begin{cases} x, & 0\le x<1,\\ 0, & x=1,\\ 2-x, & 1<x\le2. \end{cases} $$

On the left of \(1\), the values approach \(1\), since \(x\) approaches \(1\). On the right, the values also approach \(1\), since \(2-x\) approaches \(1\). But the actual breakpoint value is \(f(1)=0\), so \(f\) is not continuous at \(1\).

For every feasible \(x\), \(f(x)<1\): on \(0\le x<1\), \(f(x)=x<1\); at \(x=1\), \(f(x)=0\); and on \(1<x\le2\), \(f(x)=2-x<1\). Nevertheless, values can be made arbitrarily close to \(1\) by taking \(x<1\) sufficiently close to \(1\). Thus the supremum is \(1\), but no feasible point attains it, so there is no global maximum.

The minimum is \(0\): the formulas give nonnegative values on their respective pieces, and \(f(0)=0\), \(f(1)=0\), and \(f(2)=0\). This example shows why continuity cannot be omitted from the existence argument, and why a one-sided limiting value at a breakpoint is not automatically an attained objective value.

A Common Mistake: Assuming There Are Only Finitely Many Candidates

A common error is to say that endpoint, breakpoint, and critical-point checks always produce a finite list that can be compared. The candidate-location theorem does not say this. A differentiable piece can contain infinitely many critical points, and their objective values need not reduce to a finite set. The correct conclusion is that, under the theorem’s hypotheses, extrema occur among the stated types of points. A finite comparison is justified only if the problem also ensures finitely many candidates.

Another error is to differentiate one formula across a breakpoint as though it were valid on both sides. Instead, differentiate each formula only on its own smooth piece, then check the breakpoint itself if it is feasible. Even when the formulas meet continuously, a corner can be an extremum without having derivative zero.

Key takeaway: For piecewise optimization, separate feasibility from the objective, check the actual value at every feasible breakpoint, and use critical points only within smooth pieces. Continuity on a closed bounded feasible set guarantees attainment, but does not guarantee finitely many candidates.

Check Your Understanding

Use the definitions and candidate-point reasoning above to answer these questions.

  1. For a piecewise objective on a closed interval, why must a feasible breakpoint be checked even if neither adjacent derivative is zero?
  2. What hypotheses allow the Extreme Value Theorem to guarantee both a global maximum and a global minimum?
  3. Does the candidate-location theorem imply that there are finitely many critical points? Explain.
  4. If the objective approaches a value at an excluded boundary, why might that value fail to be a maximum?
  5. For \(f(x)=5-(x-3)^2\) on \([0,1]\cup[2,4]\), which feasible points are endpoints or critical points, and what are the corresponding objective values?

Test yourself: Calculus I final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon