Lesson 13 of 18

Average Value of a Function

Average Value of a Function

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

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

This generalizes the discrete average f1+f2++fnn\frac{f_1 + f_2 + \cdots + f_n}{n} to a continuous function.

Mean Value Theorem for Integrals

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

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

In other words, ff actually achieves its average value somewhere in the interval.

Geometric Interpretation

The average value is the height of a rectangle with base (ba)(b-a) that has the same area as the region under ff:

favg(ba)=abf(x)dxf_{\text{avg}} \cdot (b-a) = \int_a^b f(x)\, dx

Examples

  • f(x)=xf(x) = x on [0,4][0, 4]: favg=148=2f_{\text{avg}} = \frac{1}{4} \cdot 8 = 2 (the midpoint — makes sense for a linear function)
  • f(x)=x2f(x) = x^2 on [0,3][0, 3]: favg=139=3f_{\text{avg}} = \frac{1}{3} \cdot 9 = 3
  • f(x)=1f(x) = 1 on any interval: favg=1f_{\text{avg}} = 1 (average of a constant is itself)

Applications

  • Average temperature over a day
  • Average power consumed over a cycle
  • Average speed over a journey (area under speed-time curve divided by time)

Your Task

Implement double average_value(double (*f)(double), double a, double b, int n) using the midpoint rule internally.

TCC compiler loading...
Loading...
Click "Run" to execute your code.