When we are given a dataset of a function sampled in many points, and we want to find approximation of the unknown function in-between these points, one of the go-to methods for practitioners is fitting a Cubic Spline.

I am using such a method to approximate derivatives at intermediate points.

My QUESTION is, for what kind of functions a cubic splines may not a be a good choice for approximating?


Since a cubic spline can contain multiple cubic segments, it is capable of approximating almost any function as close as possible (if the number of cubic segments in the spline is not limited). If your approximation method is to sample points along the function and create a cubic spline interpolating these sampled points, then the approximation accuracy is highly related to the number of sampled points and how the points are distributed.

Cubic splines might not be as appropriate for approximating functions with $C^1$ discontinuities (such as a step function) as they will almost always produce bad approximation around where the $C^1$ discontinuity occurs.


A cubic would be a bad approximation if the function is too bumpy. Suppose we try to approximate $f(x) = \sin 10x$ by a cubic $g(x) = a + bx + cx^2 + dx^3$ on the interval $x \in [0, 2\pi]$. Then we have a calculus problem:

$$ \min_{a,b,c,d \in \mathbb{R}}\max_{x \in [0,2\pi]} \left|\, \sin 10x - \big(a + bx + cx^2 + dx^3\big)\,\right| $$

I'm pretty sure the best cubic you could find would be pretty lousy (I'm looking for a bound). Instead we could take a smaller interval:

$$ \min_{a,b,c,d \in \mathbb{R}}\max_{x \in [0,2\pi]} \left|\, \sin x - \big(a + bx + cx^2 + dx^3\big)\,\right| $$

The first step would be to take the derivative and set it to zero (to find the extrema):

$$ \cos x = b + 2cx + 3dx^2 $$

Or even a guess-and-check method might work... how about $g(x) = x(x-\pi)(x-2\pi)$ ? Can you find a better choice of $(a,b,c,d)$ ?

I found these numbers with a computer:

  • $f(x) = \sin 2\pi x$
  • $g(x) = 20\,x\,(x - \frac{1}{2})\,(x - 1)$

Which is which?

enter image description here

  • $\begingroup$ We could have that $f'(0) = f'(1) = 2\pi$ so that if $g(x) = Ax(x-1/2)(x-1)$ then $g'(x) = A(3x^2 - 3x + \frac{1}{2})$ and $g'(0) = g'(1) = A/2 = 2\pi$ and we get $A = 4\pi \approx 12$. This is a much worse fit. $\endgroup$ – cactus314 Mar 27 '18 at 14:30
  • 1
    $\begingroup$ If you approximate it with a cubic spline (which is what the OP is talking about), then the approximation will be as good as you want because you can have as many cubic segments in the spline as the approximation tolerance needs. $\endgroup$ – fang Mar 28 '18 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.