---
title: "Continuous functions on compact sets"
heading: Extreme values, intermediate values and uniform continuity
eyebrow: "A14 · Lesson 13 · Continuous functions on compact sets"
xp: 40
---

::: hook
Three theorems turn continuity on a closed, bounded interval into guarantees engineers rely on without noticing. A continuous function there reaches its maximum and minimum, so a worst case exists to be found (the **extreme value theorem**). It takes every value between its endpoint values, so a sign change means a root, which is why bisection can't fail (the **intermediate value theorem**). And one δ works for a given ε at every point at once (**uniform continuity**), which is what makes sampling, interpolation and numerical integration error bounds hold across the whole interval rather than point by point.
:::

::: play
- The curves give, for each point a, the largest δ that keeps the output within ε: for $x^2$ on [0, 2] (solid) and for $\frac1x$ on (0, 1] (dashed).
- For $x^2$ the δ is smallest at the right end but stays positive: one δ, $\sqrt{4 + \varepsilon} - 2$, works everywhere. That's uniform continuity.
- For $\frac1x$ the needed δ, $\frac{a^2\varepsilon}{1 + a\varepsilon}$, falls to 0 as a approaches 0. No single δ works, because (0, 1] isn't compact and the function blows up at the missing end.
:::
:::

```sim plot
view: graph
x: a = 0.01..2
y: d = 0..0.4
slider: e = 0.05..1 step 0.05 = 0.3
plot: sqrt(a^2 + e) - a | label: δ for x² at a
plot: step(1 - a)*a^2*e/(1 + a*e) | dashed | samples: 800 | label: δ for 1/x at a (a ≤ 1)
readout: one δ for x² on [0, 2] = sqrt(4 + e) - 2
readout: smallest δ for 1/x on (0, 1] = 0
```

::: predict
## f is continuous on [0, 1] with f(0) = −2 and f(1) = 3. Which must be true?

- [ ] f is increasing
- [x] f(c) = 0 for some c in (0, 1)
- [ ] f has exactly one root
- [ ] f(0.5) = 0.5

::: reveal
Some c has f(c) = 0, by the intermediate value theorem: a continuous function can't get from −2 to 3 without passing 0. It may cross many times, and it needn't be monotone; the theorem only promises at least one root, which is all bisection needs.
:::
:::

::: nameit
## The extreme value theorem

A continuous function on a compact set K attains a maximum and a minimum on K. (Take points where f approaches its supremum; a subsequence converges in K; continuity carries the values to the limit.)

## The intermediate value theorem

If f is continuous on [a, b] and y lies between f(a) and f(b), then f(c) = y for some c in [a, b]. In particular, a sign change brackets a root.

## Uniform continuity

f is **uniformly continuous** on S if for every ε there's a δ that works at every point at once:

$$\lvert x - y\rvert < \delta \Rightarrow \lvert f(x) - f(y)\rvert < \varepsilon \quad\text{for all } x, y \in S$$

- **Heine–Cantor:** a continuous function on a compact set is uniformly continuous.
- Lipschitz functions are uniformly continuous ($\delta = \varepsilon/L$).
- $\sqrt x$ on [0, ∞) is uniformly continuous ($\lvert\sqrt x - \sqrt y\rvert \le \sqrt{\lvert x - y\rvert}$, so $\delta = \varepsilon^2$), though not Lipschitz near 0.
- $x^2$ on ℝ and $\frac1x$ on (0, 1] are continuous but not uniformly.

## Why engineers need it

A bound like "linear interpolation with spacing h is within ε everywhere" needs a δ that doesn't depend on where you are. Uniform continuity on a closed interval supplies it; the error bounds of A13 (which use $\max\lvert f''\rvert$) are the quantitative version.
:::

::: example
## Find the largest value of $f(x) = x e^{-x/2}$ on [0, 5].

::: solution
1. **A maximum exists.** The interval is compact, so a maximum exists, at an endpoint or where f' = 0.
2. **Find the critical point.**
   $$f' = e^{-x/2}\left(1 - \frac x2\right)$$
   which is 0 at x = 2.
