# Least squares fit or decomposition of average points (from data)

I have a set of data consisting of the averages of a function $g(r)$ at regular intervals; i.e. my first datapoint is the average of the function from $0$ to $\Delta r$, the second point is the average from $\Delta r$ to $2\Delta r$ and so on.

In the end I want to decompose the function (that gives rise to these averages) in a certain basis. The easy way is to just treat the average points as points of the function and then either use a least squares fit or the normal "inner product-trick" to get the coefficients in this basis.

But I need to get closer to the underlying function. This of course means using some assumptions, since all I know is the averages, but demanding continuity of the function and of its derivatives (to one or more degrees) should do the trick.

I've tried some iterative methods, for example for 3rd degree polynomials: I divide the function into intervals of $\Delta r$ and use a 3rd degree polynomial on each interval. Then I start at the left and find the coefficients of the polynomial by using that the average should equal the data point and that the function and its first two derivatives should be continuous (between the intervals). The idea is then to use the resulting function with one of my methods (least squares, inner product) to find the decomposition.

However this iterative method gives a severely oscillating function. Say the function in the first interval overshoots a little bit, then the next has to undershoot and from there on it gets worse and worse, ending in the worst case with a function oscillating wildly around the data points (although it does satisfy the demands), and so far never ending with a satisfying function.

There must be a better way of doing this, either a completely different way of fitting/decomposing to averages of data points or another way of making my functions between intervals as described above. Both theoretic solutions and software solutions (matlab/mathematica functions etc) would be welcome. Any ideas?

EDIT: Here is a plot of the data:

• You might try Chebfun. It has a lot of good interpolation tools. – icurays1 Apr 8 '13 at 16:04
• Can you include a plot of your data? – J. M. is a poor mathematician Apr 8 '13 at 17:41
• Sure, here you go. It is a correlation function. – jorgen Apr 8 '13 at 17:53
• @icurays1: I've looked a bit into Chebfun, and although very neat I don't immediately see how it applies in my case; there are nice interpolation tools but I don't see how to "fit with average" instead of to the points themselves. Did you have a specific way to use Chebfun in mind? – jorgen Apr 8 '13 at 19:15
• I would suggest you just fit the data you have and not worry about the fact that the points are averages unless you know something about how the value varies within a time period. It will be quite smooth. You could use cubic splines if you want to ensure continuity of the derivatives across the points. – Ross Millikan Apr 11 '13 at 16:21