TExcelTAD
Home › Calculus in Depth › Average Value of a Function

Average Value of a Function

The average of finitely many numbers is their sum divided by their count. The average of a function over an interval, infinitely many values, is the integral divided by the length. This lesson derives that definition from ordinary averages, proves the Mean Value Theorem for Integrals, and connects averages to RMS levels in audio and electronics and to Monte Carlo integration, where integrals are computed as averages.

From sample averages to an integral

Take nn equally spaced sample points xi∗x_i^* in [a,b][a, b], with spacing Δx=b−an\Delta x = \frac{b - a}{n}. Their average is

f(x1∗)+⋯+f(xn∗)n=1b−a⋅∑f(xi∗)Δxsince 1n=Δxb−a\frac{f(x_1^*) + \cdots + f(x_n^*)}{n} = \frac{1}{b - a} \cdot \sum f(x_i^*)\Delta x \qquad \text{since } \frac{1}{n} = \frac{\Delta x}{b - a}

The right side is 1b−a\frac{1}{b - a} times a Riemann sum. Letting n→∞n \to \infty:

Definition. The average value of an integrable ff on [a,b][a, b] is

favg=1b−a∫abf(x) dxf_{\text{avg}} = \frac{1}{b - a} \int_a^b f(x)\,dx.

Geometrically, favgf_{\text{avg}} is the height of the rectangle on [a,b][a, b] with the same (net) area as the region under ff.

python · try it yourself
import numpy as np
import sympy as sp

x = sp.symbols('x', real=True)
f = x**2 - 2*x + 3
a, b = 0, 3
avg = sp.integrate(f, (x, a, b)) / (b - a)
print("exact average on [0, 3]:", avg)

fn = sp.lambdify(x, f)
for n in (4, 40, 4000):
    xs = a + (np.arange(n) + 0.5) * (b - a) / n          # midpoints
    print(f"mean of {n:4} sample values = {float(np.mean(fn(xs))):.6f}")
exact average on [0, 3]: 3
mean of    4 sample values = 2.953125
mean of   40 sample values = 2.999531
mean of 4000 sample values = 3.000000

The Mean Value Theorem for Integrals

Theorem. If ff is continuous on [a,b][a, b], there is a number cc in [a,b][a, b] with

f(c)=favg=1b−a∫abf(x) dxf(c) = f_{\text{avg}} = \frac{1}{b - a} \int_a^b f(x)\,dx.

Proof. By the Extreme Value Theorem, ff has a minimum m=f(u)m = f(u) and a maximum M=f(v)M = f(v) on [a,b][a, b]. The bounds property of the integral gives m(b−a)≤∫abf≤M(b−a)m(b - a) \le \int_a^b f \le M(b - a), so m≤favg≤Mm \le f_{\text{avg}} \le M. By the Intermediate Value Theorem, the continuous ff takes every value between f(u)f(u) and f(v)f(v), in particular favgf_{\text{avg}}, at some cc between uu and vv. ∎

