Given nodes a = x 0 < x 1 < ⋯ < x n = b a = x_0 < x_1 < \cdots < x_n = b a = x 0 < x 1 < ⋯ < x n = b and f f f defined on [ a , b ] [a, b] [ a , b ] , a cubic spline interpolant for f f f is a function S S S satisfying:
f f f is the function being interpolated, known only through its values f ( x 0 ) , … , f ( x n ) f(x_0), \ldots, f(x_n) f ( x 0 ) , … , f ( x n ) at the nodes (or, for a clamped spline, also through f ′ ( x 0 ) f'(x_0) f ′ ( x 0 ) and f ′ ( x n ) f'(x_n) f ′ ( x n ) ). S S S is the piecewise-cubic approximation to f f f built from those values.
S ( x ) S(x) S ( x ) is a cubic polynomial S j ( x ) S_j(x) S j ( x ) on [ x j , x j + 1 ] [x_j, x_{j+1}] [ x j , x j + 1 ] , for each j = 0 , 1 , … , n − 1 j = 0, 1, \ldots, n-1 j = 0 , 1 , … , n − 1 (piecewise cubic)
S j ( x j ) = f ( x j ) S_j(x_j) = f(x_j) S j ( x j ) = f ( x j ) and S j ( x j + 1 ) = f ( x j + 1 ) S_j(x_{j+1}) = f(x_{j+1}) S j ( x j + 1 ) = f ( x j + 1 ) , for each j = 0 , 1 , … , n − 1 j = 0, 1, \ldots, n-1 j = 0 , 1 , … , n − 1 (interpolation)
S j + 1 ( x j + 1 ) = S j ( x j + 1 ) S_{j+1}(x_{j+1}) = S_j(x_{j+1}) S j + 1 ( x j + 1 ) = S j ( x j + 1 ) , for each j = 0 , 1 , … , n − 2 j = 0, 1, \ldots, n-2 j = 0 , 1 , … , n − 2 (value continuity, implied by interpolation above)
S j + 1 ′ ( x j + 1 ) = S j ′ ( x j + 1 ) S_{j+1}'(x_{j+1}) = S_j'(x_{j+1}) S j + 1 ′ ( x j + 1 ) = S j ′ ( x j + 1 ) , for each j = 0 , 1 , … , n − 2 j = 0, 1, \ldots, n-2 j = 0 , 1 , … , n − 2 (slope continuity)
S j + 1 ′ ′ ( x j + 1 ) = S j ′ ′ ( x j + 1 ) S_{j+1}''(x_{j+1}) = S_j''(x_{j+1}) S j + 1 ′′ ( x j + 1 ) = S j ′′ ( x j + 1 ) , for each j = 0 , 1 , … , n − 2 j = 0, 1, \ldots, n-2 j = 0 , 1 , … , n − 2 (curvature continuity)
one of the following boundary conditions holds:
S ′ ′ ( x 0 ) = S ′ ′ ( x n ) = 0 S''(x_0) = S''(x_n) = 0 S ′′ ( x 0 ) = S ′′ ( x n ) = 0 (natural, aka. free, boundary)
S ′ ( x 0 ) = f ′ ( x 0 ) S'(x_0) = f'(x_0) S ′ ( x 0 ) = f ′ ( x 0 ) and S ′ ( x n ) = f ′ ( x n ) S'(x_n) = f'(x_n) S ′ ( x n ) = f ′ ( x n ) (clamped boundary)
Each S j S_j S j is written as
S j ( x ) = a j + b j ( x − x j ) + c j ( x − x j ) 2 + d j ( x − x j ) 3 S_j(x) = a_j + b_j(x - x_j) + c_j(x - x_j)^2 + d_j(x - x_j)^3 S j ( x ) = a j + b j ( x − x j ) + c j ( x − x j ) 2 + d j ( x − x j ) 3
giving 4 n 4n 4 n unknowns a j , b j , c j , d j a_j, b_j, c_j, d_j a j , b j , c j , d j , j = 0 , 1 , … , n − 1 j = 0, 1, \ldots, n-1 j = 0 , 1 , … , n − 1 , for 4 n 4n 4 n equations from the conditions above.
A natural spline approximates the shape a long flexible rod takes when forced through the data points, hence the name.
Constructing the Spline
Let h j = x j + 1 − x j h_j = x_{j+1} - x_j h j = x j + 1 − x j . Solve order:
a j = f ( x j ) a_j = f(x_j) a j = f ( x j ) , directly from interpolation.
c j c_j c j , from the tridiagonal system plus the boundary conditions.
b j b_j b j and d j d_j d j , by back-substitution from the known a j , c j a_j, c_j a j , c j .
The interpolation condition already gives a j a_j a j for each j = 0 , 1 , … , n j = 0, 1, \ldots, n j = 0 , 1 , … , n directly, leaving b j , c j , d j b_j, c_j, d_j b j , c j , d j to determine. Applying the continuity conditions to S j S_j S j gives, for each j = 0 , 1 , … , n − 1 j = 0, 1, \ldots, n-1 j = 0 , 1 , … , n − 1
a j + 1 = a j + b j h j + c j h j 2 + d j h j 3 (value continuity) b j + 1 = b j + 2 c j h j + 3 d j h j 2 (slope continuity) c j + 1 = c j + 3 d j h j (curvature continuity) \begin{aligned}
a_{j+1} &= a_j + b_j h_j + c_j h_j^2 + d_j h_j^3 & \text{(value continuity)} \\
b_{j+1} &= b_j + 2c_j h_j + 3d_j h_j^2 & \text{(slope continuity)} \\
c_{j+1} &= c_j + 3d_j h_j & \text{(curvature continuity)}
\end{aligned} a j + 1 b j + 1 c j + 1 = a j + b j h j + c j h j 2 + d j h j 3 = b j + 2 c j h j + 3 d j h j 2 = c j + 3 d j h j (value continuity) (slope continuity) (curvature continuity)
Solving the third equation for d j d_j d j and substituting into the first two, then eliminating b j b_j b j , leaves a linear system in the c j c_j c j ‘s alone
h j − 1 c j − 1 + 2 ( h j − 1 + h j ) c j + h j c j + 1 = 3 h j ( a j + 1 − a j ) − 3 h j − 1 ( a j − a j − 1 ) , j = 1 , … , n − 1 (tridiagonal system) h_{j-1}c_{j-1} + 2(h_{j-1} + h_j)c_j + h_j c_{j+1} = \frac{3}{h_j}(a_{j+1} - a_j) - \frac{3}{h_{j-1}}(a_j - a_{j-1}), \quad j = 1, \ldots, n-1 \quad \text{(tridiagonal system)} h j − 1 c j − 1 + 2 ( h j − 1 + h j ) c j + h j c j + 1 = h j 3 ( a j + 1 − a j ) − h j − 1 3 ( a j − a j − 1 ) , j = 1 , … , n − 1 (tridiagonal system)
Once { c j } j = 0 n \{c_j\}_{j=0}^n { c j } j = 0 n is known, the remaining coefficients follow directly
b j = 1 h j ( a j + 1 − a j ) − h j 3 ( 2 c j + c j + 1 ) , d j = c j + 1 − c j 3 h j (back-substitution) b_j = \frac{1}{h_j}(a_{j+1} - a_j) - \frac{h_j}{3}(2c_j + c_{j+1}), \qquad d_j = \frac{c_{j+1} - c_j}{3h_j} \quad \text{(back-substitution)} b j = h j 1 ( a j + 1 − a j ) − 3 h j ( 2 c j + c j + 1 ) , d j = 3 h j c j + 1 − c j (back-substitution)
This system has n − 1 n-1 n − 1 equations in n + 1 n+1 n + 1 unknowns c 0 , … , c n c_0, \ldots, c_n c 0 , … , c n . The 2 missing equations come from the boundary conditions.
Natural Boundary Conditions
S ′ ′ ( x 0 ) = S ′ ′ ( x n ) = 0 S''(x_0) = S''(x_n) = 0 S ′′ ( x 0 ) = S ′′ ( x n ) = 0 gives c 0 = c n = 0 c_0 = c_n = 0 c 0 = c n = 0 directly. The resulting ( n + 1 ) × ( n + 1 ) (n+1) \times (n+1) ( n + 1 ) × ( n + 1 ) system for c 0 , … , c n c_0, \ldots, c_n c 0 , … , c n is strictly diagonally dominant, so it has a unique solution, and thus f f f has a unique natural spline interpolant on the given nodes.
Clamped Boundary Conditions
S ′ ( x 0 ) = f ′ ( x 0 ) S'(x_0) = f'(x_0) S ′ ( x 0 ) = f ′ ( x 0 ) and S ′ ( x n ) = f ′ ( x n ) S'(x_n) = f'(x_n) S ′ ( x n ) = f ′ ( x n ) give 2 more equations
2 h 0 c 0 + h 0 c 1 = 3 h 0 ( a 1 − a 0 ) − 3 f ′ ( x 0 ) (left clamp) 2h_0 c_0 + h_0 c_1 = \frac{3}{h_0}(a_1 - a_0) - 3f'(x_0) \quad \text{(left clamp)} 2 h 0 c 0 + h 0 c 1 = h 0 3 ( a 1 − a 0 ) − 3 f ′ ( x 0 ) (left clamp)
h n − 1 c n − 1 + 2 h n − 1 c n = 3 f ′ ( x n ) − 3 h n − 1 ( a n − a n − 1 ) (right clamp) h_{n-1}c_{n-1} + 2h_{n-1}c_n = 3f'(x_n) - \frac{3}{h_{n-1}}(a_n - a_{n-1}) \quad \text{(right clamp)} h n − 1 c n − 1 + 2 h n − 1 c n = 3 f ′ ( x n ) − h n − 1 3 ( a n − a n − 1 ) (right clamp)
This ( n + 1 ) × ( n + 1 ) (n+1) \times (n+1) ( n + 1 ) × ( n + 1 ) system is also strictly diagonally dominant, so f f f has a unique clamped spline interpolant on the given nodes.
Unlike the natural spline, this requires knowing f ′ ( x 0 ) f'(x_0) f ′ ( x 0 ) and f ′ ( x n ) f'(x_n) f ′ ( x n ) directly, not just the node values f ( x j ) f(x_j) f ( x j ) , e.g. from a known formula for f f f .
Example
Construct a natural cubic spline through ( 1 , 2 ) , ( 2 , 3 ) , ( 3 , 5 ) (1, 2), (2, 3), (3, 5) ( 1 , 2 ) , ( 2 , 3 ) , ( 3 , 5 ) .
Nodes x 0 = 1 , x 1 = 2 , x 2 = 3 x_0 = 1, x_1 = 2, x_2 = 3 x 0 = 1 , x 1 = 2 , x 2 = 3 , so n = 2 n = 2 n = 2 , h 0 = h 1 = 1 h_0 = h_1 = 1 h 0 = h 1 = 1 , and a 0 = 2 , a 1 = 3 , a 2 = 5 a_0 = 2, a_1 = 3, a_2 = 5 a 0 = 2 , a 1 = 3 , a 2 = 5 directly from interpolation. Natural boundary conditions give c 0 = c 2 = 0 c_0 = c_2 = 0 c 0 = c 2 = 0 . The system for c 1 c_1 c 1 (the single interior equation, j = 1 j = 1 j = 1 ) is
h 0 c 0 + 2 ( h 0 + h 1 ) c 1 + h 1 c 2 = 3 h 1 ( a 2 − a 1 ) − 3 h 0 ( a 1 − a 0 ) = 3 ( 5 − 3 ) − 3 ( 3 − 2 ) = 3 h_0 c_0 + 2(h_0 + h_1)c_1 + h_1 c_2 = \frac{3}{h_1}(a_2 - a_1) - \frac{3}{h_0}(a_1 - a_0) = 3(5-3) - 3(3-2) = 3 h 0 c 0 + 2 ( h 0 + h 1 ) c 1 + h 1 c 2 = h 1 3 ( a 2 − a 1 ) − h 0 3 ( a 1 − a 0 ) = 3 ( 5 − 3 ) − 3 ( 3 − 2 ) = 3
4 c 1 = 3 ⟹ c 1 = 3 4 4c_1 = 3 \implies c_1 = \tfrac{3}{4} 4 c 1 = 3 ⟹ c 1 = 4 3
b 0 = ( a 1 − a 0 ) − 1 3 ( 2 c 0 + c 1 ) = 1 − 1 4 = 3 4 , d 0 = c 1 − c 0 3 = 1 4 b_0 = (a_1 - a_0) - \tfrac{1}{3}(2c_0 + c_1) = 1 - \tfrac{1}{4} = \tfrac{3}{4}, \qquad d_0 = \tfrac{c_1 - c_0}{3} = \tfrac{1}{4} b 0 = ( a 1 − a 0 ) − 3 1 ( 2 c 0 + c 1 ) = 1 − 4 1 = 4 3 , d 0 = 3 c 1 − c 0 = 4 1
b 1 = ( a 2 − a 1 ) − 1 3 ( 2 c 1 + c 2 ) = 2 − 1 2 = 3 2 , d 1 = c 2 − c 1 3 = − 1 4 b_1 = (a_2 - a_1) - \tfrac{1}{3}(2c_1 + c_2) = 2 - \tfrac{1}{2} = \tfrac{3}{2}, \qquad d_1 = \tfrac{c_2 - c_1}{3} = -\tfrac{1}{4} b 1 = ( a 2 − a 1 ) − 3 1 ( 2 c 1 + c 2 ) = 2 − 2 1 = 2 3 , d 1 = 3 c 2 − c 1 = − 4 1
S ( x ) = { 2 + 3 4 ( x − 1 ) + 1 4 ( x − 1 ) 3 , x ∈ [ 1 , 2 ] 3 + 3 2 ( x − 2 ) + 3 4 ( x − 2 ) 2 − 1 4 ( x − 2 ) 3 , x ∈ [ 2 , 3 ] S(x) = \begin{cases} 2 + \tfrac{3}{4}(x-1) + \tfrac{1}{4}(x-1)^3, & x \in [1, 2] \\[4pt] 3 + \tfrac{3}{2}(x-2) + \tfrac{3}{4}(x-2)^2 - \tfrac{1}{4}(x-2)^3, & x \in [2, 3] \end{cases} S ( x ) = { 2 + 4 3 ( x − 1 ) + 4 1 ( x − 1 ) 3 , 3 + 2 3 ( x − 2 ) + 4 3 ( x − 2 ) 2 − 4 1 ( x − 2 ) 3 , x ∈ [ 1 , 2 ] x ∈ [ 2 , 3 ]
With Multiple Interior Nodes
The 3-point example above has only 1 interior node, so its tridiagonal system is a single equation. With 4 nodes, there are 2 interior equations, and solving for c 1 , c 2 c_1, c_2 c 1 , c 2 requires actual elimination.
Construct a natural cubic spline through ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 0 ) , ( 3 , 1 ) (0, 0), (1, 1), (2, 0), (3, 1) ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 0 ) , ( 3 , 1 ) .
Nodes give n = 3 n = 3 n = 3 , h 0 = h 1 = h 2 = 1 h_0 = h_1 = h_2 = 1 h 0 = h 1 = h 2 = 1 , and a 0 = 0 , a 1 = 1 , a 2 = 0 , a 3 = 1 a_0 = 0, a_1 = 1, a_2 = 0, a_3 = 1 a 0 = 0 , a 1 = 1 , a 2 = 0 , a 3 = 1 . Natural boundary conditions give c 0 = c 3 = 0 c_0 = c_3 = 0 c 0 = c 3 = 0 . The tridiagonal system for j = 1 , 2 j = 1, 2 j = 1 , 2 is
4 c 1 + c 2 = 3 h 1 ( a 2 − a 1 ) − 3 h 0 ( a 1 − a 0 ) = 3 ( 0 − 1 ) − 3 ( 1 − 0 ) = − 6 c 1 + 4 c 2 = 3 h 2 ( a 3 − a 2 ) − 3 h 1 ( a 2 − a 1 ) = 3 ( 1 − 0 ) − 3 ( 0 − 1 ) = 6 \begin{aligned}
4c_1 + c_2 &= \tfrac{3}{h_1}(a_2-a_1) - \tfrac{3}{h_0}(a_1-a_0) = 3(0-1) - 3(1-0) = -6 \\
c_1 + 4c_2 &= \tfrac{3}{h_2}(a_3-a_2) - \tfrac{3}{h_1}(a_2-a_1) = 3(1-0) - 3(0-1) = 6
\end{aligned} 4 c 1 + c 2 c 1 + 4 c 2 = h 1 3 ( a 2 − a 1 ) − h 0 3 ( a 1 − a 0 ) = 3 ( 0 − 1 ) − 3 ( 1 − 0 ) = − 6 = h 2 3 ( a 3 − a 2 ) − h 1 3 ( a 2 − a 1 ) = 3 ( 1 − 0 ) − 3 ( 0 − 1 ) = 6
Eliminating c 2 c_2 c 2 (multiply the second row by 4 4 4 and subtract the first)
4 ( c 1 + 4 c 2 ) − ( 4 c 1 + c 2 ) = 4 ( 6 ) − ( − 6 ) ⟹ 15 c 2 = 30 ⟹ c 2 = 2 4(c_1 + 4c_2) - (4c_1 + c_2) = 4(6) - (-6) \implies 15c_2 = 30 \implies c_2 = 2 4 ( c 1 + 4 c 2 ) − ( 4 c 1 + c 2 ) = 4 ( 6 ) − ( − 6 ) ⟹ 15 c 2 = 30 ⟹ c 2 = 2
Back-substituting into the first row
4 c 1 + 2 = − 6 ⟹ c 1 = − 2 4c_1 + 2 = -6 \implies c_1 = -2 4 c 1 + 2 = − 6 ⟹ c 1 = − 2
b 0 = 1 − 1 3 ( − 2 ) = 5 3 , d 0 = c 1 − c 0 3 = − 2 3 b_0 = 1 - \tfrac{1}{3}(-2) = \tfrac{5}{3}, \quad d_0 = \tfrac{c_1 - c_0}{3} = -\tfrac{2}{3} b 0 = 1 − 3 1 ( − 2 ) = 3 5 , d 0 = 3 c 1 − c 0 = − 3 2
b 1 = − 1 − 1 3 ( − 4 + 2 ) = − 1 3 , d 1 = c 2 − c 1 3 = 4 3 b_1 = -1 - \tfrac{1}{3}(-4+2) = -\tfrac{1}{3}, \quad d_1 = \tfrac{c_2 - c_1}{3} = \tfrac{4}{3} b 1 = − 1 − 3 1 ( − 4 + 2 ) = − 3 1 , d 1 = 3 c 2 − c 1 = 3 4
b 2 = 1 − 1 3 ( 4 ) = − 1 3 , d 2 = c 3 − c 2 3 = − 2 3 b_2 = 1 - \tfrac{1}{3}(4) = -\tfrac{1}{3}, \quad d_2 = \tfrac{c_3 - c_2}{3} = -\tfrac{2}{3} b 2 = 1 − 3 1 ( 4 ) = − 3 1 , d 2 = 3 c 3 − c 2 = − 3 2
S ( x ) = { 5 3 x − 2 3 x 3 , x ∈ [ 0 , 1 ] 1 − 1 3 ( x − 1 ) − 2 ( x − 1 ) 2 + 4 3 ( x − 1 ) 3 , x ∈ [ 1 , 2 ] − 1 3 ( x − 2 ) + 2 ( x − 2 ) 2 − 2 3 ( x − 2 ) 3 , x ∈ [ 2 , 3 ] S(x) = \begin{cases} \tfrac{5}{3}x - \tfrac{2}{3}x^3, & x \in [0, 1] \\[4pt] 1 - \tfrac{1}{3}(x-1) - 2(x-1)^2 + \tfrac{4}{3}(x-1)^3, & x \in [1, 2] \\[4pt] -\tfrac{1}{3}(x-2) + 2(x-2)^2 - \tfrac{2}{3}(x-2)^3, & x \in [2, 3] \end{cases} S ( x ) = ⎩ ⎨ ⎧ 3 5 x − 3 2 x 3 , 1 − 3 1 ( x − 1 ) − 2 ( x − 1 ) 2 + 3 4 ( x − 1 ) 3 , − 3 1 ( x − 2 ) + 2 ( x − 2 ) 2 − 3 2 ( x − 2 ) 3 , x ∈ [ 0 , 1 ] x ∈ [ 1 , 2 ] x ∈ [ 2 , 3 ]
Clamped Boundary Example
Construct a clamped cubic spline through ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 0 ) (0, 0), (1, 1), (2, 0) ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 0 ) with f ′ ( 0 ) = 1 f'(0) = 1 f ′ ( 0 ) = 1 , f ′ ( 2 ) = − 1 f'(2) = -1 f ′ ( 2 ) = − 1 .
Nodes give n = 2 n = 2 n = 2 , h 0 = h 1 = 1 h_0 = h_1 = 1 h 0 = h 1 = 1 , and a 0 = 0 , a 1 = 1 , a 2 = 0 a_0 = 0, a_1 = 1, a_2 = 0 a 0 = 0 , a 1 = 1 , a 2 = 0 . The interior equation (j = 1 j = 1 j = 1 ) plus the 2 clamp equations give 3 equations in c 0 , c 1 , c 2 c_0, c_1, c_2 c 0 , c 1 , c 2
c 0 + 4 c 1 + c 2 = 3 h 1 ( a 2 − a 1 ) − 3 h 0 ( a 1 − a 0 ) = 3 ( − 1 ) − 3 ( 1 ) = − 6 (interior) 2 c 0 + c 1 = 3 h 0 ( a 1 − a 0 ) − 3 f ′ ( x 0 ) = 3 ( 1 ) − 3 ( 1 ) = 0 (left clamp) c 1 + 2 c 2 = 3 f ′ ( x 2 ) − 3 h 1 ( a 2 − a 1 ) = 3 ( − 1 ) − 3 ( − 1 ) = 0 (right clamp) \begin{aligned}
c_0 + 4c_1 + c_2 &= \tfrac{3}{h_1}(a_2-a_1) - \tfrac{3}{h_0}(a_1-a_0) = 3(-1) - 3(1) = -6 \quad \text{(interior)} \\
2c_0 + c_1 &= \tfrac{3}{h_0}(a_1-a_0) - 3f'(x_0) = 3(1) - 3(1) = 0 \quad \text{(left clamp)} \\
c_1 + 2c_2 &= 3f'(x_2) - \tfrac{3}{h_1}(a_2-a_1) = 3(-1) - 3(-1) = 0 \quad \text{(right clamp)}
\end{aligned} c 0 + 4 c 1 + c 2 2 c 0 + c 1 c 1 + 2 c 2 = h 1 3 ( a 2 − a 1 ) − h 0 3 ( a 1 − a 0 ) = 3 ( − 1 ) − 3 ( 1 ) = − 6 (interior) = h 0 3 ( a 1 − a 0 ) − 3 f ′ ( x 0 ) = 3 ( 1 ) − 3 ( 1 ) = 0 (left clamp) = 3 f ′ ( x 2 ) − h 1 3 ( a 2 − a 1 ) = 3 ( − 1 ) − 3 ( − 1 ) = 0 (right clamp)
From the clamp equations, c 1 = − 2 c 0 c_1 = -2c_0 c 1 = − 2 c 0 and c 2 = − 1 2 c 1 = c 0 c_2 = -\tfrac{1}{2}c_1 = c_0 c 2 = − 2 1 c 1 = c 0 . Substituting into the interior equation
c 0 + 4 ( − 2 c 0 ) + c 0 = − 6 ⟹ − 6 c 0 = − 6 ⟹ c 0 = 1 , c 1 = − 2 , c 2 = 1 c_0 + 4(-2c_0) + c_0 = -6 \implies -6c_0 = -6 \implies c_0 = 1, \quad c_1 = -2, \quad c_2 = 1 c 0 + 4 ( − 2 c 0 ) + c 0 = − 6 ⟹ − 6 c 0 = − 6 ⟹ c 0 = 1 , c 1 = − 2 , c 2 = 1
b 0 = 1 − 1 3 ( 0 ) = 1 , d 0 = c 1 − c 0 3 = − 1 b_0 = 1 - \tfrac{1}{3}(0) = 1, \quad d_0 = \tfrac{c_1-c_0}{3} = -1 b 0 = 1 − 3 1 ( 0 ) = 1 , d 0 = 3 c 1 − c 0 = − 1
b 1 = − 1 − 1 3 ( − 3 ) = 0 , d 1 = c 2 − c 1 3 = 1 b_1 = -1 - \tfrac{1}{3}(-3) = 0, \quad d_1 = \tfrac{c_2-c_1}{3} = 1 b 1 = − 1 − 3 1 ( − 3 ) = 0 , d 1 = 3 c 2 − c 1 = 1
S ( x ) = { x + x 2 − x 3 , x ∈ [ 0 , 1 ] 1 − 2 ( x − 1 ) 2 + ( x − 1 ) 3 , x ∈ [ 1 , 2 ] S(x) = \begin{cases} x + x^2 - x^3, & x \in [0, 1] \\[4pt] 1 - 2(x-1)^2 + (x-1)^3, & x \in [1, 2] \end{cases} S ( x ) = { x + x 2 − x 3 , 1 − 2 ( x − 1 ) 2 + ( x − 1 ) 3 , x ∈ [ 0 , 1 ] x ∈ [ 1 , 2 ]
Checking the endpoints confirms the clamp held: S 0 ′ ( 0 ) = b 0 = 1 = f ′ ( 0 ) S_0'(0) = b_0 = 1 = f'(0) S 0 ′ ( 0 ) = b 0 = 1 = f ′ ( 0 ) , and S 1 ′ ( 2 ) = b 1 + 2 c 1 h 1 + 3 d 1 h 1 2 = 0 − 4 + 3 = − 1 = f ′ ( 2 ) S_1'(2) = b_1 + 2c_1h_1 + 3d_1h_1^2 = 0 - 4 + 3 = -1 = f'(2) S 1 ′ ( 2 ) = b 1 + 2 c 1 h 1 + 3 d 1 h 1 2 = 0 − 4 + 3 = − 1 = f ′ ( 2 ) .
Error
For f ∈ C 4 [ a , b ] f \in C^4[a,b] f ∈ C 4 [ a , b ] with max a ≤ x ≤ b ∣ f ( 4 ) ( x ) ∣ = M \max_{a \leq x \leq b} |f^{(4)}(x)| = M max a ≤ x ≤ b ∣ f ( 4 ) ( x ) ∣ = M , the unique clamped cubic spline interpolant S S S satisfies, for all x ∈ [ a , b ] x \in [a, b] x ∈ [ a , b ]
∣ f ( x ) − S ( x ) ∣ ≤ 5 M 384 max 0 ≤ j ≤ n − 1 ( x j + 1 − x j ) 4 (error bound) |f(x) - S(x)| \leq \frac{5M}{384} \max_{0 \leq j \leq n-1} (x_{j+1} - x_j)^4 \quad \text{(error bound)} ∣ f ( x ) − S ( x ) ∣ ≤ 384 5 M 0 ≤ j ≤ n − 1 max ( x j + 1 − x j ) 4 (error bound)