14.0 KB · commit a9602da
We consider the same set of data points, viz., the data defined in Eq. (5.1), and let si(x) be the cubic spline defined in the interval [xi−1,xi]. The conditions for the natural cubic spline are
(i) si(x) is atmost a cubic in each subinterval [xi−1,xi], i=1,2,…,n, (ii) si(xi)=yi, i=0,1,2,…,n, (iii) si(x), si′(x) and si′′(x) are continuous in [x0,xn], and (iv) s1′′(x0)=sn′′(xn)=0.
To derive the governing equations of the cubic spline, we observe that the spline second derivatives must be linear. Hence, we have in [xi−1,xi]: si′′(x)=hi1[(xi−x)Mi−1+(x−xi−1)Mi],(5.24) where hi=xi−xi−1 and si′′(xi)=Mi for all i. Obviously, the spline second derivatives are continuous. Integrating Eq. (5.24) twice with respect to x, we get si(x)=hi1[6(xi−x)3Mi−1+6(x−xi−1)3Mi]+ci(xi−x)+di(x−xi−1),(5.25) where ci and di are constants to be determined.
Using conditions si(xi−1)=yi−1 and si(xi)=yi, we immediately obtain ci=hi1(yi−1−6hi2Mi−1)anddi=hi1(yi−6hi2Mi).(5.26)
Substituting for ci and di in Eq. (5.25), we obtain
si(x)=hi1[6(xi−x)3Mi−1+6(x−xi−1)3Mi+(yi−1−6hi2Mi−1)(xi−x)+(yi−6hi2Mi)(x−xi−1)].(5.27)In Eq. (5.27), the spline second derivatives, Mi, are still not known. To determine them, we use the condition of continuity of si′(x). From Eq. (5.27), we obtain by differentiation:
si′(x)=hi1[−63(xi−x)2Mi−1+63(x−xi−1)2Mi−(yi−1−6hi2Mi−1)+(yi−6hi2Mi)]Setting x=xi in the above, we obtain the left-hand derivative
si′(xi−)=2hiMi−hi1(yi−1−6hi2Mi−1)+hi1(yi−6hi2Mi)=hi1(yi−yi−1)+6hiMi−1+3hiMi(i=1,2,…,n).(5.28)To obtain the right-hand derivative, we need first to write down the equation of the cubic spline in the subinterval (xi,xi+1). We do this by setting i=i+1 in Eq. (5.27)
si+1(x)=hi+11[6(xi+1−x)3Mi+6(x−xi)3Mi+1+(yi−6hi+12Mi)(xi+1−x)+(yi+1−6hi+12Mi+1)(x−xi)],(5.29)where hi+1=xi+1−xi. Differentiating Eq. (5.29) and setting x=xi, we obtain the right-hand derivative at x=xi si+1′(xi+)=hi+11(yi+1−yi)−3hi+1Mi−6hi+1Mi+1(i=0,1,…,n−1).(5.30)
Equality of Eqs. (5.28) and (5.30) produces the recurrence relation 6hiMi−1+31(hi+hi+1)Mi+6hi+1Mi+1=hi+1yi+1−yi−hiyi−yi−1(i=1,2,…,n−1).(5.31)
For equal intervals, we have hi=hi+1=h and Eq. (5.31) simplifies to Mi−1+4Mi+Mi+1=h26(yi+1−2yi+yi−1),(i=1,2,…,n−1).(5.32)
The system of Eq. (5.31) has some special significance. If M0 and Mn are known, then the system can be written as
2(h1+h2)M1+h2M2h2M1+2(h2+h3)M2+h3M3h3M2+2(h3+h4)M3+h4M4hn−1Mn−2+2(hn−1+hn)Mn−1=6(h2y2−y1−h1y1−y0)−h1M0=6(h3y3−y2−h2y2−y1)=6(h4y4−y3−h3y3−y2)⋮=6(hnyn−yn−1−hn−1yn−1−yn−2)−hnMn.⎭⎬⎫(5.33)Equations (5.31) or (5.32) constitute a system of (n−1) equations and with the two conditions in (iv) for the natural spline, we have a complete system which can be solved for the Mi. Systems of the form (5.33) are called tridiagonal systems and in Chapter 7, we shall describe an efficient and accurate method for solving them. When the Mi are known, Eq. (5.27) then gives the required cubic spline in the subinterval [xi−1,xi]. Also, the yi′ can be obtained from Eqs. (5.28) and (5.30).
It should be noted that the tabulated function is y=x3−9 and hence the exact values of y(2.5) and y′(2.0) are, respectively, 6.625 and 12.0. The convergence to the actual values, with the increase in the order of the spline, is clearly seen from Examples 5.1, 5.2 and 5.3.
In many applications, it will be convenient to work with the spline first derivatives. Denoting si′(xi)=mi and taking suitable combinations of Eqs. (5.28) and (5.30), we can derive the following relationship for the mi:
hi1mi−1+2(hi1+hi+11)mi+hi+11mi+1=hi+123(yi+1−yi)+hi23(yi−yi−1),i=1,2,…,n−1.(5.34)
The cubic spline in (xi−1,xi) in terms of the mi is then given by
si(x)=hi21{mi−1(xi−x)2(x−xi−1)−mi(x−xi−1)2(xi−x)}+hi31{yi−1(xi−x)2[2(x−xi−1)+hi]+yi(x−xi−1)2[2(xi−x)+hi]}.(5.35)The above result can easily be derived using the Hermite interpolation formula given in Section 3.9.3.
For equally spaced knots, Eq. (5.34) assume the simpler form: mi−1+4mi+mi+1=h3(yi+1−yi−1),i=1,2,…,n−1.(5.36)
Equations (5.32) or (5.36) constitute (n−1) equations in (n+1) unknowns, viz., m0,m1,…,mn. Clearly, two further relations are required in order that a unique interpolating spline may be found. These conditions are called the end conditions and are discussed in detail in Kershaw [1971, 1972].
Specifically, we mention three types of end conditions: (i) Natural cubic spline: M0=Mn=0 (ii) D1 spline: s1′(x0)=y′(x0), s1′(xn)=y′(xn), (iii) D2 spline: s1′′(x0)=M0=y′′(x0) and s1′′(xn)=Mn=y′′(xn).
The following example demonstrates the improvement in accuracy of the cubic spline interpolates with successive interval halving.
In the interval [0,π/2], the natural cubic spline is given by s1(x)=π2(−π22x3+23x). Hence y(6π)≈s1(6π)=π2(−108π+4π)=0.4815.
We next take h=π/4, i.e., the data points are (0,0), (π/4,1/2), (π/2,1), (3π/4,1/2) and (π,0). In this case, the recurrence relation gives:
4M1+M2M1+4M2+M3M2+4M3=−4.029=−5.699=−4.029⎭⎬⎫(i)since M0=M4=0. Solving Eq. (i), we obtain M1=−0.7440,M2=−1.053,M3=−0.7440. In 0≤x≤π/4, the cubic spline is given by s1(x)=π4[−0.1240(x3)+0.7836(x)]. Hence, y(6π)≈s1(6π)=0.4998.
This result shows that the cubic spline has produced a better approximation when the interval is halved. We finally consider values of y=sinx in intervals of 10∘ from x=0 to π and then interpolate for x=5∘,15∘,25∘,35∘ and 45∘, using the natural cubic spline. The cubic spline values together with the exact values are given in the following table:
| x (in degrees) | Cubic spline values | Exact values |
|---|---|---|
| 5 | 0.087155743 | 0.087155530 |
| 15 | 0.258819045 | 0.258818415 |
| 25 | 0.422618262 | 0.422617233 |
| 35 | 0.573576436 | 0.573575040 |
| 45 | 0.707106781 | 0.707105059 |
◀
We prove this property for the natural cubic spline. Let s(x) be the natural cubic spline interpolating the set of data points (xi,yi), i=0,1,2,…,n, where it is assumed that a=x0<x1<x2<⋯<xn=b. Since s(x) is the natural cubic spline, we have s(xi)=yi for all i and also s′′(x0)=s′′(xn)=0.
Let z(x) be a function such that z(xi)=yi for all i, and z(x), z′(x), z′′(x) are continuous in [a,b]. Then the integral defined by I=∫ab[z′′(x)]2dx(5.37) will be minimum if and only if z(x)≡s(x). This means that s(x) is the smoothest function interpolating to the set of data points defined above, since the second derivative is a good approximation to the curvature of a curve. We write
∫ab[z′′(x)]2dx=∫ab[s′′(x)+z′′(x)−s′′(x)]2dx=∫ab[s′′(x)]2dx+2∫abs′′(x)[z′′(x)−s′′(x)]dx+∫ab[z′′(x)−s′′(x)]2dx.(5.38)Now,
∫abs′′(x)[z′′(x)−s′′(x)]dx=i=0∑n−1∫xixi+1s′′(x)[z′′(x)−s′′(x)]dx=i=0∑n−1{s′′(x)[z′(x)−s′(x)]}xixi+1−i=0∑n−1∫xixi+1s′′′(x)[z′(x)−s′(x)]dx.(5.39)The first term in Eq. (5.39) simplifies to s′′(xn)[z′(xn)−s′(xn)]−s′′(x0)[z′(x0)−s′(x0)]. Since s′′(xn)=s′′(x0)=0, the above expression vanishes. Similarly, the second term in Eq. (5.39) is zero since s′′′(x) has a constant value in each interval and s(xi)=z(xi)=yi, for all i. Hence, Eq. (5.38) becomes ∫ab[z′′(x)]2dx=∫ab[s′′(x)]2dx+∫ab[z′′(x)−s′′(x)]2dx(5.40) or ∫ab[z′′(x)]2dx≥∫ab[s′′(x)]2dx.(5.41)
It follows that the integral I=∫ab[z′′(x)]2dx will be minimum if and only if ∫ab[z′′(x)−s′′(x)]2dx=0,(5.42) which means that z′′(x)=s′′(x). Hence z(x)−s(x) is a polynomial in x of degree at most three in [a,b]. But the difference z(x)−s(x) vanishes at the points i=0,1,2,…,n. It, therefore, follows that z(x)=s(x),a≤x≤b.■
The errors in the natural and D1 splines are of the order of h2 and h4, respectively. The errors in the derivatives are given by s′(xi)=yi′−1801h4yiv+O(h6)(5.43)
s′′(xi)=y′′(xi)−121h2yiv(xi)+3601h4yvi(xi)+O(h6)(5.44) 21[s′′′(xi+)+s′′′(xi−)]=y′′′(xi)+121h2yv(xi)+O(h4)(5.45) s′′′(xi+)−s′′′(xi−)=hyiv(xi)−7201h5yviii(xi)+O(h7)(5.46)
From the above equations, we obtain y′(xi)=s′(xi)+O(h4)(5.47) y′′(xi)=s′′(xi)+121h2yiv(xi)+O(h4)(5.48) y′′′(xi)=21[s′′′(xi+)+s′′′(xi−)]+O(h2)(5.49) yiv(xi)=h1[s′′′(xi+)−s′′′(xi−)]+O(h4)(5.50)
These relations can be established* by using the spline recurrence relations together with the operators E and D.
*See, Curtis and Powell [1967].