(Alternatively: apply the Mean Value Theorem to F(x)=∫axf(t) dtF(x) = \int_a^x f(t)\,dt; then F′(c)=F(b)−F(a)b−aF'(c) = \frac{F(b) - F(a)}{b - a} is exactly this statement, with cc in the open interval.)

For f(x)=x2−2x+3f(x) = x^2 - 2x + 3 on [0,3][0, 3], the average is 3, and c2−2c+3=3c^2 - 2c + 3 = 3 gives c=2c = 2 (the other root, c=0c = 0, is an endpoint).

Continuity matters: a step function that is 0 on [0,1)[0, 1) and 1 on [1,2][1, 2] has average 12\frac{1}{2} but never takes that value.

RMS: the average that measures power

The ordinary average of sin⁡t\sin t over a full period is 0, yet an AC current clearly delivers power. Power depends on the square of voltage, so engineers use the root mean square

Vrms=1T∫0TV(t)2 dtV_{\text{rms}} = \sqrt{\frac{1}{T} \int_0^T V(t)^2\,dt}

For V(t)=V0sin⁡(ωt)V(t) = V_0 \sin(\omega t), the average of sin⁡2\sin^2 over a period is 12\frac{1}{2}, so Vrms=V02V_{\text{rms}} = \frac{V_0}{\sqrt{2}}. A "230 V" outlet has peak voltage 230⋅2≈325 V230 \cdot \sqrt{2} \approx 325\ \text{V}.

python · try it yourself
import numpy as np

V0, f0 = 325.0, 50.0                       # peak volts, hertz
t = np.linspace(0, 1 / f0, 10_001)[:-1]    # one period, evenly sampled
V = V0 * np.sin(2 * np.pi * f0 * t)
print(f"mean voltage = {round(float(np.mean(V)), 6) + 0.0:.6f} V")   # + 0.0 turns -0.0 into 0.0
print(f"RMS voltage  = {float(np.sqrt(np.mean(V**2))):.3f} V   (V0/√2 = {V0 / np.sqrt(2):.3f})")
mean voltage = 0.000000 V
RMS voltage  = 229.810 V   (V0/√2 = 229.810)

Monte Carlo: integrals as averages

Turn the definition around: ∫abf(x) dx=(b−a)⋅favg\int_a^b f(x)\,dx = (b - a) \cdot f_{\text{avg}}. If we estimate the average by evaluating ff at random points, we get the Monte Carlo method. Its error shrinks like 1/n1/\sqrt{n} regardless of dimension, which is why it dominates in high dimensions (rendering, Bayesian statistics), even though grid rules win in one dimension:

python · try it yourself
import numpy as np

rng = np.random.default_rng(2024)
f = lambda x: np.exp(-x**2)
a, b = 0.0, 2.0
exact = 0.8820813907624215                      # ∫₀² e^(−x²) dx = (√π/2)·erf(2)
for n in (100, 10_000, 1_000_000):
    est = (b - a) * float(np.mean(f(rng.uniform(a, b, n))))
    print(f"n = {n:>9,}: estimate = {est:.6f}   error = {est - exact:+.1e}")
n =       100: estimate = 1.057401   error = +1.8e-01
n =    10,000: estimate = 0.878240   error = -3.8e-03
n = 1,000,000: estimate = 0.882250   error = +1.7e-04

Each hundredfold increase in samples buys about one more correct digit (a factor of 10 in error): the 1/n1/\sqrt{n} law.

In software

  • Audio loudness. Meters and normalisers (RMS, and LUFS in streaming services) compute the average power 1T∫x(t)2 dt\frac{1}{T}\int x(t)^2\,dt over a window of samples.
  • Path tracing. A pixel's colour is the average of incoming light over directions; renderers estimate it with Monte Carlo samples per pixel, and the visible noise is the 1/n1/\sqrt{n} error.
  • Moving averages and smoothing. A sliding window average 1w∫f(t) dt\frac{1}{w}\int f(t)\,dt over the last ww seconds is the continuous version of the moving averages in finance and the box blur in image processing.

Exercises

Exercise 1: Average of a power

Find the average value of f(x)=xf(x) = \sqrt{x} on [0,4][0, 4].

Answer

43\frac{4}{3}.

Solution

14∫04x1/2 dx=14⋅23⋅8=43\frac{1}{4}\int_0^4 x^{1/2}\,dx = \frac{1}{4} \cdot \frac{2}{3} \cdot 8 = \frac{4}{3}.

Exercise 2: Find c

For f(x)=xf(x) = \sqrt{x} on [0,4][0, 4], find cc with f(c)=favgf(c) = f_{\text{avg}}.

Answer

c=169≈1.778c = \frac{16}{9} \approx 1.778.

Solution

c=43⇒c=169\sqrt{c} = \frac{4}{3} \Rightarrow c = \frac{16}{9}, which lies in [0,4][0, 4].

Exercise 3: Average temperature

A day's temperature is modelled by T(t)=18+6sin⁡(π(t−9)/12)T(t) = 18 + 6\sin(\pi(t - 9)/12) °C for 0≤t≤240 \le t \le 24 (hours). Find the average temperature.

Answer

18 °C.

Solution

The sine has period 24 h, so it completes exactly one period on [0,24][0, 24] and its average is 0.

python · try it yourself
import numpy as np
from scipy.integrate import quad
T = lambda t: 18 + 6 * np.sin(np.pi * (t - 9) / 12)
print(round(quad(T, 0, 24)[0] / 24, 10))
18.0

Exercise 4: RMS of a sawtooth

A sawtooth wave rises linearly from −A-A to AA over each period. Show Vrms=A3V_{\text{rms}} = \frac{A}{\sqrt{3}}.

Answer

A3≈0.577A\frac{A}{\sqrt{3}} \approx 0.577A.

Solution

Over one period, take V(t)=A(2tT−1)V(t) = A\big(\frac{2t}{T} - 1\big) for 0≤t≤T0 \le t \le T. With u=2tT−1u = \frac{2t}{T} - 1: 1T∫0TV2 dt=A22∫−11u2 du=A22⋅23=A23\frac{1}{T}\int_0^T V^2\,dt = \frac{A^2}{2}\int_{-1}^{1} u^2\,du = \frac{A^2}{2} \cdot \frac{2}{3} = \frac{A^2}{3}.

Test yourself

The average value of ff on [a,b][a, b] is…

  1. (f(a)+f(b))/2(f(a) + f(b))/2
  2. ∫abf(x) dx\int_a^b f(x)\,dx
  3. f((a+b)/2)f((a + b)/2)
  4. 1b−a∫abf(x) dx\frac{1}{b - a}\int_a^b f(x)\,dx

Which hypothesis does the Mean Value Theorem for Integrals need so that ff actually takes its average value?

  1. ff is differentiable
  2. ff is continuous on [a,b][a, b]
  3. ff is positive
  4. ff is increasing

Monte Carlo integration's error decreases roughly like…

  1. 1/n1/\sqrt{n}
  2. 1/n1/n
  3. 1/n21/n^2
  4. e−ne^{-n}