Last modified: November 10, 2018
This article is written in: πΊπΈ
Cubic Spline
Cubic spline interpolation is a refined mathematical tool frequently used within numerical analysis. It's an approximation technique that employs piecewise cubic polynomials, collectively forming a cubic spline. These cubic polynomials are specifically engineered to pass through a defined set of data points, hence striking a balance between overly simple (like linear) and overly intricate (like high-degree polynomial) interpolations.
Conceptual Illustration:
Imagine you have a set of points on a 2D plane. A cubic spline will "thread" through these points, forming a smooth curve that does not exhibit sudden bends or wiggles:
The spline is constructed from piecewise cubic segments that meet at the data points with continuous first and second derivatives, ensuring a visually natural and mathematically smooth interpolation.
Mathematical Formulation
We start with a set of data points:
with .
A cubic spline is a function defined piecewise on each interval , :
where are the unknown coefficients for the cubic polynomial on the interval .
Key Requirements:
I. Interpolation Condition:
Each segment must pass through the given data points:
II. Continuity of the Spline:
The function must be continuous at the interior points:
III. Continuity of First Derivative:
The first derivatives of adjacent segments must match:
IV. Continuity of Second Derivative:
Similarly, the second derivatives must also be continuous:
V. Boundary Conditions:
For a natural cubic spline, the second derivatives at the boundaries are set to zero:
These conditions lead to a system of linear equations that determine the coefficients and .
Derivation of the Coefficients
I. Divided Differences and Step Sizes:
Let the spacing between consecutive points be:
II. Formulation in Terms of Second Derivatives:
Let . If we can determine for all , we can write each piece as:
$$S_i(x) = M_{i}\frac{(x_{i+1}-x)^3}{6h_i} + M_{i+1}\frac{(x - x_i)^3}{6h_i}
-
\left(y_i - \frac{M_i h_i^2}{6}\right)\frac{x_{i+1}-x}{h_i}
-
\left(y_{i+1} - \frac{M_{i+1}h_i^2}{6}\right)\frac{x - x_i}{h_i}.$$
This form ensures the correct boundary conditions and continuity of derivatives once are found.
III. System of Equations for :
Using the conditions for continuity of first and second derivatives, one obtains a tridiagonal system of equations in terms of the unknown second derivatives . For natural splines, we have:
The remaining 's (for ) are found by solving this system:
where depend on the data points and .
IV. Once are determined, the coefficients of the cubic spline in the standard form:
can be computed directly:
Algorithm Steps
I. Data Preparation:
- Sort the data points in ascending order by .
- Compute for .
II. Form the Equations:
Set up the linear system to solve for the second derivatives . For a natural spline:
For :
III. Solve the Tridiagonal System:
Use an efficient method (like the Thomas algorithm) to solve for .
IV. Calculate the Coefficients:
With known, compute:
as described above.
V. Interpolation:
For a given , find the interval such that and evaluate:
Example
Consider three points: .
- .
- Boundary conditions: .
We form the equation for :
Since :
Then:
And similarly for .
This gives piecewise polynomials smoothly interpolating the given points.
Advantages
- Splines ensure smoothness by producing curves with continuous first and second derivatives, leading to a natural and visually appealing fit.
- The method provides controlled behavior, avoiding the large oscillations often observed in high-degree polynomial interpolation.
- Local control means that changing a single data point only impacts the neighboring spline segments, rather than the entire curve.
Limitations
- The method involves complexity, as it requires setting up and solving a linear system of equations, making it more complicated than simpler interpolation techniques.
- Computational cost is higher than methods like linear interpolation, particularly for large datasets with many control points.
- Boundary conditions must be specified (e.g., natural, clamped) to define the behavior at the endpoints, which can influence the overall fit of the spline.