Chapter 8
15 min read
Section 77 of 353

Average Value of a Function

The Definite Integral

Learning Objectives

By the end of this section, you will be able to:

  1. Define the average value of a continuous function over an interval
  2. Calculate average values using the definite integral formula
  3. Interpret the average value geometrically as the height of an equal-area rectangle
  4. State and apply the Mean Value Theorem for Integrals
  5. Connect average value to expected value in probability and machine learning
  6. Solve real-world problems involving average quantities

The Big Picture: From Sums to Integrals

"The average value of a continuous function is the natural extension of the arithmetic mean to the world of infinitely many values."

We all know how to find the average of a finite set of numbers: add them up and divide by how many there are. But what if you have infinitely many values? What is the "average height" of a curve?

This section answers that question using the definite integral. The average value of a function is one of the most intuitive applications of integration — it tells us what single constant value would give the same "total effect" as the varying function over an interval.

Why Average Value Matters

Average value appears everywhere: the average temperature over a day, the average velocity of a moving object, the average power consumption of a device, the expected value in probability theory, and the mean loss in machine learning. Understanding this concept unlocks a powerful way to summarize continuous data.


Historical Context: Measuring the Unmeasurable

The problem of finding average values of continuously varying quantities puzzled mathematicians and scientists for centuries. Before calculus, there was no systematic way to answer questions like:

  • What is the average height of a parabolic arch?
  • What is the average speed of an accelerating object?
  • What is the average value of a sine wave?

Ancient mathematicians like Archimedes could compute areas under curves using exhaustion methods, but the connection to "average height" wasn't explicitly formalized until the development of calculus in the 17th century.

The Key Insight

The breakthrough came from recognizing that if the area under a curve equals the area of a rectangle with the same base, then the rectangle's height must be the "average height" of the curve.

The Core Idea

If we can find the height favgf_{avg} such that the rectangle with this height has the same area as the region under the curve, then favgf_{avg} is the average value of ff.


From Discrete to Continuous Averages

The Discrete Case: Arithmetic Mean

For a finite set of nn values y1,y2,,yny_1, y_2, \ldots, y_n, the average is:

yˉ=y1+y2++ynn=1ni=1nyi\bar{y} = \frac{y_1 + y_2 + \cdots + y_n}{n} = \frac{1}{n} \sum_{i=1}^{n} y_i

This is sum divided by count — the total divided by how many.

Sampling a Continuous Function

Now consider a continuous function f(x)f(x) on an interval [a,b][a, b]. If we sample nn equally-spaced points:

xi=a+iΔxwhereΔx=banx_i = a + i \cdot \Delta x \quad \text{where} \quad \Delta x = \frac{b - a}{n}

The sample average of ff at these points is:

fˉ1ni=1nf(xi)\bar{f} \approx \frac{1}{n} \sum_{i=1}^{n} f(x_i)

Taking the Limit

Rewriting this sum:

fˉ1ni=1nf(xi)=1bai=1nf(xi)Δx\bar{f} \approx \frac{1}{n} \sum_{i=1}^{n} f(x_i) = \frac{1}{b-a} \sum_{i=1}^{n} f(x_i) \cdot \Delta x

As nn \to \infty, this Riemann sum becomes a definite integral:

The Continuous Average

fˉ=limn1ni=1nf(xi)=1baabf(x)dx\bar{f} = \lim_{n \to \infty} \frac{1}{n} \sum_{i=1}^{n} f(x_i) = \frac{1}{b-a} \int_a^b f(x) \, dx

The Pattern

Notice the structure: sum → integral, and count → interval length. The integral is a "continuous sum," and the interval length (ba)(b-a) plays the role of "how many."


The Average Value Formula

Definition: Average Value of a Function

If ff is integrable on [a,b][a, b], the average value of ff on [a,b][a, b] is:

favg=1baabf(x)dxf_{avg} = \frac{1}{b - a} \int_a^b f(x) \, dx

Understanding Each Part

  • abf(x)dx\int_a^b f(x) \, dx: The total accumulation (signed area under the curve)
  • bab - a: The length of the interval (like the count nn in discrete averages)
  • favgf_{avg}: The height of a rectangle with the same area as the region under ff

Geometric Interpretation

Area Under the Curve

A=abf(x)dxA = \int_a^b f(x) \, dx

The signed area between the curve and the x-axis from aa to bb.

