R – spline for non differentiable function

apache-flexinterpolationspline

I have a function that sometimes is non-differentiable at a point. When I now use a spline (Bezierspline in degrafa) for interpolation the interpolation at this point does not work as expected (at this point my function has a kink). Now when interpolating with a spline it draws some kind of loop around this point. I think this happens because the spline needs the derivatives of the functions which is not unique at this point.

Is that right? What would you advise me to do in this case?

Thanks in advance

Sebastian

Best Answer

You can't calculate the gradient of a "kink" (as you so eloquently put it). If you really need a gradient at such a point (x), I'd just average the gradient at (x-d) and (x+d) where d is a small enough delta. It's as mathematically valid as any other single answer you're likely to get.

For example, the function:

f(x) = |x|

will produce:

\   |   /
 \  |  /
  \ | /
   \|/
----+----

where there is no gradient at the origin (0,0). However, averaging the gradients at -0.0001 (gradient = -1) and +0.0001 (gradient = +1) will give you a gradient of zero (flat line).

This should give a half-decent answer for other equations that produce non-symmetrical gradients at (x-d) and (x+d) as well.

What I would do, since it's licensed under MIT, is to modify the source to allow an option for the Bezierspline to use that +/- delta method to calculate gradients at the non-continuous points. Maybe even push back the source changes to the developers if you think it's a worthwhile addition.

Related Topic