Interpoltion, Smoothing, Extrpoltion A typicl numericl ppliction is to find smooth prmetriztion of ville dt so tht results t intermedite (or extended) positions cn e evluted. Wht is good estimte for y for x=4.5, or x=15? Options: if hve model, y=f(x), then fit the dt nd extrct model prmeters. Model then used to give vlues t other points. If no model ville, then use smooth function to interpolte Winter Semester 2006/7 Computtionl Physics I Lecture 3 1
Interpoltion Strt with interpoltion. Simplest - liner interpoltion. Imgine we hve two vlues of x, x nd x, nd vlues of y t these points, y, y. Then we interpolte (estimte the vlue of y t n intermedite point) s follows: y = y + (y y ) (x x ) (x x ) Winter Semester 2006/7 Computtionl Physics I Lecture 3 2
Interpoltion Bck to the initil plot: y = y + (y y ) (x x ) (x x ) Not very stisfying. Our intuition is tht functions should e smooth. Try reproducing with higher order polynomil. If we hve n+1 points, then we cn represent the dt with polynomil of order n. Winter Semester 2006/7 Computtionl Physics I Lecture 3 3
Interpoltion Fit with 10th order polynomil. We go through every dt point (11 free prmeters, 11 dt points). This gives smooth representtion of the dt nd indictes tht we re deling with n oscillting function. However, extrpoltion is dngerous! Winter Semester 2006/7 Computtionl Physics I Lecture 3 4
For n+1 points (x i,y i ), with Lgrnge Polynomils i = 0,1,,n x i x j i there is unique interpolting polynomil of degree n with p(x i ) = y i i = 0,1,,n Cn construct this polynomil using the Lgrnge polynomils, defined s: L i (x) = (x x 0 )(x x i1 )(x x i+1 )(x x n ) (x i x 0 )(x i x i1 )(x i x i+1 )(x i x n ) Degree n (denomintor is constnt), nd L i (x k ) = i,k Winter Semester 2006/7 Computtionl Physics I Lecture 3 5
Lgrnge Polynomils The Lgrnge Polynomils cn e used to form the interpolting polynomil: p(x) = n y i L i (x) = y i i=0 * * Exmple: 10th order polynomil Lgrnge=0. * Do I=0,10 term=1. Do k=0,10 If (k.ne.i) then term=term*(x-x0(k))/(x0(i)-x0(k)) Endif Enddo Lgrnge=Lgrnge+Y0(I)*term Enddo n i=0 n k =0,k i x x k x i x k Winter Semester 2006/7 Computtionl Physics I Lecture 3 6
Lgrnge Polynomils Error estimtion of the interpoltion/extrpoltion: Define err(x) = f (x) p(x) where f (x) is originl function, p(x) is interpolting function Choose x x i for ny i = 0,1,,n Now define F(x) = f (x) p(x) ( f (x) p(x) ) n i=0 n i=0 (x x i ) (x x i ) Now look t properties of F(x) Winter Semester 2006/7 Computtionl Physics I Lecture 3 7
Inter- nd Extrpoltion Error F(x i ) = 0 for ll i = 0,1,,n nd F(x) = 0. I.e., F(x) hs n + 2 zeroes Rolle's theorem: There exists etween x, x 0, x 1,, x n such tht F (n+1) () = 0 so, 0 = f (n+1) () ( f (x) p(x) ) n i=0 (n + 1)! (x x i ) ( p (n+1) = 0) ut x is ritrry, so e(x) = f (n+1) n () (x x i ) for some etween x, x 0, x 1,, x n (n + 1)! i=0 Winter Semester 2006/7 Computtionl Physics I Lecture 3 8
Inter- nd Extrpoltion Error Suppose we re trying to interpolte sine function (our exmple). We hve 11 dt points (n=10). Then f (n+1) (x) = d11 sin x dx 11 = cos x so f (n+1) () 1 e(x) n i=0 (x x i ) (n + 1)! ( )11 < 11! for interpoltion For extrpoltion, the error grows s the power (n+1) Winter Semester 2006/7 Computtionl Physics I Lecture 3 9
Splines Assume hve dt { x k, y k } with k = 0,n i.e., n + 1 points (lso known s knots) Define = x 0, = x n nd rrnge so tht x 0 < x 1 < < x n1 < x n A spline is polynomil interpoltion etween the dt points which stisfies the following conditions: 1. S(x) = S k (x) for x k x x k +1 k = 0,1,,n 1 2. S(x k ) = y k k = 0,1,,n 3. S k (x k +1 ) = S k +1 (x k +1 ) k = 0,1,,n 2 i.e., S(x) is continuous Winter Semester 2006/7 Computtionl Physics I Lecture 3 10
Splines Liner Spline: Qudrtic Spline: S k (x) = y k + y k +1 y k x k +1 x k (x x k ) S k (x) = y k + z k (x x k ) + z k +1 z k 2(x k +1 x k ) (x x k )2 z 0 hs to e fixed, for exmple from requiring S k () = z 0 = 0. then, z k +1 = z k + 2 y k +1 y k x k +1 x k Winter Semester 2006/7 Computtionl Physics I Lecture 3 11
Splines The cuic spline stisfies the following conditions: 1. S(x) = S k (x) for x k x x k +1 k = 0,1,,n 1 S k (x) = S k,0 + S k,1 (x x k ) + S k,2 (x x k ) 2 + S k,3 (x x k ) 3 2. S(x k ) = y k k = 0,1,,n 3. S k (x k +1 ) = S k +1 (x k +1 ) k = 0,1,,n 2 i.e., S(x) is continuous 4. S k (x k +1 ) = S k +1 (x k +1 ) k = 0,1,,n 2 i.e., S (x) is continuous 5. S k (x k +1 ) = S k +1 (x k +1 ) k = 0,1,,n 2 i.e., S (x) is continuous Winter Semester 2006/7 Computtionl Physics I Lecture 3 12
Splines Need t lest 3rd order polynomil to stisfy the conditions. Numer of prmeters is 4n. Fixing S k (x k )=y k gives n+1 conditions. Fixing S k (x k+1 )=S k+1 (x k+1 ) gives n dditionl n-1 conditions. Mtching the first nd second derivtive gives nother 2n-2 conditions, for totl of 4n-2 conditions. Two more conditions re needed to specify unique cuic spline which stisfies the conditions on the previous pge: S () = 0 S () = 0 Nturl cuic spline Cn tke other options for the oundry conditions Winter Semester 2006/7 Computtionl Physics I Lecture 3 13
Liner spline Splines Cuic spline Qudrtic spline Winter Semester 2006/7 Computtionl Physics I Lecture 3 14
Cuic Splines The cuic spline is optiml in the following sense: 1. It is ccurte to fourth order, nd f(x)-s(x) 5 384 mx f ( 4) (x) h 4 where h = mx k x k +1 x k x 2. It is the minimum curvture function linking the set of dt points. Cuic spline stisfies Curvture is defined s [ S (x) ] 2 dx f (x) [ ] 2 Winter Semester 2006/7 Computtionl Physics I Lecture 3 15 f (x) ( 1 + f (x) 2 ) 3/2 dx f (x) Any smooth interpolting function must hve curvture t lest s lrge s cuic spline
Cuic Splines Proof of 2. Strt with lgeric identity F 2 S 2 = (F S) 2 2S(S F) Let F = f (x), S = S (x) then [ f (x) ] 2 dx [ S (x) ] 2 dx = [ f (x) S (x) ] 2 dx 2 S (x) [ S (x) f (x) ] dx [ f (x) S (x) ] 2 dx 0 S (x) [ S (x) f (x) ] dx = S (x) [ S (x) f (x) ] dx n1 k =0 x k+1 x k Now we use integrtion y prts to solve the integrls Winter Semester 2006/7 Computtionl Physics I Lecture 3 16
Cuic Splines Recll: u(x) v (x)dx = u(x)v(x) u (x)v(x)dx n1 x S (x) ( S (x) f (x) k+1 x ) dx = S (x) ( S (x) f (x) ) k+1 xk S (x) ( S (x) f (x) ) dx k =0 The first term is n1 S (x) S (x) f (x) x k+1 = S () ( S () f () ) S () ( S () f () ) k =0 ( ) xk = 0 From the oundry conditions for nturl cuic spline S (x) is constnt (since we hve cuic) nd cn e tken out of the integrl, so ( ) S (x) S (x) f (x) dx = S k ut since S(x k ) = f (x k ), = 0 n1 k =0 n1 S k k =0 x k+1 x k ( S (x) f (x) ) dx = ( S(x) f (x)) xk x k+1 x k Winter Semester 2006/7 Computtionl Physics I Lecture 3 17
Cuic Splines [ f (x) ] 2 dx [ S (x) ] 2 dx 0 We hve proven tht cuic spline hs smller or equl curvture thn ny function which fulfills the interpoltion requirements. This lso includes the function we strted with. Physicl interprettion: clmped flexile rod picks the minimum curvture to minimize energy - spline Winter Semester 2006/7 Computtionl Physics I Lecture 3 18
Dt Smoothing If we hve lrge numer of dt points, interpoltion with polynomils, splines, etc is very costly in time nd multiplies the numer of dt. Smoothing (or dt fitting) is wy of reducing. In smoothing, we just wnt prmetriztion which hs no model ssocited to it. In fitting, we hve model in mind nd try to extrct the prmeters. Dt fitting is full semester topic of its own. A few rief words on smoothing of dt set. The simplest pproch is to find generl function with free prmeters which cn e djusted to give the est representtion of the dt. The prmeters re optimized y minimizing chi squred: 2 = n i=0 (y i f (x i ; )) 2 w i 2 Winter Semester 2006/7 Computtionl Physics I Lecture 3 19
2 = Dt Smoothing n i=0 (y i f (x i ; )) 2 w i 2 re the prmeters of the function to e fit y i re the mesured points t vlues x i w i is the weight given to point i In our exmple, let s tke f (x; A,) = Acos(x + ) And set w i = 1 i Now we minimize 2 s function of A nd Winter Semester 2006/7 Computtionl Physics I Lecture 3 20
Dt Smoothing Best fit for A=1, =3/2 Acos(x + ) = 1 cos(x + 3 /2)= cos x cos 3 /2 sin xsin 3 /2= sin x Winter Semester 2006/7 Computtionl Physics I Lecture 3 21
Exercises 1. Clculte the Lgrnge Polynomil for the following dt: x 0 0.5 1. 2. y 1 0.368 0.135 0.018 2. For the sme dt, find the nturl cuic spline coefficients. Plot the dt, the lgrnge polynomil nd the cuic spline interpoltions. 3. Smooth the dt in the tle with the function f(x)=aexp(-x). Wht did you get for A,? Winter Semester 2006/7 Computtionl Physics I Lecture 3 22