Equal-Area Rectangle

A=favg(ba)A = f_{avg} \cdot (b - a)

A rectangle with base (ba)(b-a) and height favgf_{avg} has the same area.

Why 'Average'?

The average value favgf_{avg} is the height at which a horizontal line would "balance" the function — if you could pour the area under the curve into a rectangle, favgf_{avg} would be its height.

Interactive: Average Value Explorer

Explore how the average value relates to the area under different functions. Notice how the rectangle with height favgf_{avg} always has the same area as the region under the curve:

Average Value of a Function Explorer
-0.50.31.11.92.73.5-1.21.74.77.610.513.5a = 0.00b = 3.00f_avg = 3.000
Function
f(x) = x²
0.03.0 f(x) dx
9.0000
Average Value f_avg
3.0000
Average Value Formula: favg = (1/(3.00 - 0.00)) × 9.0000 = 3.0000
The red dashed rectangle has the same area (9.000) as the blue shaded region under the curve.

The Mean Value Theorem for Integrals

The average value formula raises a natural question: is there a point cc in [a,b][a, b] where the function actually attains its average value? The answer is yes, for continuous functions.

Mean Value Theorem for Integrals

If ff is continuous on [a,b][a, b], then there exists a point c[a,b]c \in [a, b] such that:

f(c)=favg=1baabf(x)dxf(c) = f_{avg} = \frac{1}{b - a} \int_a^b f(x) \, dx

Equivalently: abf(x)dx=f(c)(ba)\int_a^b f(x) \, dx = f(c) \cdot (b - a)

Why This Theorem Is True

By the Extreme Value Theorem, a continuous function on a closed interval attains its minimum mm and maximum MM. The average value must lie between these:

mfavgMm \leq f_{avg} \leq M

By the Intermediate Value Theorem, since ff is continuous and takes values mm and MM, it must take every value in between — including favgf_{avg}. Therefore, there exists cc where f(c)=favgf(c) = f_{avg}.

Geometric Meaning

The MVT for Integrals guarantees that somewhere on the interval, the curve crosses the horizontal line at height favgf_{avg}. At that point cc, the function value equals the average value.

Interactive: MVT for Integrals

Explore how the Mean Value Theorem for Integrals works. For any continuous function, there's always a point where the function equals its average:

Mean Value Theorem for Integrals
-0.50.31.11.92.73.5-1.21.74.77.610.513.5c = 1.732abf_avg = 3.000
Integral
9.0000
Average Value
3.0000
MVT Point c
1.7320
f(c)
3.0000
Mean Value Theorem for Integrals
For continuous f on [a, b], there exists c ∈ [a, b] such that:
f(c) = f_avg = (1/(b-a)) ∫ab f(x) dx
At c = 1.7320, the function achieves its average value: f(1.732) = 3.0000 3.0000

Worked Examples

Example 1: Polynomial Function

Problem: Find the average value of f(x)=x2f(x) = x^2 on [0,3][0, 3].

Solution:

Step 1: Apply the average value formula:

favg=13003x2dxf_{avg} = \frac{1}{3 - 0} \int_0^3 x^2 \, dx

Step 2: Evaluate the integral using FTC Part 2:

03x2dx=[x33]03=2730=9\int_0^3 x^2 \, dx = \left[ \frac{x^3}{3} \right]_0^3 = \frac{27}{3} - 0 = 9

Step 3: Divide by the interval length:

favg=93=3f_{avg} = \frac{9}{3} = 3

Check with MVT: Where does f(c)=c2=3f(c) = c^2 = 3? At c=31.732c = \sqrt{3} \approx 1.732, which is in [0,3][0, 3]. ✓

Example 2: Trigonometric Function

Problem: Find the average value of f(x)=sin(x)f(x) = \sin(x) on [0,π][0, \pi].

Solution:

favg=1π00πsin(x)dxf_{avg} = \frac{1}{\pi - 0} \int_0^{\pi} \sin(x) \, dx

Evaluate the integral:

0πsin(x)dx=[cos(x)]0π=cos(π)(cos(0))=1+1=2\int_0^{\pi} \sin(x) \, dx = [-\cos(x)]_0^{\pi} = -\cos(\pi) - (-\cos(0)) = 1 + 1 = 2
favg=2π0.637f_{avg} = \frac{2}{\pi} \approx 0.637

