f f f f f (/2).9.8.7.6.5.4.3.2. S Knots.7.6.5.4.3.2. 5 5.2.8.6.4.2 S Knots.2 5 5.9.8.7.6.5.4.3.2..9.8.7.6.5.4.3.2. S Knots 5 5 S Knots 5 5 5 5.35.3.25.2.5..5 5 5.6.5.4.3.2. 5 5 4 x 3 3.5 3 2.5 2.5.5 5 5 2 Piecewise Polynomial Interpolation 2.2 (Natural) Cubic Splines MA378/53 Numerical Analysis II ( NA2 ) February 27.9.8.7.6.5.4.3.2. S Knots 8 x 4 7 6 5 4 3 2 5 5 5 5 These slides are licensed under CC BY-SA 4.
Introduction (2/2) The Cubic Spline is perhaps the most useful and popular interpolating function used in numerical analysis, automotive and aeronautical engineering, computer and film animation, digital photography, financial modelling, and as many other areas as there are human endeavours where continuous processes are modelled by discrete ones. It is generally accepted that (mathematical) splines were first described by Isaac Schoenberg (93-99) during WW2. However their physical realisation had been used in the ship-building and aircraft industries prior to that.
Introduction (3/2) One could argue that the most fundamental short-coming of the linear spline interpolant to f is that they are not smooth : that is, although.9.8.7.6.5.4.3 f(x) l 4 (x) l i (x i ) = l i+ (x i ), it is generally the case that l i(x i ) l i+(x i )..2. 5 5.9.8.7.6.5.4.3 f(x) l 8 (x).2. Also, the interpolating function cannot capture the curvature of f. (If you think about this last statement, you ll see that it can be expressed as l (x) = for all x [a, b].) 5 5.9.8.7.6.5.4.3.2. f(x) l 6 (x) 5 5
Definition (4/2) Cubic splines try to balance the simplicity of the linear spline approach by using a low-order polynomial on each interval with the desire for curvature and more smoothness by using cubics, and by forcing adjacent ones, and their first and second derivatives, to agree at knot points.
Definition (5/2) Definition (Cubic Spline) Let f be a function that is continuous on [a, b]. The cubic spline interpolant to f is the continuous function S such that (i) for i =,..., N, on each interval [x i, x i ] let S(x) = s i (x), where each of the s i is a cubic polynomial. (ii) s i (x i ) = f(x i ) for i =,..., N, (iii) s i (x i ) = f(x i ) for i =,..., N, (iv) s i (x i) = s i+ (x i) for i =,..., N, (v) s i (x i) = s i+ (x i) for i =,..., N. So, we have defined the cubic spline S as a function that interpolates f at N + points, has continuous first and second derivatives on [x, x N ] and is a cubic polynomial on each of the n intervals [x i, x i ]. That is, it is piecewise cubic.
Definition (6/2) We know that one can write a cubic as a + a x + a 2 x 2 + a 3 x 3. So it takes 4 terms to uniquely define a single cubic. To define the spline we need 4N terms. They can be found by solving 4N (linearly independent) equations. But the definition only gives 4N 2 equations. The missing equations can be chosen in a number of ways: (i) by setting S (x ) = and S (x N ) =. This is called a natural spline, and is the approach we ll take. (ii) by setting S (x ) = and S (x N ) =. This is called a clamped spline. (iii) set S (x ) = S (x N ) and S (x ) = S (x N ). This is the periodic spline and is used for interpolating, say, trigonometric functions. (iv) only use N 2 components of the spline: s 2,..., s N. But extend to two end ones so that s 2 (x ) = f(x ) and s N = f(x N ). This is called the not-a-knot condition.
Definition (7/2) The following figures show the linear spline (left) and natural cubic spline (right), and errors, interpolants to f(x) = /( + x 2 ) (with a = 5 and b = 5 as usual) for various N. Compared with linear splines, we seem to get significantly better approximation. Moreover, the rate at which the error decreases with respect to h is much faster.
Definition (8/2).9.8.7.6.5.4.3.2. N = 2 f(x) l 2 (x).9.8.7.6.5.4.3.2. f S Knots 5 5.2 f(x) l 2 (x). 5 5.7.6.5..4.2.3.3.2.4..5 5 5 5 5
Definition (8/2).9.8.7.6.5.4.3.2. N = 4 f(x) l 4 (x).2.8.6.4.2 f S Knots 5 5.5 f(x) l 4 (x).5.2 5 5.35.3.25.2..5..5.5.2 5 5 5 5
Definition (8/2).9.8.7.6.5.4.3.2. N = 8 f(x) l 8 (x).9.8.7.6.5.4.3.2. f S Knots 5 5.8 5 5.6.6.4.2.2.4 f(x) l 8 (x).5.4.3.2..6 5 5 5 5
Definition (8/2).9.8.7.6.5.4.3.2. N = 6 f(x) l 6 (x).9.8.7.6.5.4.3.2. f S Knots 5 5.6.5.4.3.2...2 f(x) l 6 (x).3 5 5 5 5 4 x 3 3.5 3 2.5 2.5.5 5 5
Definition (8/2).9.8.7.6.5.4.3.2. N = 32 f(x) l 32 (x).9.8.7.6.5.4.3.2. f S Knots 5 5.25 5 5 8 x 4.2.5..5.5 f(x) l 32 (x) 7 6 5 4 3 2. 5 5 5 5
Constructing Cubic Splines (9/2) Some notation: h = x i x i = (x N x )/N for all i. f i := f(x i ). To construct the spline, first observe that if S is piecewise cubic, then S is piecewise quadratic, and S is piecewise linear. (i) Let σ i = S (x i ) for i =,..., N.
Constructing Cubic Splines (/2) (ii) Integrate twice: We get s i (x) = α i (x x i ) + β i (x i x)+ σ i 6h (x i x) 3 + σ i 6h (x x i ) 3, () for x [x i, x i ].
Constructing Cubic Splines (/2) (iii) The α i and β i arose as the constants of integration. To find them:
Constructing Cubic Splines (2/2) and so, for i =, 2,..., N α i = f i h h 6 σ i, Notice that this gives β i = α i. β i = f i h h 6 σ i. (2)
Constructing Cubic Splines (3/2) (iv) So, now we just need the equations for σ i. Two of these come from the fact that this is a natural cubic spline, with S (x ) = and S (x N ) =, therefore σ = and σ N =. The remaining N equations come from the fact that S is continuous at x, x 2,..., x n. So we set that s i(x i ) = s i+(x i ). After some work (see exercises...), we can show this means that the system is: σ =, (3a) 6 (σ i + 4σ i + σ i+ ) = ( fi h 2 2f i + f i+ ) (3b) for i =,..., N, σ N =. (3c)
A cubic spline example (4/2) Example Find the natural cubic spline interpolant to f at the points x =, x =, x 2 = 2 and x 3 = 3 where f =, f = 2, f 2 = and f 3 =. [We won t do all the details in class, so here they are] Solution: From () we see we are looking for S(x)= α x + β ( x) + σ 6h ( x)3 + σ 6h x3,x [, ], α 2 (x ) + β 2 (2 x) + σ 6h (2 x)3 + σ 2 6h (x )3,x [, 2], α 3 (x x 2 ) + β 3 (3 x) + σ 2 6h (3 x)3 + σ 3 6h (x 2)3,x [2, 3].
A cubic spline example (5/2) We first solve for the σ i using (3): This gives 6 Now use (2) to get σ 4 σ 4 σ 2 = 8 σ 3 σ =, σ = 24 5, σ 2 = 6 5, σ 3 =. and α = 4 5, α 2 = 4 5, α 3 =. β = β 2 = 4 5, β 3 = 4 5.
A cubic spline example (6/2) The answer is 4 5 x 4 5 x3, x [, ], 4 S(x) = 5 (x ) + 4 5 (2 x) 4 5 (2 x)3 + 5 (x )3, x [, 2], 4 5 (3 x) + 5 (3 x)3. x [2, 3]. This is shown below. 2.5 2 (x i,y i ) S.5.5.5.5.5.5 2 2.5 3 3.5
Error Estimates (7/2) We state the following error estimates without proof. You don t need to know these, or be able to prove them. But you should be able to use them if required. Theorem If f C 4 [a, b] and S is its cubic spline interpolant on N + equally spaced points, then f S 5 384 M 4h 4, f S 24 M 4h 3, f S 3 8 M 4h 2, where M 4 = f (iv).
Error Estimates (8/2) Example Give an upper bound on the error for the cubic spline interpolant to f = e x on the interval [, ] with N = mesh points.
Error Estimates (9/2) Example What is the smallest value of N that you can take which ensures that, if interpolating f(x) = e x on N equally sized intervals on [, ], the error is less that 8? How does this compare with a linear spline interpolation (see corresponding example for linear splines).
Error Estimates (2/2) Recall the minimum energy property of linear splines. There is an analogous result for natural cubic splines. Theorem Let u be any function that interpolates f at ω N, and is such that u H 2 (x, x N ). Then S 2 u 2. The proof is not hard - it is analogous to the proof of Theorem 2..9.