---
title: Gronwall's inequality and continuous dependence
heading: How fast solutions can separate, and why that proves uniqueness and bounds numerical error
eyebrow: A14 · Lesson 35 · Gronwall's inequality
xp: 40
---

::: hook
Picard–Lindelöf (lesson 34) says a solution exists and is unique. Engineers also need to know how much the solution changes when the starting value is a little off, when the model has a small error, or when a numerical method commits a small error at every step. **Gronwall's inequality** answers all three with one estimate: errors can grow no faster than $e^{Lt}$, where L is the Lipschitz constant of the right-hand side. For stable systems a sharper version shows errors shrinking instead.
:::

::: play
- The curves start a distance d apart and both obey a linear ODE $\dot y = ky$. Their gap is exactly $de^{kt}$.
- With k > 0 the gap grows exponentially, and Gronwall's bound with L = k is sharp. With k < 0 the gap shrinks.
- The readout gives the time for the gap to grow a thousandfold, $\frac{\ln 1000}{k}$, when k > 0: in chaotic systems this "predictability horizon" is why forecasts fail beyond a few multiples of $1/L$.
:::

```sim plot
view: graph
x: t = 0..5
y: y = 0..4
slider: k = -1..1 step 0.05 = 0.4
slider: d = 0.05..0.5 step 0.05 = 0.2
plot: exp(k*t) | label: one solution
plot: (1 + d)*exp(k*t) | label: a neighbor | color: ch3
plot: d*exp(k*t) | label: their gap | color: ch2 | dashed
readout: time to grow a thousandfold = ln(1000)/(k + 1e-9) | digits: 3
```

::: predict
## Two solutions of $\dot y = \sin y + t$ start 0.01 apart. What's the most they can differ at t = 3?

- [ ] 0.01
- [ ] 0.03
- [x] About 0.2
- [ ] It can't be bounded

::: reveal
At most $0.01e^3 = 0.20$. The right-hand side has Lipschitz constant 1 in y (since $\lvert\cos y\rvert \le 1$), so by Gronwall the gap grows at most like $e^t$. The actual gap is usually much smaller; the bound is the worst case over all solutions.
:::
:::

::: nameit
## The inequality

If u is continuous and nonnegative with $u(t) \le a + \int_0^tb\,u(s)\,ds$ for constants a, b ≥ 0, then $u(t) \le ae^{bt}$. In differential form: $\dot u \le bu$ implies $u(t) \le u(0)e^{bt}$, since $\frac{d}{dt}(ue^{-bt}) \le 0$.

## Continuous dependence and uniqueness

If $\lvert f(t, y) - f(t, z)\rvert \le L\lvert y - z\rvert$, two solutions satisfy

$$\lvert y(t) - z(t)\rvert \le \lvert y(0) - z(0)\rvert e^{Lt}.$$

With equal starts the gap stays 0: that's uniqueness. With different starts, the solution depends continuously on its initial value, though the constant $e^{Lt}$ can be enormous on long intervals.

## Model errors

If z instead solves $\dot z = f(t, z) + \delta(t)$ with $\lvert\delta\rvert \le \delta_0$, then

$$\lvert y(t) - z(t)\rvert \le \lvert y(0) - z(0)\rvert e^{Lt} + \frac{\delta_0}{L}\left(e^{Lt} - 1\right).$$

## Numerical error

Euler's method commits a local error of about $\frac{h^2}{2}\max\lvert\ddot y\rvert$ per step, which acts like a model error $\delta_0 = \frac h2M$. So its global error over [0, T] is at most $\frac{hM}{2L}\left(e^{LT} - 1\right)$: first order in h, with a constant set by Gronwall.

## Stable systems

If instead $(f(t, y) - f(t, z))(y - z) \le -\mu(y - z)^2$ with μ > 0 (a contracting, one-sided condition), gaps shrink: $\lvert y - z\rvert \le \lvert y(0) - z(0)\rvert e^{-\mu t}$, and bounded model errors give bounded deviations, at most $\frac{\delta_0}{\mu}$. That's why stable circuits forgive small errors.
:::

::: example
## Bound the gap at t = 3 between two solutions of $\dot y = \sin y + t$ that start 0.01 apart.

::: solution
1. **Lipschitz constant.**
   $$\left\lvert\frac{\partial}{\partial y}(\sin y + t)\right\rvert = \lvert\cos y\rvert \le 1$$
   so L = 1.
2. **Apply Gronwall.**
   $$\begin{aligned} \lvert y(3) - z(3)\rvert &\le 0.01e^3 \\ &= 0.201 \end{aligned}$$