Physical meaning: The average height of one complete arch of the sine function is about 64% of its maximum height.

Example 3: Exponential Function

Problem: Find the average value of f(x)=exf(x) = e^x on [0,2][0, 2].

Solution:

favg=12002exdx=12[ex]02=12(e21)f_{avg} = \frac{1}{2 - 0} \int_0^{2} e^x \, dx = \frac{1}{2} [e^x]_0^2 = \frac{1}{2}(e^2 - 1)
favg=e2127.389123.195f_{avg} = \frac{e^2 - 1}{2} \approx \frac{7.389 - 1}{2} \approx 3.195

Note: For an exponential, the average is closer to the larger end because exponentials grow rapidly.

Example 4: Finding Where f(c) = f_avg

Problem: For f(x)=4x2f(x) = 4 - x^2 on [0,2][0, 2], find the value cc where f(c)=favgf(c) = f_{avg}.

Solution:

Step 1: Find the average value:

favg=1202(4x2)dx=12[4xx33]02f_{avg} = \frac{1}{2} \int_0^2 (4 - x^2) \, dx = \frac{1}{2} \left[ 4x - \frac{x^3}{3} \right]_0^2
=12(883)=12163=83= \frac{1}{2} \left( 8 - \frac{8}{3} \right) = \frac{1}{2} \cdot \frac{16}{3} = \frac{8}{3}

Step 2: Solve f(c)=favgf(c) = f_{avg}:

4c2=83    c2=483=43    c=231.1554 - c^2 = \frac{8}{3} \implies c^2 = 4 - \frac{8}{3} = \frac{4}{3} \implies c = \frac{2}{\sqrt{3}} \approx 1.155
c=2331.155[0,2]c = \frac{2\sqrt{3}}{3} \approx 1.155 \in [0, 2]

Real-World Applications

Physics: Average Velocity

Problem: An object's velocity is v(t)=3t2+2v(t) = 3t^2 + 2 m/s for t[0,4]t \in [0, 4] seconds. Find the average velocity.

Solution:

vavg=1404(3t2+2)dt=14[t3+2t]04v_{avg} = \frac{1}{4} \int_0^4 (3t^2 + 2) \, dt = \frac{1}{4} [t^3 + 2t]_0^4
=14(64+8)=724=18 m/s= \frac{1}{4}(64 + 8) = \frac{72}{4} = 18 \text{ m/s}

Note: Average velocity also equals total displacement divided by time: if s(t)=t3+2ts(t) = t^3 + 2t, then vavg=(s(4)s(0))/4=72/4=18v_{avg} = (s(4) - s(0))/4 = 72/4 = 18.

Engineering: Average Temperature

Problem: The temperature in a room over a 12-hour period follows T(t)=20+5sin(πt12)T(t) = 20 + 5\sin\left(\frac{\pi t}{12}\right) °C, where tt is hours. Find the average temperature.

Solution:

Tavg=112012(20+5sin(πt12))dtT_{avg} = \frac{1}{12} \int_0^{12} \left( 20 + 5\sin\left(\frac{\pi t}{12}\right) \right) dt
=112[20t60πcos(πt12)]012= \frac{1}{12} \left[ 20t - \frac{60}{\pi}\cos\left(\frac{\pi t}{12}\right) \right]_0^{12}
=112(24060π(1)+60π(1))=112(240+120π)23.2°C= \frac{1}{12}\left( 240 - \frac{60}{\pi}(-1) + \frac{60}{\pi}(1) \right) = \frac{1}{12}\left( 240 + \frac{120}{\pi} \right) \approx 23.2°C

Economics: Average Cost

Problem: The marginal cost of production is MC(q)=10+0.1qMC(q) = 10 + 0.1q dollars per unit for quantities q[0,100]q \in [0, 100]. Find the average marginal cost.

Solution:

MCavg=11000100(10+0.1q)dq=1100[10q+0.05q2]0100MC_{avg} = \frac{1}{100} \int_0^{100} (10 + 0.1q) \, dq = \frac{1}{100} [10q + 0.05q^2]_0^{100}
=1100(1000+500)=$15 per unit= \frac{1}{100}(1000 + 500) = \$15 \text{ per unit}

This tells us the "typical" cost per additional unit over the production range.

Interactive: Applications Demo

Explore average value in different real-world contexts:

Real-World Average Value Applications

An object accelerates with velocity v(t) = at² + v₀. Find the average velocity over the time interval.

