Average value.

Suppose you picked at random 1000 numbers between 0 and 1. What would you expect the average of the squares of these numbers to be, about?

Solution .

First let's look up how rand works.

> ?rand

So to get a function which returns random numbers between 0 and 1, we could do something like this:

> f := rand(10^7)/10.^7:

> f();

[Maple Math]

> s := 0:
for i from 1 to 1000 do
s := s+f()^2 od:
s/1000;

[Maple Math]

>

Looks like its around a third.

On the other hand, you could estimate the average value by averaging the values at n equally spaced points in the interval. Here is a procedure for doing this. The inputs are f, the function to be averaged; a,b, the endpoints of the interval where the function is evaluated; and n, the number of equally spaced values to be averaged.

> av := proc(f,a,b,n)
local i,dx;
dx := (b-a)/n;
evalf(sum(f(a+i*dx),i=1..n)/n);
end:

>

So to estimate the average value of x^2 as x ranges from 0 to 1, we could generate a sequence of estimates

> for i by 100 from 100 to 400 do
print(i, av(x->x^2,0,1,i)) od;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

This seems to give about 1/3 also.

The last estimate can be turned into a regular Riemann sum. Let [Maple Math] denote the length of each subinterval in the regular partition of [a,b] into n subintervals. Then the average and Riemann sum are the same:

[Maple Math]

As n gets large, this Riemann sum converges to the integral of the function over the interval divided by the length of the interval. Thus we are justified in defining the average value as an integral.

Problems.

Exercise: The temperature in the 24 period from 0..24 is given as [Maple Math] . Find the average temperature over the time interval. Find a time t when it is the average temperature. Also find the maximum temperature and minimum temperature.

>

>

Exercise: Suppose f is a continuous function on [a,b], with average value T. Show that there is an x in [a,b] so that f(x) = T.

>

>