3. **Compare the candidates.**
   $$\begin{aligned} f(0) &= 0 \\ f(2) &= 2/e \\ &= 0.736 \\ f(5) &= 5e^{-2.5} \\ &= 0.410 \end{aligned}$$

**Answer:** the maximum is 0.736, at x = 2.
:::
:::

::: example
## Find one δ that works for $\sqrt x$ on [0, 9] with ε = 0.01.

::: solution
1. **A bound that holds everywhere.**
   $$\lvert\sqrt x - \sqrt y\rvert \le \sqrt{\lvert x - y\rvert}$$
2. **Choose δ.** So $\lvert x - y\rvert < \varepsilon^2$ is enough everywhere:
   $$\begin{aligned} \delta &= \varepsilon^2 \\ &= 0.0001 \end{aligned}$$
3. **It's the largest near 0.** x = 0.0001 and y = 0 differ by exactly 0.01 in their square roots.

**Answer:** δ = 0.0001 works on all of [0, 9].
:::
:::

::: example
## Find the largest value of $f(x) = x(1 - x)e^x$ on [0, 1].

::: solution
1. **A maximum exists.** [0, 1] is compact and f is continuous, so a maximum exists, at an endpoint or where $f' = 0$.
2. **Differentiate.**
   $$\begin{aligned} f'(x) &= e^x(1 - 2x + x - x^2) \\ &= e^x(1 - x - x^2) \end{aligned}$$
3. **Find the critical point.** This vanishes at
   $$\begin{aligned} x &= \frac{\sqrt5 - 1}{2} \\ &= 0.618 \end{aligned}$$
4. **Value there.**
   $$\begin{aligned} f &= 0.618 \times 0.382 \times e^{0.618} \\ &= 0.438 \end{aligned}$$
   while $f(0) = f(1) = 0$.
5. **Conclude.** So the maximum is 0.438, at the golden ratio's reciprocal. The extreme value theorem told us to look; calculus told us where.

**Answer:** the maximum is 0.438, at $x = \frac{\sqrt5 - 1}{2} = 0.618$.
:::
:::

::: check
given: R = 1 | 2 | 5; e = 0.1 | 0.01
answer: sqrt(R^2 + e) - R
tolerance: 0.01%

## What's the largest δ that works at every point for $x^2$ on [0, {R}] with ε = {e}?

::: right
Right. The steepest point, R, sets it: $\sqrt{R^2 + \varepsilon} - R$ = {answer}.
:::

::: misses
- [sqrt(e)] That's the δ at a = 0, the easiest point; the hardest is the right end.
- [any] Not yet. Find δ at the steepest point.
:::
:::

::: check
given: a = 0.5 | 0.1 | 0.01; e = 0.1 | 1
answer: a^2*e/(1 + a*e)
tolerance: 0.1%

## For $\frac1x$ at a = {a}, what's the largest δ that keeps $\left\lvert\frac1x - \frac1a\right\rvert < \given{e}$?

::: right
Right. The tight side is x < a: $\frac{a^2\varepsilon}{1 + a\varepsilon}$ = {answer}.
:::

::: misses
- [a^2*e/(1 - a*e)] That's the side x > a, which is looser; δ must work on both.
- [any] Not yet. Solve $\frac{1}{a - \delta} - \frac1a = \varepsilon$.
:::
:::

::: check
given: e = 0.1 | 0.03 | 0.001
answer: e^2
tolerance: 0.1%

## What δ works everywhere for $\sqrt x$ on [0, ∞) with ε = {e}?

::: right
Right. $\varepsilon^2$ = {answer}.
:::

::: misses
- [e] Square it: $\sqrt{\lvert x - y\rvert} < \varepsilon$ needs $\lvert x - y\rvert < \varepsilon^2$.
- [any] Not yet. $\lvert\sqrt x - \sqrt y\rvert \le \sqrt{\lvert x - y\rvert}$.
:::
:::

::: check
given: t = 1 | 2 | 3; T = 6 | 10
answer: t/exp(1)
tolerance: 0.1%

## What's the maximum of $f(x) = xe^{-x/\given{t}}$ on [0, {T}]?