Time (s)Velocity (m/s)
Interval
[0.0, 4.0]
Total (Integral)
62.67
Average
15.67 m/s

Machine Learning Connection: Expected Value

The average value of a function is intimately connected to one of the most fundamental concepts in probability and machine learning: expected value.

Expected Value as a Weighted Average

For a continuous random variable XX with probability density function (PDF) f(x)f(x), the expected value is:

E[X]=xf(x)dx\mathbb{E}[X] = \int_{-\infty}^{\infty} x \cdot f(x) \, dx

This is precisely an average value — but instead of dividing by the interval length, we weight each value xx by its probability density f(x)f(x).

The Deep Connection

In probability, the PDF f(x)f(x) integrates to 1 over its entire domain. So expected value is a weighted average where the weights are probabilities. The average value formula is the special case where all xx-values are weighted equally (uniform distribution).

Expected Loss in Machine Learning

In ML, we often minimize expected loss:

L(θ)=Exp[(θ,x)]=(θ,x)p(x)dxL(\theta) = \mathbb{E}_{x \sim p}[\ell(\theta, x)] = \int \ell(\theta, x) \cdot p(x) \, dx

This is the average value of the loss function \ell weighted by the data distribution p(x)p(x).

Why Sample Mean Works

In practice, we approximate expected values with sample means:

E[X]1ni=1nxi\mathbb{E}[X] \approx \frac{1}{n} \sum_{i=1}^{n} x_i

This is exactly the discrete average! The Law of Large Numbers guarantees that as nn \to \infty, the sample mean converges to the true expected value.

ConceptDiscrete VersionContinuous Version
Average/Mean(1/n) Σᵢ xᵢ(1/(b-a)) ∫ₐᵇ f(x) dx
Expected ValueΣᵢ xᵢ · P(X=xᵢ)∫ x · f(x) dx
Expected Loss(1/n) Σᵢ ℓ(θ, xᵢ)∫ ℓ(θ, x) · p(x) dx

Root Mean Square (RMS) in Signals

In signal processing, we often use the RMS value:

frms=1baab[f(x)]2dxf_{rms} = \sqrt{\frac{1}{b-a} \int_a^b [f(x)]^2 \, dx}

This is the square root of the average value of f2f^2. For a sine wave Asin(ωt)A\sin(\omega t), the RMS is A/2A/\sqrt{2}. This is why household AC voltage labeled "120V" is actually referring to the RMS value.


Python Implementation

Computing Average Values

The following code demonstrates how to compute average values using numerical integration:

Average Value of a Function
🐍average_value.py
3Average Value Function

The average value formula divides the integral (total area) by the interval length (b-a). This gives the height of a rectangle with the same area.

20Numerical Integration

We use scipy.integrate.quad for accurate numerical integration. For simple functions, we could also use FTC Part 2 with exact antiderivatives.

38Polynomial Example

For f(x) = x² over [0, 3]: the integral is 9, so the average is 9/3 = 3. Note this is NOT simply (f(0) + f(3))/2 = 4.5!

48Sine Example

The average value of sin(x) over one complete arch [0, π] is 2/π ≈ 0.637. This represents the average height of the sine wave.

73Visualization

The key visual insight: the rectangle with height = average value has exactly the same area as the region under the curve.

