Linear Program Polynomial Interpolation Spline
- In this article, we address the problem of interpolating data points by regular L 1 -spline polynomial curves of smoothness C k, k ⩾ 1, that are invariant under rotation of the data. To obtain a C 1 cubic interpolating curve, we use a local minimization method in parallel on five data points belonging to a sliding window.
- In this lecture, we will only consider spline interpolation using linear splines. (splines of degree 1), quadratic splines (splines of degree 2), and cubic splines. (splines of degree 3). Generalization to splines of general order is relatively straightforward. 2 Linear Interpolating Splines. A simple piecewise polynomial fit is the.
I'm trying to write a cubic spline interpolation program. I have written the program but, the graph is not coming out correctly. The spline uses natural boundary conditions(second dervative at start/end node are 0). The code is in Matlab and is shown below,
Oct 28, 2010. Proving that linear programming can be solved in polynomial time. Then learn more about it (read papers, books, etc) and find out what numerical algorithms are important. Examples: Linear solvers for projection methods in fluid dynamics. Eigenvalue solvers for the google matrix. Spline interpolation.
When I run the code, the interpolation function is not symmetric and, it doesn't converge correctly. Can anyone offer any suggestions about problems in my code? Thanks.
Itamar Katz2 Answers
I wrote a cubic spline package in Mathematica a long time ago. Here is my translation of that package into Matlab. Note I haven't looked at cubic splines in about 7 years, so I'm basing this off my own documentation. You should check everything I say.
The basic problem is we are given n
data points (x(1), y(1)) , .. , (x(n), y(n))
and we wish to calculate a piecewise cubic interpolant. The interpolant is defined as
Here Sk(x) is a cubic polynomial of the form
The properties of the spline are:
- The spline pass through the data point
Sk(x(k)) = y(k)
- The spline is continuous at the end-points and thus continuous everywhere in the interpolation interval
Sk(x(k+1)) = Sk+1(x(k+1))
- The spline has continuous first derivative
Sk'(x(k+1)) = Sk+1'(x(k+1))
- The spline has continuous second derivative
Sk'(x(k+1)) = Sk+1'(x(k+1))
To construct a cubic spline from a set of data point we need to solve for the coefficients sk0
, sk1
, sk2
and sk3
for each of the n-1
cubic polynomials. That is a total of 4*(n-1) = 4*n - 4
unknowns. Property 1 supplies n
constraints, and properties 2,3,4 each supply an additional n-2
constraints. Thus we have n + 3*(n-2) = 4*n - 6
constraints and 4*n - 4
unknowns. This leaves two degrees of freedom. We fix these degrees of freedom by setting the second derivative equal to zero at the start and end nodes.
Let m(k) = Sk'(x(k))
, h(k) = x(k+1) - x(k)
and d(k) = (y(k+1) - y(k))/h(k)
. The followingthree-term recurrence relation holds
The m(k) are unknowns we wish to solve for. The h(k)
and d(k)
are defined by the input data.This three-term recurrence relation defines a tridiagonal linear system. Once the m(k)
are determined the coefficients for Sk
are given by
Okay that is all the math you need to know to completely define the algorithm to compute a cubic spline. Here it is in Matlab:
Here is some code to plot a cubic spline:
Here is a function that constructs a cubic spline and plots in on the famous Runge function:
You can see it in action by running the following at the Matlab prompt
By the time you have twenty nodes your interpolant is visually indistinguishable from the Runge function.
Some comments on the Matlab code: I don't use any for or while loops. I am able to vectorize all operations. I quickly form the sparse tridiagonal matrix with spdiags
. I solve it using the backslash operator. I counting on Tim Davis's UMFPACK to handle the decomposition and forward and backward solves.
Hope that helps. The code is available as a gist on github https://gist.github.com/1269709
There was a bug in spline function, generated (n-2) by (n-2) should be symmetric:
Not the answer you're looking for? Browse other questions tagged matlabmatrixinterpolationspline or ask your own question.
In the mathematical field of numerical analysis, spline interpolation is a form of interpolation where the interpolant is a special type of piecewisepolynomial called a spline. Spline interpolation is often preferred over polynomial interpolation because the interpolation error can be made small even when using low degree polynomials for the spline.[1] Spline interpolation avoids the problem of Runge's phenomenon, in which oscillation can occur between points when interpolating using high degree polynomials.
Introduction[edit]
Originally, spline was a term for elasticrulers that were bent to pass through a number of predefined points ('knots'). These were used to make technical drawings for shipbuilding and construction by hand, as illustrated by Figure 1.
The approach to mathematically model the shape of such elastic rulers fixed by n + 1 knots is to interpolate between all the pairs of knots and with polynomials .
The curvature of a curve is given by:
As the spline will take a shape that minimizes the bending (under the constraint of passing through all knots) both and will be continuous everywhere and at the knots. To achieve this one must have that
This can only be achieved if polynomials of degree 3 or higher are used. The classical approach is to use polynomials of degree 3 — the case of cubic splines.
Algorithm to find the interpolating cubic spline[edit]
A third-order polynomial for which
can be written in the symmetrical form
(1) |
where
(2) |
(3) |
(4) |
As
one gets that:
(5) |
(6) |
Setting x = x1 and x = x2 respectively in equations (5) and (6) one gets from (2) that indeed first derivatives q′(x1) = k1 and q′(x2) = k2 and also second derivatives
(7) |
(8) |
If now (xi, yi), i = 0, 1, .., n are n + 1 points and
(9) |
where i = 1, 2, .., n and are n third degree polynomials interpolating y in the interval xi−1 ≤ x ≤ xi for i = 1, .., n such that q′i (xi) = q′i+1(xi) for i = 1, .., n−1 then the n polynomials together define a differentiable function in the interval x0 ≤ x ≤ xn and
(10) |
(11) |
for i = 1, .., n where
(12) |
(13) |
(14) |
If the sequence k0, k1, .., kn is such that, in addition, q′′i(xi) = q′′i+1(xi) holds for i = 1, .., n-1, then the resulting function will even have a continuous second derivative.
From (7), (8), (10) and (11) follows that this is the case if and only if
(15) |
for i = 1, .., n-1. The relations (15) are n − 1 linear equations for the n + 1 values k0, k1, .., kn.
For the elastic rulers being the model for the spline interpolation one has that to the left of the left-most 'knot' and to the right of the right-most 'knot' the ruler can move freely and will therefore take the form of a straight line with q′′ = 0. As q′′ should be a continuous function of x one gets that for 'Natural Splines' one in addition to the n − 1 linear equations (15) should have that
i.e. that
(16) |
(17) |
Eventually, (15) together with (16) and (17) constitute n + 1 linear equations that uniquely define the n + 1 parameters k0, k1, .., kn.
There exist other end conditions: 'Clamped spline', that specifies the slope at the ends of the spline, and the popular 'not-a-knot spline', that requires that the third derivative is also continuous at the x1 and xN−1 points.For the 'not-a-knot' spline, the additional equations will read:
where .
Example[edit]
In case of three points the values for are found by solving the tridiagonal linear equation system
Linear Program Polynomial Interpolation Splines
with
For the three points
- ,
one gets that
and from (10) and (11) that
In Figure 2, the spline function consisting of the two cubic polynomials and given by (9) is displayed.
2G/GSM/ GPRS/MMS/SMS. Digital Infrared Trail Camera. User's Manual. 1.1 General Description. This digital trail camera with MMS function can work automatically day and night. It can be triggered by any movement of. Some functions in TEST mode: user settings, manually capture, preview. Hc300m trail camera manual.
See also[edit]
Computer code[edit]
References[edit]
- ^Hall, Charles A.; Meyer, Weston W. (1976). 'Optimal Error Bounds for Cubic Spline Interpolation'. Journal of Approximation Theory. 16 (2): 105–122. doi:10.1016/0021-9045(76)90040-X.
- Schoenberg, Isaac J. (1946). 'Contributions to the Problem of Approximation of Equidistant Data by Analytic Functions: Part A.—On the Problem of Smoothing or Graduation. A First Class of Analytic Approximation Formulae'. Quarterly of Applied Mathematics. 4 (2): 45–99. doi:10.1090/qam/15914.
- Schoenberg, Isaac J. (1946). 'Contributions to the Problem of Approximation of Equidistant Data by Analytic Functions: Part B.—On the Problem of Osculatory Interpolation. A Second Class of Analytic Approximation Formulae'. Quarterly of Applied Mathematics. 4 (2): 112–141. doi:10.1090/qam/16705.
External links[edit]
- Hazewinkel, Michiel, ed. (2001) [1994], 'Spline interpolation', Encyclopedia of Mathematics, Springer Science+Business Media B.V. / Kluwer Academic Publishers, ISBN978-1-55608-010-4