Finding the average value of a function