102 lines without explanation
1import numpy as np
2from scipy import integrate
3import matplotlib.pyplot as plt
4
5def average_value(f, a, b, n_points=1000):
6    """
7    Compute the average value of a function f over [a, b].
8
9    The average value formula:
10    f_avg = (1/(b-a)) * ∫[a to b] f(x) dx
11
12    Parameters:
13    -----------
14    f : callable - The function to average
15    a, b : float - The interval endpoints
16    n_points : int - Points for numerical integration
17
18    Returns:
19    --------
20    float : The average value of f over [a, b]
21    """
22    # Compute the definite integral
23    integral, error = integrate.quad(f, a, b)
24
25    # Divide by the interval length
26    avg = integral / (b - a)
27
28    return avg
29
30def demonstrate_average_value():
31    """
32    Demonstrate the average value concept with several examples.
33    """
34    print("=" * 60)
35    print("Average Value of a Function")
36    print("=" * 60)
37
38    # Example 1: f(x) = x² over [0, 3]
39    f1 = lambda x: x**2
40    a1, b1 = 0, 3
41    avg1 = average_value(f1, a1, b1)
42
43    print(f"\nExample 1: f(x) = x² over [0, 3]")
44    print(f"  Integral: ∫₀³ x² dx = [x³/3]₀³ = 9")
45    print(f"  Average value: 9 / (3-0) = {avg1:.4f}")
46    print(f"  Note: This is NOT (0² + 3²)/2 = 4.5!")
47
48    # Example 2: f(x) = sin(x) over [0, π]
49    f2 = np.sin
50    a2, b2 = 0, np.pi
51    avg2 = average_value(f2, a2, b2)
52
53    print(f"\nExample 2: f(x) = sin(x) over [0, π]")
54    print(f"  Integral: ∫₀^π sin(x) dx = [-cos(x)]₀^π = 2")
55    print(f"  Average value: 2 / π = {avg2:.4f}")
56    print(f"  Physical meaning: average height of one arch of sine")
57
58    # Example 3: f(x) = e^x over [0, 1]
59    f3 = np.exp
60    a3, b3 = 0, 1
61    avg3 = average_value(f3, a3, b3)
62
63    print(f"\nExample 3: f(x) = eˣ over [0, 1]")
64    print(f"  Integral: ∫₀¹ eˣ dx = e - 1 ≈ {np.e - 1:.4f}")
65    print(f"  Average value: (e - 1) / 1 = {avg3:.4f}")
66
67    # Visualization
68    fig, axes = plt.subplots(1, 3, figsize=(15, 4))
69
70    examples = [
71        (f1, a1, b1, avg1, 'x²', '[0, 3]'),
72        (f2, a2, b2, avg2, 'sin(x)', '[0, π]'),
73        (f3, a3, b3, avg3, 'eˣ', '[0, 1]')
74    ]
75
76    for ax, (f, a, b, avg, name, interval) in zip(axes, examples):
77        x = np.linspace(a, b, 200)
78        y = f(x)
79
80        # Plot function and fill area
81        ax.fill_between(x, y, alpha=0.3, color='blue', label='Area under curve')
82        ax.plot(x, y, 'b-', linewidth=2, label=f'f(x) = {name}')
83
84        # Plot average value line
85        ax.axhline(y=avg, color='red', linestyle='--', linewidth=2,
86                   label=f'Average = {avg:.3f}')
87
88        # Fill rectangle with same area
89        ax.fill_between([a, b], [avg, avg], alpha=0.2, color='red',
90                        label='Rectangle (same area)')
91
92        ax.set_xlabel('x')
93        ax.set_ylabel('f(x)')
94        ax.set_title(f'{name} over {interval}')
95        ax.legend(fontsize=8)
96        ax.grid(True, alpha=0.3)
97
98    plt.tight_layout()
99    plt.savefig('average_value_demo.png', dpi=150, bbox_inches='tight')
100    plt.show()
101
102    print("\n" + "=" * 60)
103    print("Key Insight: The rectangle with height = average value")
104    print("has the SAME AREA as the region under the curve!")
105    print("=" * 60)
106
107demonstrate_average_value()

Machine Learning Connections

See how average value connects to expected value and loss functions:

Average Value in Probability and ML
🐍average_value_ml.py
3Expected Value Connection

The expected value E[X] = ∫ x·f(x) dx is exactly the average value concept applied to probability. It's the 'weighted average' where weights are probabilities.

22Uniform Distribution

For Uniform[0,1], E[X] = ∫₀¹ x dx = 1/2. The average value of x over [0,1] weighted uniformly is just the midpoint.

49Normal Distribution

For N(μ, σ²), E[X] = μ by symmetry. The integral of x·f(x) equals μ because the distribution is symmetric around μ.

66MSE in Machine Learning

Mean Squared Error is the expected (average) squared loss. Minimizing MSE is equivalent to finding the predictor that minimizes average loss.

95RMS Values

Root Mean Square is the square root of the average of f². For AC signals, RMS gives the 'effective' value that produces the same power as DC.

