MATLAB: Spline approximation with constraints

constrained splinecurve fittingsmoothspline

Hey everyone. I have a dense set of points x,y that seem to fall on a single curve:
I would like to find a smooth function to mach the data. Specifically, I would like it to fulfill the following criteria:
-It is the closest to the data (say in a least squares sense)
-Its first and second derivatives vanishes only once (hopefully at the maximum and inflection points of the original data)
I have tried doing that using smoothing spline approximation (not sure if this is the correct approach here with such a dense dataset, I any of you have a better idea i would like to hear). So far my best results were obtained by manually picking ~50 points from the data, using:
[xi,yi] = ginput;
and fitting a spline to them, using
splinetools(xi,yi)
And playing with the parameter in the smoothing spline approximation method until the spline matches.
Obviously that's very crude and doesn't satisfy my criteria. How are things like that typically done? Is there a way to put constraints on the number of critical and inflection points?

Best Answer

There are several problems in what you are trying to do.
The obvious one is that splines abhor singularities, and you have one on the left end of that curve. Made up of polynomial segments, you can expect them to fail there.
As well, a standard least squares spline, or a smoothing spline both assume the error is in y only. But you clearly have a cloud that spreads out along the curve in both directions. So any least squares or smoothing spline must perform poorly. So I would not even bother trying to use my own SLM toolbox on this data.
Orthogonal regressions using splines are difficult.
I see that you have supplied the data, so I'll take a look at it. Perhaps I can make a stab at something...