Mark Trew CT1 2002
Halfway Down Halfway down the stairs Is a stair Where I sit. There isn't any Other stair Quite like It. I'm not at the bottom, I'm not at the top; So this is the stair Where I always Stop. Halfway up the stairs Isn't up, And isn't down. It isn't in the nursery, It isn't in the town. And all sorts of funny thoughts Run round my head: "It isn't really Anywhere! It's somewhere else instead!"
Mark Trew CT Halfway Down Halfway down the stairs Is a stair Where I sit. There isn't any Other stair Quite like It. I'm not at the bottom, I'm not at the top; So this is the stair Where I always Stop. Halfway up the stairs Isn't up, And isn't down. It isn't in the nursery, It isn't in the town. And all sorts of funny thoughts Run round my head: "It isn't really Anywhere! It's somewhere else instead!" A.A. Milne
Mark Trew CT Interpolation – the ups and downs
Mark Trew CT Interpolation and Fitting Discrete datum points obtained by some process Provide basis for a description of behaviour at any point Description usually in some function form: Function can have some physical form based on theoretical behaviour or can be a more general form Use interpolation every day, e.g. measurements, weights, solving ODEs etc. or
Mark Trew CT Interpolation and Fitting Interpolation vs Fitting – in general: -Interpolation reproduces datum values at the datum locations -Fitting seeks to provide the best overall description Interpolation vs Extrapolation -Interpolation: unknown value bracketed by known values -Extrapolation: unknown value has known value on one side only x y x y
Mark Trew CT Polynomial Interpolation Determine the coefficients of a polynomial one order less than the number of datum points: Coefficients found by solving linear system of equations: Significant problems with this kind of interpolation, especially as the number of datum points becomes large: 1.“expensive” to solve for the coefficients 2.System of equations (Vandermonde matrix) becomes ill- conditioned 3.High order polynomials oscillate between points
Mark Trew CT Polynomial (and other) Fitting Polynomials useful for small number of points – at least 3 for a quadratic Can be useful for fitting rather than datum interpolation Given polynomial to “reasonable” order, find coefficients such that function is a good representation of data, e.g. minimise the sum of the squared difference between function and datum values (called Least Squares Fit): If we have N data points and our polynomial is of order m, how can we solve? The problem is overdetermined. know don’t know
Mark Trew CT Polynomial (and other) Fitting Problem looks like: Two options: 1.Solve the normal equations: A T Aa = A T b. Solved by standard LU decomposition, but tend to be badly conditioned and prone to roundoff error. 2.Do a singular value decomposition on A. Naturally finds the solution which is the best least squares approximation. A=a=a=b=b= Aa=bAa=b
Mark Trew CT Up or Down? Up Down Halfway up the stairs Isn't up, And isn't down. It isn't in the nursery, It isn't in the town. How much up and how much down?
Mark Trew CT Lagrangian Interpolation Used for large number of datum points Break whole interpolation range into smaller intervals Use low order polynomial to interpolate over sub-interval only Overcomes problems with high-order polynomial interpolation x y entire range sub-interval
Mark Trew CT Linear Lagrange Interpolation x y sub-interval Put a straight line between each pair of points (x j,y j ) (x j+1,y j+1 ) yj(x)yj(x) What form do L j and L j+1 take?
Mark Trew CT Linear Lagrange Interpolation x x y sub-interval Put a straight line between each pair of points (x j,y j ) (x j+1,y j+1 ) yj(x)yj(x) L j+1 1 xjxj x j+1 Important!! L act as weighting functions: some of y j and some of y j+1
Mark Trew CT Quadratic Lagrange Interpolation x y sub-interval Put a quadratic between each triplet of points (x j-1,y j-1 )(x j,y j ) yj(x)yj(x) (x j+1,y j+1 )
Mark Trew CT Quadratic Lagrange Interpolation L j-1 1 x j-1 x j+1 xjxj LjLj 1 x j-1 x j+1 xjxj L j+1 1 x j-1 x j+1 xjxj
Mark Trew CT Quadratic Lagrange Interpolation Still true? Check! L continue to act as weighting functions: some of y j-1, some of y j, and some of y j+1
Mark Trew CT Lagrange Interpolation of any Order An mth order Lagrange interpolation using m+1 datum points is represented by: The weighting functions, or Lagrange polynomials, are described by: multiply
Mark Trew CT Lagrange Interpolation of any Order Always true that: A problem with Lagrange interpolation is the lack of slope continuity between the sub-interval (element) boundaries. x y sub-interval (x j-1,y j-1 )(x j,y j ) (x j+1,y j+1 ) slope discontinuous Not always important
Mark Trew CT Next time… Function continuity and Cubic Splines
Mark Trew CT The story continues… Function continuity and Cubic Splines
Mark Trew CT Function Continuity
Mark Trew CT Function Continuity C 0 continuity – value continuous C 1 continuity – gradient or slope continuous C 2 continuity – curvature (2 nd derivative) continuous
Mark Trew CT Interpolation with Slope Continuity Four “degrees of freedom” over interval: p j (x j ), p j (x j+1 ), p’ j (x j )=k j and p’ j (x j+1 )=k j+1 Four dof can be fitted by a cubic polynomial. Gradients may be known at x 0 and x N. May be reasonable to set p’’=0 at x 0 and x N. x y sub-interval: j xjxj x j+1 yj(x)yj(x) Definitions: kjkj k j+1 p’’ 0 p’’=0
Mark Trew CT Cubic Spline Polynomial General form: Spline – from thin rods used by engineers to fit smooth curves through a number of points. p j (x) must satisfy: p j (x j )=y j, p j (x j+1 )=y j+1, p’ j (x j )=k j and p’ j (x j+1 )=k j+1 Two steps to make p j (x) useful. (1) Determine a 0 to a 3. (2) Determine k values. Two sets of equations necessary.
Mark Trew CT Step 1: Spline Coefficients To satisfy: p j (x j )=y j, p’ j (x j )=k j, p j (x j+1 )=y j+1 and p’ j (x j+1 )=k j+1
Mark Trew CT …some algebra later…
Mark Trew CT Step 1: Spline Coefficients Solving for a 2 and a 3 : Once the k j values are known, the spline function is determined.
Mark Trew CT Step 2: Unknown Gradients x y’’ sub-interval: j xjxj p’’ j-1 (x) sub-interval: j-1 p’’ j (x) For cubic in each interval: Evaluating the second derivatives: Equating the second derivatives:
Mark Trew CT Step 2: Unknown Gradients Known or assumed information: If k 0 and k N are known, there are N-1 points, N-1 unknown k values and N-1 equations. Equal number of equations and unknowns. x y x0x0 xNxN k0k0 kNkN y’’ N-1 (x N )=0 y’’ 0 (x 0 )=0 N-1 internal points
Mark Trew CT Step 2: Unknown Gradients If k 0 and k N are not known, there are N+1 points, N+1 unknown k values and N-1 equations of the type: and two equations: from the condition of zero curvature (p’’=0) at the end-points. Still equal number of equations and unknowns.
Mark Trew CT Step 2: Unknown Gradients In both cases, equations are put together into a matrix of linear equations in the unknown k values. The system of equations is solved. Each row has only 3 non-zero terms – one on either side of the diagonal. Very efficient to solve. = k
Mark Trew CT Summary Gradient continuous interpolations can be produced using cubic splines. Gradients must be known at the extremum points – or assumption of zero curvature can be used. System of linear equations solved to give gradients at each discrete point. (Step 2) Gradients used to determine coefficents of cubic spline interpolation for each sub-interval. (Step 1) Cubic splines can be used to interpolate to x points lying between known discrete points.
Mark Trew CT The end…