Exercises 2.17 Interpolate A Cubic Spline Between The Threepoints (0, 1), (2, 2) And (4, 0).
Introduction to Cubic Spline Interpolation
Cubic spline interpolation is a powerful numerical method used to construct a smooth curve passing through a given set of points. Unlike simple polynomial interpolation, which can lead to oscillations between points (Runge's phenomenon), cubic splines ensure a smooth and stable fit by piecing together cubic polynomials with continuous first and second derivatives. This technique is particularly useful in data fitting, computer graphics, and numerical analysis, where smoothness and accuracy are essential.
In this article, we delve into the process of interpolating a cubic spline through three specific points: (0, 1), (2, 2), and (4, 0). We explore the mathematical formulation, derive the spline coefficients, and discuss the properties of the resulting spline.
Understanding the Data Points
Given Points
The data points provided for interpolation are:
- (0, 1)
- (2, 2)
- (4, 0)
These points define the key locations through which the interpolating spline must pass. The goal is to find a piecewise cubic function \( S(x) \) such that:
- \( S(x) \) passes through all three points.
- \( S(x) \) is twice continuously differentiable over the interval \([0, 4]\).
- The spline consists of two cubic polynomials: one from \( x=0 \) to \( x=2 \), and another from \( x=2 \) to \( x=4 \).
Formulating the Cubic Spline
Partitioning the Interval
Since we have three points, the interval \([0, 4]\) is divided into two subintervals:
- \( [x0, x1] = [0, 2] \)
- \( [x1, x2] = [2, 4] \)
Corresponding to these, we define two cubic polynomials:
\[
S1(x) = a1 + b1(x - x0) + c1(x - x0)^2 + d1(x - x0)^3
\]
\[
S2(x) = a2 + b2(x - x1) + c2(x - x1)^2 + d2(x - x1)^3
\]
where:
- \( S_1(x) \) is valid for \( x \in [0, 2] \),
- \( S_2(x) \) is valid for \( x \in [2, 4] \).
Conditions for the Spline
To ensure a smooth cubic spline, the following conditions must be met:
- Interpolation Conditions:
- \( S_1(0) = 1 \) (passes through (0, 1))
- \( S_1(2) = 2 \) (passes through (2, 2))
- \( S_2(2) = 2 \) (continuity at \( x=2 \))
- \( S_2(4) = 0 \) (passes through (4, 0))
- Smoothness Conditions:
- Continuity of first derivatives at \( x=2 \):
\[
S1'(2) = S2'(2)
\]
- Continuity of second derivatives at \( x=2 \):
\[
S1''(2) = S2''(2)
\]
- Boundary Conditions:
- Since no specific boundary conditions are given, a common choice is the "natural" spline, where second derivatives at endpoints are zero:
\[
S1''(0) = 0, \quad S2''(4) = 0
\]
Alternatively, for simplicity, in this case, we can proceed with these natural boundary conditions.
Deriving the Coefficients
Step 1: Expressing the Cubic Polynomials
Let’s set:
- \( x0 = 0 \), \( x1 = 2 \), \( x_2 = 4 \).
The cubic polynomials:
\[
S1(x) = a1 + b1 x + c1 x^2 + d_1 x^3
\]
\[
S2(x) = a2 + b2 (x - 2) + c2 (x - 2)^2 + d_2 (x - 2)^3
\]
Note: Using shifted variables for \( S_2 \) simplifies the calculations.
Step 2: Applying the Interpolation Conditions
From \( S_1(0) = 1 \):
\[
a1 + b1 \cdot 0 + c1 \cdot 0 + d1 \cdot 0 = 1 \Rightarrow a_1 = 1
\]
From \( S_1(2) = 2 \):
\[
a1 + 2b1 + 4c1 + 8d1 = 2
\]
But since \( a_1 = 1 \):
\[
1 + 2b1 + 4c1 + 8d1 = 2 \Rightarrow 2b1 + 4c1 + 8d1 = 1
\]
From \( S_2(2) = 2 \):
At \( x=2 \), \( x - 2=0 \):
\[
a2 + b2 \cdot 0 + c2 \cdot 0 + d2 \cdot 0 = 2 \Rightarrow a_2=2
\]
From \( S_2(4) = 0 \):
At \( x=4 \), \( x - 2=2 \):
\[
a2 + b2 \cdot 2 + c2 \cdot 4 + d2 \cdot 8 = 0
\]
Using \( a_2=2 \):
\[
2 + 2b2 + 4c2 + 8d_2= 0
\]
Step 3: Derivative Conditions for Smoothness
First derivatives:
\[
S1'(x) = b1 + 2c1 x + 3d1 x^2
\]
\[
S2'(x) = b2 + 2c2 (x - 2) + 3d2 (x - 2)^2
\]
At \( x=2 \):
\[
S1'(2) = b1 + 4 c1 + 12 d1
\]
\[
S2'(2) = b2 + 0 + 0 = b_2
\]
Set equal for smoothness:
\[
b1 + 4 c1 + 12 d1 = b2
\]
Second derivatives:
\[
S1''(x) = 2 c1 + 6 d_1 x
\]
\[
S2''(x) = 2 c2 + 6 d_2 (x - 2)
\]
At \( x=2 \):
\[
S1''(2) = 2 c1 + 12 d_1
\]
\[
S2''(2) = 2 c2 + 0 = 2 c_2
\]
Set equal:
\[
2 c1 + 12 d1 = 2 c_2
\]
Step 4: Boundary Conditions for Natural Spline
At \( x=0 \):
\[
S1''(0) = 2 c1 + 0 = 0 \Rightarrow c_1=0
\]
At \( x=4 \):
\[
S2''(4) = 2 c2 + 6 d2 \cdot 2 = 2 c2 + 12 d_2=0
\]
Solving the System for Coefficients
Now, compile all the equations:
- \( a_1=1 \)
- \( 2b1 + 4 c1 + 8 d_1=1 \)
- \( a_2=2 \)
- \( 2 + 2b2 + 4 c2 + 8 d_2=0 \)
- \( b2 = b1 + 4 c1 + 12 d1 \)
- \( 2 c1 + 12 d1= 2 c_2 \)
- \(