138 lines without explanation
1import numpy as np
2from scipy import integrate, stats
3
4def expected_value_as_average():
5    """
6    The expected value E[X] is the 'average value' of a random variable.
7
8    For a continuous RV with PDF f(x):
9    E[X] = ∫ x * f(x) dx
10
11    This is exactly the average value formula applied to g(x) = x * f(x)
12    weighted by the probability density!
13    """
14    print("Expected Value as Average Value")
15    print("=" * 55)
16
17    # Example 1: Uniform distribution on [0, 1]
18    # PDF: f(x) = 1 for x ∈ [0, 1]
19    # E[X] = ∫₀¹ x * 1 dx = 1/2
20
21    uniform_pdf = lambda x: 1.0  # constant
22    integrand1 = lambda x: x * uniform_pdf(x)
23    expected_uniform, _ = integrate.quad(integrand1, 0, 1)
24
25    print(f"\nUniform[0, 1]:")
26    print(f"  PDF: f(x) = 1")
27    print(f"  E[X] = ∫₀¹ x dx = {expected_uniform:.4f}")
28    print(f"  (This is the 'center of mass' of the distribution)")
29
30    # Example 2: Exponential distribution with λ = 2
31    # PDF: f(x) = 2e^(-2x) for x ≥ 0
32    # E[X] = ∫₀^∞ x * 2e^(-2x) dx = 1/2
33
34    lambda_param = 2.0
35    exp_pdf = lambda x: lambda_param * np.exp(-lambda_param * x)
36    integrand2 = lambda x: x * exp_pdf(x)
37    expected_exp, _ = integrate.quad(integrand2, 0, np.inf)
38
39    print(f"\nExponential(λ=2):")
40    print(f"  PDF: f(x) = 2e^(-2x)")
41    print(f"  E[X] = ∫₀^∞ x · 2e^(-2x) dx = {expected_exp:.4f}")
42    print(f"  (Average waiting time = 1/λ)")
43
44    # Example 3: Normal distribution N(μ, σ²)
45    # The expected value is μ (by symmetry and integration)
46
47    mu, sigma = 3.0, 1.5
48    normal_pdf = lambda x: stats.norm.pdf(x, mu, sigma)
49    integrand3 = lambda x: x * normal_pdf(x)
50    expected_normal, _ = integrate.quad(integrand3, mu - 10*sigma, mu + 10*sigma)
51
52    print(f"\nNormal(μ=3, σ=1.5):")
53    print(f"  E[X] = ∫ x · f(x) dx = {expected_normal:.4f}")
54    print(f"  (By symmetry, E[X] = μ = 3)")
55
56    print("\n" + "=" * 55)
57    print("Connection: Expected Value IS an Average Value!")
58    print("  E[X] = 'average' of x weighted by probability density")
59    print("=" * 55)
60
61def loss_function_averaging():
62    """
63    In ML, we often average loss over a dataset.
64
65    For continuous distributions, this becomes:
66    Expected Loss = ∫ L(θ, x) * p(x) dx
67
68    This is the average value of the loss function!
69    """
70    print("\n\nAverage Loss in Machine Learning")
71    print("=" * 55)
72
73    # Simple example: Mean Squared Error for a constant predictor
74    # Data comes from N(μ, σ²), we predict a constant θ
75    # MSE(θ) = E[(X - θ)²] = ∫ (x - θ)² * f(x) dx
76
77    true_mu = 5.0
78    sigma = 2.0
79
80    def mse_for_theta(theta):
81        '''Compute E[(X - θ)²] when X ~ N(μ, σ²)'''
82        normal_pdf = lambda x: stats.norm.pdf(x, true_mu, sigma)
83        integrand = lambda x: (x - theta)**2 * normal_pdf(x)
84        mse, _ = integrate.quad(integrand, true_mu - 10*sigma, true_mu + 10*sigma)
85        return mse
86
87    # Test different predictors
88    thetas = [3, 4, 5, 6, 7]
89    print("\nMSE for different constant predictors (true μ = 5):")
90    print("-" * 40)
91
92    for theta in thetas:
93        mse = mse_for_theta(theta)
94        print(f"  θ = {theta}: MSE = {mse:.4f}")
95
96    print("\nNote: MSE is minimized at θ = μ (the expected value)!")
97    print("This is why we use sample mean as our predictor.")
98
99    # Analytical result: E[(X-θ)²] = σ² + (μ-θ)²
100    print("\nAnalytical formula: MSE = σ² + (μ - θ)²")
101    print(f"  At θ = μ: MSE = σ² = {sigma**2:.4f}")
102
103def temporal_averaging():
104    """
105    Average value over time appears in:
106    - RMS (Root Mean Square) values in signals
107    - Time-averaged quantities in physics
108    - Moving averages in time series
109    """
110    print("\n\nTemporal Averaging in Signals")
111    print("=" * 55)
112
113    # RMS of a sine wave
114    # f(t) = A*sin(ωt)
115    # f_rms = sqrt( (1/T) ∫₀^T [A*sin(ωt)]² dt ) = A/√2
116
117    A = 10.0  # amplitude
118    omega = 2 * np.pi  # angular frequency
119    T = 1.0  # period
120
121    f = lambda t: A * np.sin(omega * t)
122    f_squared = lambda t: f(t)**2
123
124    # Average of f²
125    avg_f_squared, _ = integrate.quad(f_squared, 0, T)
126    avg_f_squared /= T
127
128    rms = np.sqrt(avg_f_squared)
129    theoretical_rms = A / np.sqrt(2)
130
131    print(f"\nSine wave: f(t) = {A}·sin(2πt)")
132    print(f"  Average value of f(t): 0 (symmetric)")
133    print(f"  Average value of f(t)²: {avg_f_squared:.4f}")
134    print(f"  RMS value: √(avg of f²) = {rms:.4f}")
135    print(f"  Theoretical: A/√2 = {theoretical_rms:.4f}")
136    print("\nRMS is crucial for:")
137    print("  - AC voltage/current (e.g., 120V RMS)")
138    print("  - Signal power calculations")
139    print("  - Audio processing")
140
141expected_value_as_average()
142loss_function_averaging()
143temporal_averaging()

