What is the average value of number-range along interval?

202 Views Asked by At

Given a finite range of real numbers $$x = x_0,x_1,x_2,...,x_n$$

and an interpolation function $f(c), c\in[0..1]$ (such that e.g. $c(0)=x_0$, $c(1)=x_n$),

and an interval $$I =[u,v], u\in[0..1], v\in[0..1]$$

what would be the accurate way to get the average value of $x$ within $I$? Is there a well known, finite algorithm, which correctly weights each $x$?

Usage example in pseudo code to support my question:

list = [1,2,9]
a = average(list, interval(0.25, 9))
1

There are 1 best solutions below

0
On

The question boils down to:

How much area along your interval is occupied by each list-element, and this area will then be your input to computing a weighted average (see also http://en.wikipedia.org/wiki/Weighted_average#Mathematical_definition).

E.g., given $\{1,2,9\}$, with the number $2$ occupying the interval $[0.25..0.75]$. You want to compute the average along the interval $[0.2..0.8]$. Then $1$ occupies $\frac{1}{12}$ of space along your query-interval:

$$\frac{0.25-0.2}{0.6} = \frac{0.05}{0.6} = \frac{1}{12}$$

Your number $2$ occupies

$$\frac{0.5}{0.6} = \frac{10}{12}$$

of space. Likewise for your number $9$.

These are your weights:

$$ w = \{\frac{1}{12}, \frac{10}{12}, \frac{1}{12}\}$$

Or just the intermediary values, it doesn't matter as long as the relations are kept:

$$w = \{0.05, 0.5, 0.05\}$$

and together with your initial list

$$x = \{1,2,9\}$$

your average along the interval becomes

$$ \bar{x} = \frac{0.05\cdot1 + 0.5\cdot2 + 0.05\cdot9}{0.05+0.5+0.05} = \frac{1.5}{0.6} = 2.5 $$