3. **How sharp it is.** The bound holds for every pair of solutions and every t, but it can be pessimistic: where $\cos y < 0$ along the solutions, the gap actually shrinks. Gronwall uses only the worst case of the Lipschitz constant, which is what makes it universal.

**Answer:** the gap at t = 3 is at most 0.201.
:::
:::

::: example
## Bound the global error of Euler's method with h = 0.01 on $\dot y = -y + \sin t$ over [0, 1], given $\lvert\ddot y\rvert \le 3$ there.

::: solution
1. **The constants.** L = 1 and M = 3.
2. **The plain bound.**
   $$\begin{aligned} \frac{0.01 \times 3}{2 \times 1}\left(e^1 - 1\right) &= 0.015 \times 1.718 \\ &= 0.026 \end{aligned}$$
3. **Why it's pessimistic.** The actual error is far smaller, because the system contracts (the −y term pulls solutions together), and the plain Gronwall bound can't see that.
4. **The one-sided bound.** With the one-sided version (μ = 1), each local error is damped instead of amplified, and the bound becomes
   $$\frac{hM}{2\mu}(1 - e^{-T}) = 0.0095$$

**Answer:** the plain Gronwall bound is 0.026, and the one-sided version tightens it to 0.0095.
:::
:::

::: example
## A circuit obeys $\dot v = -2v + u(t)$, and the input has an unmodeled error of at most 0.1. How far can the response stray from the model's?

::: solution
1. **The deviation's equation.** The system contracts with μ = 2. Starting from the same state, the deviation e satisfies
   $$\dot e = -2e + \delta$$
2. **Bound it.**
   $$\lvert e(t)\rvert \le \frac{0.1}{2}\left(1 - e^{-2t}\right)$$
   which is 0.0499 at t = 3 and never exceeds 0.05.
3. **Compare plain Gronwall.** With L = 2 it would allow $\frac{0.1}{2}(e^{2t} - 1)$, about 20 at t = 3.
4. **Which to use.** For stable systems, use the contracting version: it gives bounds that stay bounded.

**Answer:** the response never strays more than 0.05 from the model's (0.0499 at t = 3).
:::
:::

::: check
given: L = 0.5 | 2; d = 0.001 | 0.01; t = 1 | 5
answer: d*exp(L*t)
tolerance: 0.5%

## Two solutions of an ODE with Lipschitz constant {L} start {d} apart. What's the largest possible gap at t = {t}?

::: right
Right. $de^{Lt}$, by Gronwall.
:::

::: misses
- [d*(1 + L*t)] The growth compounds: exponential, not linear.
- [any] $\lvert y(0) - z(0)\rvert e^{Lt}$.
:::
:::

::: check
given: L = 1 | 3; e = 0.01 | 0.001; t = 1 | 2
answer: e/L*(exp(L*t) - 1)
tolerance: 0.5%

## A model's right-hand side is off by at most {e}, and its Lipschitz constant is {L}. Starting from the exact state, how far can its solution drift by t = {t}?

::: right
Right. $\frac{\delta_0}{L}(e^{Lt} - 1)$.
:::

::: misses
- [e*t] That ignores the amplification by L.
- [any] Solve $\dot u = Lu + \delta_0$ with u(0) = 0.
:::
:::

::: check
given: h = 0.01 | 0.001; M = 2 | 5; L = 1 | 2; T = 1 | 3
answer: h*M/(2*L)*(exp(L*T) - 1)
tolerance: 0.5%

## Bound Euler's global error with h = {h} over [0, {T}], with Lipschitz constant {L} and $\lvert\ddot y\rvert \le$ {M}.

::: right
Right. $\frac{hM}{2L}(e^{LT} - 1)$: first order in h.
:::

::: misses
- [h^2*M/(2*L)*(exp(L*T) - 1)] The local error is $O(h^2)$ but there are $T/h$ steps: the global error is O(h).
- [any] Treat each step's local error as a model error $\frac{hM}{2}$.
:::
:::

::: check
given: m = 1 | 5; d = 0.1 | 1; t = 1 | 3
answer: d*exp(-m*t)
tolerance: 0.5%

## A system contracts with rate μ = {m}. Two solutions start {d} apart. What bound holds on their gap at t = {t}?

::: right
Right. $de^{-\mu t}$: stable systems forget their starting differences.
:::

::: misses
- [d*exp(m*t)] That's the growing bound; contraction gives decay.
- [any] $\lvert y(0) - z(0)\rvert e^{-\mu t}$.
:::
:::

::: check
given: L = 0.1 | 1 | 5
answer: ln(1000)/L
tolerance: 0.5%

