8.8 KB · commit a9602da
In Chapter 3, we have discussed the methods of finding an nth order polynomial passing through (n+1) given data points. In certain cases, these polynomials tend to give erroneous results due to round-off and other errors. Further, it was found that a low-order polynomial approximation in each subinterval provides a better approximation to the tabulated function than fitting a single high-order polynomial to the entire interval. Such an interpolation is called piecewise polynomial interpolation and the spline functions are such piecewise connecting polynomials.
The name spline has been adopted following the draftsman's device of using a thin flexible strip (called a spline) to draw a smooth curve through given points. The points at which two connecting splines meet are called knots. The connecting polynomials could be of any degree and, therefore, we have different types of splines: linear, quadratic, cubic, quintic, etc. Of these, the cubic spline (spline of degree three, or order four) has been found to be the most popular in engineering applications. Before discussing about cubic splines, we shall start with linear and quadratic splines since such a discussion will eventually justify the development of cubic splines. In Section 5.2, we derive the governing equations of a cubic spline and consider different end conditions. Errors in the cubic spline and cubic spline derivatives are important from the stand point of applications. These derivatives will be discussed in Section 5.2. Surface fitting cubic splines will be considered in Section 5.3, while cubic B-splines and their computation will be introduced in Section 5.4.
Applications of cubic splines to numerical differentiation, integration, numerical solution of differential equations, etc. will be considered in subsequent chapters.
Let the given data points be (xi,yi),i=0,1,2,…,n,(5.1) where a=x0<x1<x2<⋯<xn=b and let hi=xi−xi−1,i=1,2,…,n.(5.2)
Further, let si(x) be the spline of degree one defined in the interval [xi−1,xi]. Obviously, si(x) represents a straight line joining the points (xi−1,yi−1) and (xi,yi). Hence, we write si(x)=yi−1+mi(x−xi−1),(5.3) where mi=xi−xi−1yi−yi−1.(5.4)
Setting i=1,2,…,n successively in Eq. (5.3), we obtain different splines of degree one valid in the subintervals 1 to n, respectively. It is easily seen that si(x) is continuous at both the end points.
It is easy to check that the splines si(x) are continuous in [1,3] but their slopes are discontinuous. This is clearly a drawback of linear splines and therefore we next discuss quadratic splines which assume the continuity of the slopes in addition to that of the function.
With reference to the data points given in Eq. (5.1), let si(x) be the quadratic spline approximating the function y=f(x) in the interval [xi−1,xi], where xi−xi−1=hi. Let si(x) and si′(x) be continuous in [x0,xn] and let si(xi)=yi,i=0,1,2,…,n.(5.5)
Since si(x) is a quadratic in [xi−1,xi], it follows that si′(x) is a linear function and therefore we write si′(x)=hi1[(xi−x)mi−1+(x−xi−1)mi],(5.6) where mi=si′(xi).(5.7)
Integrating Eq. (5.6) with respect to x, we obtain si(x)=hi1[−2(xi−x)2mi−1+2(x−xi−1)2mi]+ci,(5.8) where ci are constants to be determined. Putting x=xi−1 in Eq. (5.8), we get ci=yi−1+hi12hi2mi−1=yi−1+2himi−1.
Hence Eq. (5.8) becomes: si(x)=hi1[−2(xi−x)2mi−1+2(x−xi−1)2mi]+yi−1+2himi−1.(5.9)
In Eq. (5.9), the mi are still unknown. To determine the mi, we use the condition of continuity of the function since the first derivatives are already continuous. For the continuity of the function si(x) at x=xi, we must have si(xi−)=si+1(xi+)(5.10)
From Eq. (5.9), we obtain
si(xi−)=2himi+yi−1+2himi−1=2hi(mi−1+mi)+yi−1.(5.11)Further, si+1(x)=hi+11[−2(xi+1−x)2mi+2(x−xi)2mi+1]+yi+2hi+1mi,
and therefore si+1(xi+)=−2hi+1mi+yi+2hi+1mi=yi.(5.12)
Equality of Eqs. (5.11) and (5.12) produces the recurrence relation mi−1+mi=hi2(yi−yi−1),i=1,2,…,n(5.13) for the spline first derivatives mi. Equations (5.13) constitute n equations in (n+1) unknowns, viz, m0,m1,…,mn. Hence, we require one more condition to determine the mi uniquely. There are several ways of choosing this condition. One natural way is to choose s1′′(x1)=0, since the mechanical spline straightens out in the end intervals. Such a spline is called a natural spline. Differentiating Eq. (5.9) twice with respect to x, we obtain si′′(x)=hi1(−mi−1+mi), or s1′′(x1)=h11(m1−m0).
Hence, we have the additional condition as m0=m1.(5.14)
Therefore, Eqs. (5.13) and (5.14) can be solved for mi, which when substituted in Eq. (5.9) gives the required quadratic spline.
The quadratic spline s1(x) in the interval [1,2] can be determined in a similar way. A straightforward way of deriving the quadratic splines is as follows:
Since si(x) is a quadratic in (xi−1,xi), we can write si(x)=ai+bix+cix2,(5.15) where ai,bi and ci are constants to be determined. Clearly, there are 3n constants and therefore we require 3n conditions to determine them. These conditions are obtained by using the properties of the quadratic spline. Firstly, we use the condition that the spline passes through the interior points. This means si(xi)=ai+bixi+cixi2i=1,2,…,n−1.(5.16) Next, si(x) is continuous at x=xi. This condition requires si(xi−)=si+1(xi+).(5.17) Hence, we must have ai+bixi+cixi2=ai+1+bi+1xi+ci+1xi2,i=1,2,…,n−1.(5.18) Again, si′(x) is continuous at x=xi. This gives bi+2cixi=bi+1+2ci+1xi,i=1,2,…,n−1.(5.19) We thus have 3n−3 conditions and we require three more conditions. Since the spline passes through the end points also, we must have y0=a1+b1x0+c1x02(5.20) and yn=an+bnxn+cnxn2.(5.21) Finally, for the natural spline, we have s1′′(x0)=0,(5.22) and this gives c1=0.(5.23)
We have, thus, a completed system of 3n equations in 3n unknowns. Although this system can certainly be solved, it is obviously more expensive and, therefore, this method is less preferred to the previous one.
The discontinuity in the second derivatives is an obvious disadvantage of the quadratic splines and this drawback is removed in the cubic splines discussed below.