Let's say I have a few points and derivatives given for a function and I'd like to find the best fit through the data, which is monotonic. For example, if I take a polynomial ansatz, I get
f[x_] = Sum[a[i] x^i, {i, 0, 4}];
constraints = f[x1] == y1 && f'[x1] == 0 && f[x2] == 0 && f[x3] == y3 && f'[x3] == 0;
result = f[x] /. Solve[constraints, Table[a[i], {i, 0, 4}]][[1]] // FullSimplify;
which for some xi
and yi
sometimes leads to an interpolation that is not monotonic:
as can be seen by the fact that the minimum is not at the region boundary.
How can I produce a fit (with the simplest model possible) that would satisfy all constraints and simultaneously return a result that is monotonic?
EDIT:
More details on the data:
The data is always given in terms of points at the far left and far right boundary of a range (positive on the left and negative on the right), slopes at these points are zero, and the position at which the function crosses the x-axis is also known, so it looks something like:
Example values might be:
Xleft=0;
Xright=1;
Xmid=0.41;
As a list of points:
fvalues={{0,1180},{0.41,0},{1,-570}};
fprimes={{0,0},{1,0}};
for which fourth degree polynomial fit produces the non-monotonic function plotted above. Basically, I'm wondering what would be the simplest function template to fit 3 given points and 2 given slopes to, such that the function is monotonic?