Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

 Open In Colab

Splines were formulated to relieve oscillations attributed to Runge’s phenomenon by piecing together a series of lower-order polynomials and requiring smoothness. Consider a polynomial over the interval between xix_i and xi+1x_{i+1}, and assert:

  • y(xi)=yiy(x_i) = y_i

  • y(xi+1)=yi+1y(x_{i+1}) = y_{i+1}

  • y′(xi)y'(x_i) be continuous

  • y′′(xi)y''(x_i) be continuous

With these 4 constraints, it is clear we are looking for cubic functions, and therefore these splines are piecewise cubic curves.

We will be describing the splines in terms of the knots, kik_i which parameterize the curves. For these splines, these knots are the second derivatives at a point xix_i.

To find the coefficients of the cubic splines, consider that the second derivative is linear and represent it with a 2-point Lagrange interpolation:

yi,i+1′′=kiPi(x)+ki+1Pi+1(x)=ki[x−xi+1]+ki+1[x−xi]xi−xi+1\begin{aligned} y''_{i, i+1} &= k_i P_i(x) + k_{i+1} P_{i+1}(x) \\ &= \frac{k_i [x-x_{i+1}] + k_{i+1} [x-x_i]}{x_i-x_{i+1}} \end{aligned}

Using the constraints above we end up with:

ki−1[xi−1−xi]+2ki[xi−1−xi+1]+ki+1[xi−xi+1]=6[yi−1−yixi−1−xi−yi−yi+1xi−xi+1]k_{i-1}[x_{i-1}-x_i] + 2 k_i [x_{i-1} - x_{i+1}] + k_{i+1}[x_i-x_{i+1}] = 6\left[ \frac{y_{i-1}-y_i}{x_{i-1}-x_i} - \frac{y_{i}-y_{i+1}}{x_{i}-x_{i+1}} \right]

which is a tridiagonal matrix!

[1000000000014100000000014100000000014100000000014100000000014100000000014100000000014100000000014100000000014100000000001][k1k2k3k4k5k6k7k8k9k10k11]=[0−0.424−1.052−0.8911.1382.6541.138−0.891−1.052−0.4240]\begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 4 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 4 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 4 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 4 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 4 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 4 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} k_1 \\ k_2\\ k_3\\ k_4\\ k_5\\ k_6\\ k_7\\ k_8\\ k_9\\ k_{10}\\ k_{11} \end{bmatrix} = \begin{bmatrix} 0\\ -0.424 \\ -1.052 \\ -0.891 \\ 1.138 \\ 2.654 \\ 1.138 \\ -0.891 \\ -1.052 \\ -0.424 \\ 0 \end{bmatrix}

Visualizing Cubic Splines

We can compute and visualize a cubic spline interpolation of the function f(x)=exp⁡(−(x2)2)f(x) = \exp\left(-\left(\frac{x}{2}\right)^2\right) using scipy.interpolate.CubicSpline.

Analysis of cubic splines

We note:

  • Cubic splines are stiffer in that they don’t have high-frequency oscillations (thus avoiding Runge’s phenomenon).

  • The concept of smoothness is easy in 1D, but what does it mean for 2D+? How would you ensure continuity along an edge?

  • Specifying smoothness as part of the goals going in suggest this is more of a global scheme. This requires simultaneous linears systems to be solved.