12.07.2015 Views

9 Cubic Spline Examples

9 Cubic Spline Examples

9 Cubic Spline Examples

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Lecture 9 <strong>Cubic</strong> <strong>Spline</strong> <strong>Examples</strong> 22 Mon 08/02/109 <strong>Cubic</strong> <strong>Spline</strong> <strong>Examples</strong>9.1 Recall...During Wednesday’s lecture we saw that each cubic inthe spline interpolant can be written ass i (x) = α i (x − x i−1 ) + β i (x i − x)+σ i−16h (x i − x) 3 + σ i6h (x − x i−1) 3 , (9.1)for x ∈ [x i−1 ,x i ], where the unknown σ i = S ′′ (x i ). Theα i and β i are also unknown, but using that s i (x i−1 ) =f i−1 and s i (x i ) = f i we found the expressionsα i = f ih − h 6 σ i,β i = f i−1h − h 6 σ i−1. (9.2)for i = 1,2,...,n. We noted that β i = α i−1 .Finally, to find equations for the σ i , we used that S ′is continuous at each of the x i for i = 1,2,...,n − 1.Thus s ′ i (x i) = s ′ i+1 (x i). These equations allow one todeduce that the σ i satisfy16 (σ i−1 + 4σ i + σ i+1 ) = 1 h 2 (f i−1 − 2f i + f i+1 ) (9.3)for i = 1,...,n − 1. That is n − 1 equations in n + 1unknowns. To determine the “missing” equations, recallthat we are using Natural <strong>Spline</strong>s: S ′ (x 0 ) = S ′ (x n ) = 0.Now we have the full systemσ 0 = 016 (σ i−1 + 4σ i + σ i+1 ) = 1 h 2 (f i−1 − 2f i + f i+1 ) (9.4)σ N = 0i = 1,...,N − 1...................................................Example 9.1. Find the natural cubic spline interpolantto f at the points x 0 = 0, x 1 = 1, x 2 = 2 and x 3 = 3where f 0 = 0,f 1 = 2,f 2 = 1 and f 3 = 0.[This didn’t quite go to plan in class, so here are thefull details]Solution:From (8.12) we see we are looking for S(x)=α 1 x + β 1 (1 − x) + σ 06h (1 − x)3 + σ 16h x3 ,x ∈ [0,1],α 2 (x − 1) + β 2 (2 − x) + σ 16h (2 − x)3 + σ 26h (x − 1)3 ,x ∈ [1,2],α 3 (x − x 2 ) + β 3 (3 − x) + σ 26h (3 − x)3 + σ 36h (x − 2)3 ,x ∈ [2,3],We first solve for the σ i using (9.4):This gives16⎛ ⎞ ⎛ ⎞ ⎛ ⎞1 0 0 0 σ 0 0⎜1 4 1 0⎟⎜σ 1 ⎟ ⎜−18⎟⎝0 1 4 1⎠ ⎝σ⎠ = ⎝2 0⎠0 0 0 1 σ 3 0σ 0 = 0, σ 1 = − 245 , σ 2 = 6 5 , σ 3 = 0.Now use (8.13) to getα 1 = 145 , α 2 = 4 5 , α 3 = 0.andβ 1 = 0 β 2 = 145 , β 3 = 4 5 .The answer is⎧145 5 x3 , x ∈ [0,1],⎪⎨ 4 14(x − 1) + (2 − x)−5 5S(x) =45⎪⎩+ 1(x − 5 1)3 , x ∈ [1,2],45 5 x)3 . x ∈ [2,3].This is shown in Figure 9.1.2.521.510.50(x i, y i)S(x)−0.5−0.5 0 0.5 1 1.5 2 2.5 3 3.5Figure 9.1: <strong>Spline</strong> interpolant from Example 9.19.2 Error EstimatesWe 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.


Lecture 9 <strong>Cubic</strong> <strong>Spline</strong> <strong>Examples</strong> 23 Mon 08/02/10Theorem 9.1. If f ∈ C 4 [a,b] and S is its cubic splineinterpolant on N + 1 equally spaced points, then‖f − S‖ ∞ 5384 M 4h 4 ,‖f ′ − S ′ N‖ ∞ 124 M 4h 3 , ‖f ′′ − S ′′ N‖ ∞ 3 8 M 4h 2 ,where M 4 = ‖f (iv) ‖ ∞ .Example 9.2.Give an upper bound on the error for the cubic splineinterpolant to f = e x on the interval [−1,1] with n = 10mesh points....................................................Recall Theorem 7.3 for linear splines. There is ananalogous result for natural cubic splines.Theorem 9.2. Let u be any function that interpolatesf at ω N , and is such that u ∈ H 2 (x 0 ,x n ). Then‖S ′′ ‖ 2 ‖u ′′ ‖ 2 .The proof is not hard - it is analogous to the proofof Theorem 7.3....................................................9.3 ExercisesExercise 9.1. ⋆ When deducing the system of equationsfor the natural cubic spline, we showed how toconstruct the formulation given in (9.1) and the relationshipbetween σ i , α i and β i in (9.2). Now carefullyshow to deduce the system (9.4).Exercise 9.2. Write the equations above as a linearsystem Aσ = b, where A is an n × n matrix. Showthat A is nonsingular, and hence that the system as aunique solution. (Hint: recall your Gerschgorin Disksfrom MA385).Exercise 9.3. Find the Natural <strong>Cubic</strong> <strong>Spline</strong>interpolant to f(x) = sin(πx/2) at the nodes{x i } 3 i=0 = {0,1,2,3}.Calculate value of the interpolant at x = 2.5. Whatis the error at this point?Example 9.3.What is the smallest value of n that you must choose toensure that the error is less that 10 −8 ? How does thiscompare with a linear spline interpolation?Exercise 9.4. Take f(x) = ln(x), x 0 = 1, x n = 2.What value of n would you have to take to ensure that|ln(x) − S(x)| 10 −4 for all x ∈ [1,2]?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!