Interpolation Interpolation

Interpolation Interpolation

Interpolation • In interpolation or extrapolation we usually want to do the following - We have data points xi yi , i = 12} N - We want to know the y value at xxz i - In interpolation x1 xxN and in extrapolation xx 1 or xx! N - Extrapolation is dangerous; it is used e.g. in solving differential equations. - Data set may have noise: the interpolate should go smoothly through the data set not necessarily through all points. - One application is approximating (special) functions - In this case we have an infinite number of points available. - In some cases interpolation is done by using a few points in the neighborhood of x. - This may result in noncontinuous derivative of the interpolate. - In spline interpolation one condition is that also the derivative is continuous. - In polynomial interpolation one is not particularly interested in the polynomial coefficients only in its values. - Calculating coefficients is rather error prone. Scientific computing III 2011: 6. Interpolation 1 Interpolation • Interpolation vs. curve fitting: Scientific computing III 2011: 6. Interpolation 2 Interpolation • Degree of interpolation is (number of points used)-1. - Below an example of interpolation of a smooth function original function low degree interpolation high degree interpolation - When the original function has sharp corners an interpolation polynomial with a lower degree may work better Scientific computing III 2011: 6. Interpolation 3 Interpolation: polynomials • We have a data set xi yi , yi = fx()i , i = 1} N - We have to find a polynomial P N – 1 x that fulfills the condition PN – 1()xi = yi , i = 1} N - It is easy to show that the polynomial is at most of degree N – 1 and it is unique if all x i are different. - A straightforward way to determine the coefficients is to use the methods we have already learned - Let the polynomial be of the form 2 N–1 yc=1+c2xc+3x ++}cNx - From the above condition we get a group of linear equations ­ 2 N–1 °c1+c2x1+c3x1 ++}cNx1 =y1 ° °c+cx+cx2 ++}cxN–1=y ®12232 N2 2 ° } ° °c+cx+cx2 ++}cxN–1=y ¯12N3N NN N Scientific computing III 2011: 6. Interpolation 4 Interpolation: polynomials • Theorem: existence of interpolating polynomial: If points x1 x2 } xN are distinct, then for arbitrary real values y1 y2 } yN there is a unique polynomial P of degree d N – 1 such that Px i = yi for 1 d i d N . - Proof by induction: Suppose we have already a polynomial P that reproduces a part of the data set: Px i = yi , 1 ddik, (For example: this can be a constant polynomial for data point 1: Px = y1 .) Then we add another term to P so that it will go through the point xk + 1 yk + 1 : Qx = Px + cxx – 1 xx– 2 } xx– k Q reproduces data points 12 } k because P does and the added term is zero for all these points. Now we adjust constant c so that Q reproduces the data point k + 1: Qx k + 1 = Px k + 1 + cx k + 1 – x1 xk + 1 – x2 } xk + 1 – xk = yk + 1 . From this equation we can solve c because all x i are distinct. QED. Scientific computing III 2011: 6. Interpolation 5 Interpolation: polynomial - In matrix form: 1 x x2 } xN – 1 1 1 1 c1 y1 2 N – 1 1 x2 x2 } x2 c2 y2 2 N – 1 c = y 1 x3 x3 } x3 3 3 }}}} } } } 2 N–1 cN yN 1 xNxN}xN - This square matrix has a name of its own: Vandermonde matrix and its a little bad behaving: >> v=1:5 >> v=1:8 v = v = 1 2 3 4 5 1 2 3 4 5 6 7 8 >> m=vander(v) >> m=vander(v) m = m = 1 1 1 1 1 1 1 1 1 1 1 ... 16 8 4 2 1 128 64 32 16 8 4 ... 81 27 9 3 1 2187 729 243 81 27 9 ... 256 64 16 4 1 16384 4096 1024 256 64 16 ... 625 125 25 5 1 78125 15625 3125 625 125 25 ... >> rcond(m) 279936 46656 7776 1296 216 36 ... ans = 823543 117649 16807 2401 343 49 ... 2.2699e-05 2097152 262144 32768 4096 512 64 ... >> rcond(m) ans = 6.0171e-10 Scientific computing III 2011: 6. Interpolation 6 Interpolation: polynomial - A better way is to calculate P N – 1 by using so called Lagrange’s polynomials. - Let the polynomials l1 l2 } lN be defined as N§·xx– l ()x = ¨¸--------------j, i=1}N i ©¹x–x j=1i j jiz - These functions have the property li()xj= Gij - Now we can write P N – 1 x as N P ()x = fx()l()x N – 1 ¦ i i i=1 - It is easy to check that P N–1 x goes through all the data points xiyi . - Because functions l ihave degree less than N it follows that P N–1also has degree less than N. Scientific computing III 2011: 6. Interpolation 7 Interpolation: polynomial - Example: x : 13e 14e 1 43e y : 2 –1 7 2 1 4 §·x– - -- x–1§·x– - -- ©¹4 ©¹3 93 69 l x = ------------------------------------------------------= 1 8 x 3 – ------ x 2 + ------ x – 6 1 11 1 14 2 2 §·- -- – - -- §·---1– §·- -- – - -- ©¹34 ©¹3©¹33 1 4 §·x– - -- x–1§·x– - -- ©¹3 ©¹3 192 512 1216 256 l x = ------------------------------------------------------ = – --------- x 3 + --------- x 2 – ------------ x + --------- 2 11 1 14 13 13 39 39 §·- -- – - -- §·---1– §·- -- – - -- ©¹43 ©¹4©¹43 1 1 4 §·x– - -- §·x– - -- §·x– - -- ©¹3©¹4©¹3 23 31 2 l x = -----------------------------------------------------= – 6 x 3 + ------ x 2 – ------ x + - -- 3 1 1 4 2 6 3 §·1– - -- §·1– - -- §·1– - -- ©¹3©¹4©¹3 1 1 §·x– - -- §·x– - -- x–1 ©¹3©¹4 36 57 24 3 l x = ------------------------------------------------------ = ------ x 3 – ------ x 2 + ------ x – ------ 4 1 41 4 13 13 13 13 §·-4 -- – - -- §·- -- – - -- §·---1– ©¹33 ©¹34 ©¹3 186 1577 5281 560 P x = 2l x–l x+7l x+2l x = --------- x 3 – ------------ x 2 + ------------ x – --------- 3 1 2 3 4 13 26 78 39 Scientific computing III 2011: 6. Interpolation 8 Interpolation: polynomials - So we end up with the interpolation polynomial (let’s leave the subscript out) xx–2 xx–3 } xx–N Px()= ------------------------------------------------------------------------- y 1 x1–x2 x1–x3 } x1 – xN xx–1 xx–3 } xx–N + ------------------------------------------------------------------------- y 2 x2–x1 x2–x3 } x2 – xN + } xx–1 xx–2 } xx–N–1 + ----------------------------------------------------------------------------------- y N xN–x1 xN–x2 } xN – xN – 1 - The error estimation of the above polynomial can be given as follows: - Let x 1 x 2 } x N be distinct numbers in >@ab and let’s assume that f has N continuous derivatives in >@ab - Then for each x >@ ab [ x ab so that N f N [ x fx =Px +------------------------- xx– (1) N! i i=1 Scientific computing III 2011: 6. Interpolation 9 Interpolation: polynomials - Proof: - For xx= k , k = 12 } N fx k = Px k and any [ xk ab fulfills (1) - For x k z x we define function gt as tx– gt = ft –Pt – >@fx –Px N -----------------i(2) i = 1 xx–i - Since f has N continuous derivatives and P has all derivatives continuous and xx z k o gt has N continuous deriv- atives in >@ab - For tx= k Generalized Rolle’s theorem: N x–x gx = fx –Px – >@fx –Px --------------------ki= 0 Assume k k k 1. fx continuous on >@ab , xx–i i = 1 2. derivatives f 1 }x f N x exist in ab , 3. x x x ab, - For tx= 01 } N >@ 4. fx j = 0 , for j = 01} N . N xx– Then , , such that N . gx = fx –Px – >@fx –Px -----------------i= 0 c acb f c = 0 xx– i = 1 i - Thus g vanishes at N + 1 points xx 1 x 2 } x N in >@ab . - Generalized Rolle’s theorem says that [[ { x in ab for which g N [ =0. - From (2) we get dN­½ tx– 0=g N [ =f N [–P N [–>@fx –Px -------- N -----------------i (3) N®¾ i = 1 dt ¯¿ xx–i t=[ Scientific computing III 2011: 6. Interpolation 10 Interpolation: polynomials - Now P is at most of degree N – 1 o P N { 0 - The product term is a polynomial of degree N o N N –1 N tx– dN­½ tx– N! -----------------i= xx– tN+Ot N–1 o -------- -----------------i = ------------------------------------- i N®¾ N xx–i dt ¯¿ xx–i xx– i = 1 i=1 i = 1 i=1 i - (3) now becomes N! 0 = f N [– >@fx –Px ------------------------------------- N xx– i=1 i - And solving for fx we get f N [ fx =Px +----------------- N xx– N! i=1 i QED. - Note the analogy between the error formula of the Taylor series: f N [ ----------------- xx– N N! 0 and f N ----------------- [ xx– xx– } xx– N! 1 2 N Scientific computing III 2011: 6. Interpolation 11 Interpolation: polynomials - Example: - Prepare a table for function fx =ex, x>@01 . - Precision d decimals, step size h - What step size is needed for linear interpolation to give absolute error no more than 10–6 ? - Let x >@01 and xj d x d xj + 1 - Error is now f 2 f 2 f 2 fx –Px d---------------- [ xx– xx– =------------------- [ xx– xx– =------------------- [ x– jh xj– +1h 2! j j+1 2 j j+1 2 1 fx –Px d---max f 2 [ max x– jh xj– +1h 2 [ >@01 xj ddxxj+1 Maximum of x– jh xj– +1his at xj= +12ehwith value h2e4 eh2 o fx –Px d -------- 8 - We want the error to be less than 10–6 : eh2 8 –3 --------d 1 0 – 6 h 2 d ---10–6 h 1.72u10 8 e - So we could choose h=0.001 Scientific computing III 2011: 6.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    53 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us