Question

I've been looking for a while onto websearch, however, possibly or probably I am missing the right terminology.

I have arbitrary sized arrays of scalars ...

array = [n_0, n_1, n_2, ..., n_m]

I also have a function f->x->y, with 0<=x<=1, and y an interpolated value from array. Examples:

array = [1,2,9]

f(0)    = 1
f(0.5)  = 2
f(1)    = 9

f(0.75) = 5.5

My problem is that I want to compute the average value for some interval r = [a..b], where a E [0..1] and b E [0..1], i.e. I want to generalize my interpolation function f->x->y to compute the average along r.

My mind boggles me slightly w.r.t. finding the right weighting. Imagine I want to compute f([0.2,0.8]):

array     -->  1       |      2       |      9
[0..1]    -->  0.00   0.25   0.50   0.75  1.00
[0.2,0.8] -->        ^___________________^

The latter being the range of values I want to compute the average of.

Would it be mathematically correct to compute the average like this?: *

          1 * (1-0.8)       <- 0.2 'translated' to [0..0.25]
        + 2 * 1
avg =   + 9 * 0.2           <- 0.8 'translated' to [0.75..1]
       ----------
            1.4             <-- the sum of weights
Was it helpful?

Solution

This looks correct.

In your example, your interval's length is 0.6. In that interval, your number 2 is taking up (0.75-0.25)/0.6 = 0.5/0.6 = 10/12 of space. Your number 1 takes up (0.25-0.2)/0.6 = 0.05 = 1/12 of space, likewise your number 9.

This sums up to 10/12 + 1/12 + 1/12 = 1.

For better intuition, think about it like this: The problem is to determine how much space each array-element covers along an interval. The rest is just filling the machinery described in http://en.wikipedia.org/wiki/Weighted_average#Mathematical_definition .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top