# Constraint Cubic spline

### Cubic Spline Interpolation

Cubic spline interpolation is a way of finding a curve that connects data points with a degree of three or less. Splines are polynomial that are smooth and continuous across a given plot and also continuous first and second derivatives where they join.

We take a set of points [x_{i}, y_{i}] for i = 0, 1, …, n for the function y = f(x). The cubic spline interpolation is a piecewise continuous curve, passing through each of the values in the table.

- Following are the conditions for the spline of degree K=3:
- The domain of s is in intervals of [a, b].
- S, S’, S” are all continuous function on [a,b].

Here S_{i}(x) is the cubic polynomial that will be used on the subinterval [x_{i}, x_{i+1}].

The main factor about spline is that it combines different polynomials and does not use a single polynomial of degree * n* to fit all the points at once, it avoids high degree polynomials and thereby the potential problem of overfitting. These low-degree polynomials need to be such that the spline they form is not only continuous but also smooth.

But for the spline to be smooth and continuous, the two consecutive polynomials and S_{i} (x) and S_{i+1} (x) must join at x_{i}.

Or, S_{i} (x) must be passed through two end-points:

Assume, S” (x) = M_{i} (i= 0,1,2, … , n). Since S(x) is cubic polynomial , so S” (x) is the linear polynomial in [x_{i}, x_{i+1}], then S”’ (x) will be:

By applying the Taylor series:

Let, x = x_{i+1}:

Similarly, we apply above equation b/w range [x_{i-1}, x_{i}]:

Let h_{i} =x_{i }– x_{i-1}

Now, we have n-1 equations, but have n+1 variables i.e M_{0}, M_{1}, M_{2},…M_{n-1}, M_{n}. Therefore, we need to get 2 more equations. For that, we will be using additional boundary conditions.

Let’s consider that we know S’ (x_{0}) = f_{0}‘ and S’ (x_{n}) = f_{n}‘, especially if S’ (x_{0}) and S’ (x_{n}) both are 0. This is called the clamped boundary condition.

Similarly, for M_{n}

or

Combining the above equation in to the matrix form, we get the following matrix:

### Constraint Cubic Spline

Constraint cubic spline was proposed by the CJC Kruger in his article. The algorithm is an extension of cubic spline interpolation. The important step in it is the calculation of the slope at each point. The idea behind the slope calculation is that the slope at a point will be b/w the slope of the two adjacent lines joining that point, if one of them is 0 then the slope at point should also be 0.

Let take a collection of point (x_0, y_0), (x_1, x_2) …\, …\, … \, (x_{i-1}, y_{i-1}),(x_{i}, y_{i}), (x_{i+1}, y_{i+1})…\, …\, … \, (x_n, y_n). The cubic curve can be given by:

The above curve pass through all of the following points:

THe first order derivative must be continuous at intermediate points:

which can be calculated by following formula for intermediate points:

if slope changes sign at point.

First derivative (slope) of each end point is calculated by following formula:

Second derivative are calculated by following formula:

Solving for the coefficient of curve gives:

### Conclusion

Constraint cubic spline interpolation has the following advantages as compared to a standard cubic spline.

- It generates a relatively smooth curve as compare to standard cubic spline
- Interpolated values are calculated without solving a system of equations.
- It never overshoots the immediate values.

## Please

Loginto comment...