## An error grows like $e^{Lt}$ with L = {L}. How long until it's 1000 times larger?

::: right
Right. $\frac{\ln 1000}{L} = \frac{6.9}{L}$: the predictability horizon for three digits.
:::

::: misses
- [log(1000)/L] Use the natural logarithm.
- [any] Solve $e^{Lt} = 1000$.
:::
:::

::: check
kind: parts
given: m = 2 | 4; e = 0.1 | 0.5; t = 1 | 5

## A stable circuit obeys $\dot v = -\given{m}v + u$, and u is off by at most {e}.

::: part
answer: e/m*(1 - exp(-m*t))
tolerance: 0.5%

### Starting from the right state, how far can v stray by t = {t}?

::: misses
- [e/m*(exp(m*t) - 1)] That's plain Gronwall; contraction gives a bounded deviation.
- [any] Solve $\dot e = -\mu e + \delta_0$ from 0.
:::
:::

::: part
answer: e/m
tolerance: 0.5%

### What's the most it can ever stray?

::: misses
- [any] The limit $\frac{\delta_0}{\mu}$.
:::
:::
:::

::: check
kind: choice

## What does Gronwall's inequality give when two solutions of a Lipschitz ODE start at the same point?

- [ ] That they stay close
- [x] That they're identical: the bound is $0 \cdot e^{Lt} = 0$
- [ ] That they separate exponentially
- [ ] Nothing, since the inequality needs a positive starting gap

::: right
Right. That's the uniqueness half of Picard–Lindelöf, in one line.
:::

::: misses
- [1] It gives more: the gap is exactly zero.
- [3] The exponential multiplies a zero starting gap.
- [4] The inequality holds with a = 0 as well.
:::
:::

::: check
kind: derivation
vars: u = 0.1..2, b = 0.1..2, t = 0..3, d = 0.01..1

## Solve the comparison equations behind Gronwall's inequality.

::: step
answer: u*exp(b*t)

### If $\dot w = bw$ with $w(0) = u$, what is w(t)?
:::

::: step
answer: d/b*(exp(b*t) - 1)

### If $\dot w = bw + d$ with w(0) = 0, what is w(t)?
:::

::: right
Right. Gronwall says anything growing no faster than these comparison solutions stays below them.
:::
:::

::: check
kind: python

## Solve $\dot y = -y + \sin t$, y(0) = 0, to t = 1 by Euler's method with h = 0.01. Set `err` to its error against the exact $y = \frac12e^{-t} + \frac{\sin t - \cos t}{2}$, and `bound` to Gronwall's $\frac{hM}{2L}(e^{L} - 1)$ with L = 1, M = 3.

```python starter
import math

err = bound = 0.0
print(err, bound)
```

```python solution
import math

y, t, h = 0.0, 0.0, 0.01
for _ in range(100):
    y += h * (-y + math.sin(t))
    t += h
exact = 0.5 * math.exp(-1) + (math.sin(1) - math.cos(1)) / 2
err = abs(y - exact)
bound = h * 3 / 2 * (math.e - 1)
print(err, bound)
```

```python tests
assert abs(err - 0.0013586) < 2e-6, f"Euler's error at t = 1 is 0.00136; got {err}."
assert err < bound, "The actual error must respect the bound."
```

::: right
Right. 0.00136 against the bound 0.026: the system contracts, so local errors fade instead of compounding.
:::
:::

::: explain
## Why does a Lipschitz condition make solutions separate at most exponentially?

::: model
The gap between two solutions changes at a rate equal to the difference of the right-hand sides, and a Lipschitz constant L says that difference is at most L times the gap. So the gap's growth rate is at most proportional to its current size, which is exactly the condition for exponential growth: the gap can at most double in each time interval of length $\frac{\ln 2}{L}$. Any growth beyond that would need the right-hand side to change faster than L allows. Gronwall's inequality turns this rate comparison into an inequality between the gap and $e^{Lt}$ times its starting value.
:::
:::

::: practice

::: check
given: L = 1 | 4; d = 0.005 | 0.05; t = 0.5 | 2
answer: d*exp(L*t)
tolerance: 0.5%

## Gronwall gap bound, L = {L}, start {d}, t = {t}?

::: misses
- [any] $de^{Lt}$.
:::
:::

::: check
given: L = 0.1 | 0.2 | 0.5 | 1 | 2 | 5
answer: ln(1000)/L
tolerance: 0.5%

## Time for a thousandfold growth at L = {L}?

::: misses
- [any] $\frac{\ln 1000}{L}$.
:::
:::
:::