::: right
Right. At x = τ: $\tau/e$ = {answer}.
:::

::: misses
- [T*exp(-T/t)] That's the value at the right end; the maximum is inside.
- [any] Not yet. $f' = 0$ at $x = \tau$; compare with the ends.
:::
:::

::: check
kind: choice

## Which function is uniformly continuous on the given set?

- [x] $\sin x$ on ℝ
- [ ] $x^2$ on ℝ
- [ ] $\frac1x$ on (0, 1]
- [ ] $\tan x$ on $(-\frac\pi2, \frac\pi2)$

::: misses
- [2] Its slope is unbounded on ℝ.
- [3] δ must shrink to 0 near the missing end.
- [4] It blows up at both ends.
:::
:::

::: check
kind: order

## Put the steps of the proof of the extreme value theorem in order.

1. Let f be continuous on the compact set K, and $M = \sup f(K)$ (possibly infinite).
2. Choose points $x_n \in K$ with $f(x_n) \to M$.
3. K is compact, so a subsequence $x_{n_k}$ converges to some $c \in K$.
4. By continuity, $f(x_{n_k}) \to f(c)$.
5. So $f(c) = M$: M is finite and attained.

::: right
Right. Compactness provides the limit point; continuity transfers the values.
:::
:::

::: check
kind: parts
given: m = 2 | 3; T = 10 | 20

## $f(x) = x^{\given{m}}e^{-x}$ on [0, {T}].

::: part
answer: m
tolerance: 0.5%

### Where is its maximum?

::: misses
- [T] The endpoint is lower: f has already peaked and fallen.
- [any] $f' = x^{m-1}e^{-x}(m - x)$.
:::
:::

::: part
answer: m^m*exp(-m)
tolerance: 0.5%

### What is the maximum value?

::: misses
- [any] $m^me^{-m}$.
:::
:::
:::

::: check
kind: derivation
vars: e = 0.001..0.5

## Uniform δ from Hölder bounds.

::: step
answer: e^2

### Since $\lvert\sqrt x - \sqrt y\rvert \le \sqrt{\lvert x - y\rvert}$, what δ works everywhere for $\sqrt x$?
:::

::: step
answer: e^3

### And for $x^{1/3}$, with $\lvert x^{1/3} - y^{1/3}\rvert \le \lvert x - y\rvert^{1/3}$?
:::

::: right
Right. Both are uniformly continuous on [0, ∞), though neither is Lipschitz at 0.
:::
:::

::: explain
## Why is a continuous function on a closed interval uniformly continuous, while $\frac1x$ on (0, 1] isn't?

::: model
For a continuous function, δ at each point depends on how steep the function is near it. On a closed, bounded interval there's no place for the steepness to grow without limit: if the needed δ shrank toward zero along some sequence of points, those points would have a convergent subsequence in the interval, and continuity at the limit point would give a positive δ nearby, a contradiction. So the δ's have a positive lower bound, and that bound works everywhere. On (0, 1] the trouble sits at the missing point 0, where $\frac1x$ blows up; points approaching it need ever smaller δ, and there's no limit point inside the set to stop the shrinking.
:::
:::

::: practice

::: check
given: R = 3 | 10; e = 0.5 | 0.05
answer: sqrt(R^2 + e) - R
tolerance: 0.01%

## Uniform δ for $x^2$ on [0, {R}], ε = {e}?

::: misses
- [any] $\sqrt{R^2 + \varepsilon} - R$.
:::
:::

::: check
given: a = 0.2 | 0.05; e = 0.5 | 2
answer: a^2*e/(1 + a*e)
tolerance: 0.1%

## Largest δ for $1/x$ at {a}, ε = {e}?

::: misses
- [any] $\frac{a^2\varepsilon}{1 + a\varepsilon}$.
:::
:::

::: check
given: t = 0.5 | 4; T = 8 | 12
answer: t/exp(1)
tolerance: 0.1%

## Maximum of $xe^{-x/\given{t}}$ on [0, {T}]?

::: misses
- [any] $\tau/e$.
:::
:::
:::