Common Mistakes to Avoid

Mistake 1: Averaging endpoints instead of integrating

Wrong: favg=f(a)+f(b)2f_{avg} = \frac{f(a) + f(b)}{2}

Correct: favg=1baabf(x)dxf_{avg} = \frac{1}{b-a} \int_a^b f(x) \, dx

The endpoint average only works for linear functions! For curves, you must integrate.

Mistake 2: Forgetting the 1/(b-a) factor

Wrong: favg=abf(x)dxf_{avg} = \int_a^b f(x) \, dx

Correct: The integral gives the total (area), not the average. You must divide by the interval length to get the average.

Mistake 3: Confusing average value with maximum/minimum

The average value is typically between the minimum and maximum values, but it's usually not equal to either. For non-constant functions, m<favg<Mm < f_{avg} < M.

Mistake 4: Using the wrong interval in applications

Make sure you're averaging over the correct interval. The average temperature "during the day" should use the daytime interval, not a full 24-hour period.

Mistake 5: Ignoring signs for signed area

If f(x)<0f(x) < 0 for part of the interval, that region contributes negatively to the average. The average of sin(x) over [0,2π][0, 2\pi] is 0, not 2/π2/\pi!


Test Your Understanding

Average Value QuizQuestion 1 of 8
What is the average value of f(x) = 2x on the interval [0, 4]?

Summary

The average value of a function extends the familiar concept of arithmetic mean to continuous functions using the definite integral.

The Central Formula

favg=1baabf(x)dxf_{avg} = \frac{1}{b - a} \int_a^b f(x) \, dx

Average Value = Total Accumulation ÷ Interval Length

Key Results

ConceptFormulaMeaning
Average Valuef_avg = (1/(b-a)) ∫ₐᵇ f(x) dxHeight of equal-area rectangle
MVT for Integrals∃c: f(c) = f_avgContinuous functions attain their average
Expected ValueE[X] = ∫ x·f(x) dxProbability-weighted average
RMS Valuef_rms = √((1/(b-a)) ∫ₐᵇ f² dx)Square root of average of squares

Key Takeaways

  1. Average value generalizes arithmetic mean — from finitely many values to infinitely many (continuous) values
  2. The average value is the height of a rectangle with the same area as the region under the curve
  3. MVT for Integrals guarantees that continuous functions actually achieve their average value somewhere
  4. Expected value in probability is a probability-weighted version of average value
  5. Don't confuse average value with the average of endpoints — you must integrate!
  6. Applications include average temperature, velocity, power, cost, and many quantities in science and engineering
The Core Insight:
"The average value of a function is the height that would give a rectangle the same area as the region under the curve — it's how we extend the concept of 'mean' to the continuous world."
Coming Next: In the next section, we'll explore Numerical Integration: Trapezoidal Rule — methods for approximating definite integrals when antiderivatives are difficult or impossible to find.
Loading comments...