0
$\begingroup$

I am implementing the cubic spline method to interpolate the function: $$f(x)=\sin(x);\ -π≤0≤π$$ I am using this paper by Antony Jameson to construct my code, with a few modifications to correct the various typos on that paper. I am using uniformly spaced anchor points and natural spline boundary conditions, and I am breaking the range of $-π ≤ 0 ≤ π$ into $100$ splines/$101$ points.

When I set the number of data points to interpolate from to be $N=4$ and $N=8$ and compared it to the actual graph of the function, the resulting graph looked like this:

which is fine and dandy. However, when I set the number of data points to be $N=10$ and $N=16$, the result is not as good:

As we can see from the second graph, the interpolation produces zero values on the positive end of the graph when I input $10$ and $16$ data points. When I checked the value of my interpolation, I found that the last three spline-ends yield zeroes like this:

$$\small\begin{bmatrix} -0.00000 & -0.06274 & -0.12524 & \cdots & 0.24669 & 0.18695 & 0.00000 & 0.00000 & 0.00000\\ \end{bmatrix}$$

I have scoured the net and found something called Runge's phenomenon, and it seems that my implementation of the cubic spline has run into that phenomenon. However, when reading further, I have found that the phenomenon should not occur in cubic splines.

What am I doing wrong? Is there something wrong with my implementation, or is that phenomenon occurs to everyone applying the cubic spline to the sine function?

$\endgroup$
  • $\begingroup$ Are you using uniformly spaced anchor points? Natural spline boundary conditions? (In the latter case the sine function "cheats" because the real function satisfies these conditions, so also test with $\cos x$.) $\endgroup$ – Oscar Lanzi Dec 8 '18 at 10:45
  • $\begingroup$ Yes, I'm using uniformly spaced anchor points and natural spline boundary conditions. I tried testing with $cos(x)$ a few seconds ago and it produces the same error--the last three spline-ends have zeroes as their value. $\endgroup$ – sagungrp Dec 8 '18 at 10:51
  • $\begingroup$ Are you using single precision floating number in your codes? If yes, try using double precision floating numbers. $\endgroup$ – fang Dec 8 '18 at 22:07

Your Answer

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

Browse other questions tagged or ask your own question.