120 likes | 275 Views
Scientific Computing. Cubic Splines. Cubic Spline. Definition : A function S is a cubic spline on [a,b] if The domain of S is [a,b] S is continuous on [a,b] S’ is continuous on [a,b] S’’ is continuous on [a,b]
E N D
Scientific Computing Cubic Splines
Cubic Spline Definition: A function S is a cubic spline on [a,b] if The domain of S is [a,b] S is continuous on [a,b] S’ is continuous on [a,b] S’’ is continuous on [a,b] There is a partition of points on [a,b] such that S is a polynomial of degree <= 3 on each sub-interval [ti , ti+1 ]
Degree k Spline Definition: A function S is a spline of degree k on [a,b] if The domain of S is [a,b] S is continuous on [a,b] S’, S’’, …, S(k-1) are all continuous on [a,b] There is a partition of points on [a,b] such that S is a polynomial of degree <= k on each sub-interval [ti , ti+1 ]
Computing Degree k Splines If there are n-1 knots then we have n (degree k) polynomials to find: S0 (t), S1 (t), …, Sn-1 (t) Each polynomial Si (t) is defined by (k+1) constants: ck tk + ck-1 tk-1 + ck-2 tk-2 + … + c1 t + c0 Thus, to find the spline we need to solve for n*(k+1) constants and so need n*(k+1) equations. … t0 t1 t2 t3 tn-2 tn-1 tn S0 S1 Sn-2 Sn-1
Computing Degree k Splines At the data points we have the following n+1 equations: S0 (t0) = y0, S1 (t1) = y1, … , Sn-1 (tn-1) = yn-1, Sn-1 (tn) = yn The continuity of S at the knots requires (n-1) equations S0 (t1) = y1 , S1 (t2) = y2, …, Sn-2 (tn-1) = yn-1 We have a total of 2n equations from the continuity of S. (Remember we need n*(k+1) equations) … t0 t1 t2 t3 tn-2 tn-1 tn S0 S1 Sn-2 Sn-1
Computing Degree k Splines The continuity of the (k-1) derivatives S’, S’’, …, S(k-1) at the (n-1) internal knots t1 ,t2 ,…, tn-1 produces (k-1)*(n-1) more equations. So, we have a total of 2n+(k-1)*(n-1) = 2n + kn – n –(k-1) = n*(k+1) – (k-1) equations. We have a total of n*(k+1) – (k-1) equations. We need n*(k+1) equations, so we are (k-1) short! Solution: Add (k-1) conditions on constants. (usually on derivatives) “Natural Spline” – set some derivatives=0 at t0 and/or t1 … t0 t1 t2 t3 tn-2 tn-1 tn S0’ S1’ Sn-2’ Sn-1’
Computing Natural Cubic Splines Example: A cubic spline has degree k=3. Suppose we have this data:Then, n+1=3, k+1=4. So, we need to determine n*(k+1) = 8 constants. Continuity of S: S0 3= -a+b–c+d, S1 h = -1, 3= 8e+4f+2g+h Continuity at knots: S0 d = -1
Computing Natural Cubic Splines Example: So far, have Continuity of S’ at internal knot: S0’ c= g Continuity of S’’ at internal knot: S0’’ 2b = 2f
Computing Natural Cubic Splines Example: Now, we have 3 = -a+b-c-1 3 = 8e+4b+2c-1 The “natural” spline has S’’(t0)=0=S’’(t2) So, -6a+2b=0 and 12e+2f=12e+2b=0. Thus, we have 4 equations in 4 unknowns: -a+b-c = 4 8e+4b+2c = 4 -6a+2b=0 12e+2b=0 Solve by Gaussian Elimination
Computing Natural Cubic Splines Example: Get
Computing Natural Cubic Splines General Case: Given we have to find n cubic polynomials: P0 (x) = a0 (x-t0 )3 + b0 (x-t0 )2 + c0 (x-t0 ) + d0 P1 (x) = a1 (x-t1 )3 + b1 (x-t1 )2 + c1 (x-t1 ) + d1 . . . Pn-1 (x) = an-1 (x-tn-1 )3 + bn-1 (x-tn-1 )2 + cn-1 (x-tn-1 ) + dn-1
Computing Natural Cubic Splines We will look at how to compute cubic splines by reviewing notes in class.