Fitting for piecewise function, with constraints on first/second derivative I have the following problem. 
We have a set of discrete points ($x_i$,$y_i$), defined for $0 \leq x_i \leq r$, where $r$ is an arbitrary value. For values of $0 \leq x \leq r$, the y value is obtained from polynomial interpolation over 6 points, three with $x_i < x$ and three with $x_i > x$.
For $x > r$, y must go to zero. The current technique used is to extrapolate with a polynomial matched on the last 6 points of the set, plus 3 points forced to zero. This leads to weird wiggling due to Runge's phenomenon.
One idea I have is to perform least squares on a negative exponential, which is guaranteed to go to numerical zero. However, the problem occurs at the point where we switch from interpolation to extrapolation, because we want to guarantee the first derivative to be continuous in $r$. Splines (at least the ones I know) don't satisfy these constraints, and a simple extrapolation to negative exponential will produce a non-continuous first derivative.
Do you have any hints on how to tackle this problem ? 
Edit: this is an example of the data (I plot two curves, but they are the same, I just had this plot around).

I need to go to zero by extending the curve beyond point 16 so that it goes to zero only at +infinity (like an negative exponential), with the constraint that in point 16 it must be smooth. I removed the need for the second derivative to have the same sign. This is clearly not possible here.
Note that the points can be considered either exact or not. The problem is that for $x < r$ we assume the points are exact and when $x = x_i$ you should get $y_i$. However, when $x > r$, the points are not considered exact anymore for the extrapolation, thus the need for a least square fitting.
 A: You need to decide how fast you want your function to go to zero, and how sharply it is allowed to curve to get there. For instance, one candidate function has the shape:
$$y = \frac{1}{1+x^2}$$
Or in general:
$$y = \frac{a}{b+(x-c)^2}$$
This has three degrees of freedom, but there are only two constraints, $y(r)$ and $y'(r)$. So there is a whole family of such curves. Basically, the faster you want $y$ to tend to zero, the more sharply it has to bend.  
Also, are you concerned about the asymptotic behaviour? If you want it to approach $0$ exponentially, then you could try something of the form
$$y = e^{-x^2}$$
Or in general:
$$y = ae^{-b(x-c)^2}$$
Again there is an extra degree of freedom, and you have to decide what you want from your model.
Updated to add: After posting my answer, I wondered if what you really want is to choose the function that matches the existing points as best as possible, even though it is not actually going to be used over that range. Is this right? If so, then least squares should be doable. But you still have to decide which basic curve shape you want to use. If you don't have a theoretical model of some kind, I don't see how you're going to do this. What are these data points?
