Presentation on theme: "Interpolation Methods"— Presentation transcript:
1 Interpolation Methods Robert A. DalrympleJohns Hopkins University
2 Why Interpolation?For discrete models of continuous systems, we need the ability to interpolate values in between discrete points.Half of the SPH technique involves interpolation of values known at particles (or nodes).
3 Interpolation To find the value of a function between known values. Consider the two pairs of values (x,y):(0.0, 1.0), (1.0, 2.0)What is y at x = 0.5? That is, what’s (0.5, y)?
4 Linear Interpolation Given two points, (x1,y1), (x2,y2): Fit a straight line between the points.y(x) = a x +ba=(y2-y1)/(x2-x1), b= (y1 x2-y2 x1)/(x2-x1),Use this equation to find y values for anyx1 < x < x2
5 Polynomial Interpolants Given N (=4) data points,Find the interpolating function that goes through the points:If there were N+1 data points, the function would bewith N+1 unknown values, ai, of the Nth order polynomial
6 Polynomial Interpolant Force the interpolant through the four points to get four equations:Rewriting:The solution is found by inverting p(N+1) x (N+1) matrix equation
7 Example Data are: (0,2), (1,0.3975), (2, -0.1126), (3, -0.0986). Fitting a cubic polynomial through the four points gives:
8 Matlab code for polynomial fitting % the data to be interpolated (in 1D)x=[ ];y=[ ];plot(x,y,'bo')n=size(x,2)% CUBIC FITp=[ones(1,n)xx.*xx.*(x.*x)]'a=p\y' %same as a=inv(p)*y'yp=p*ahold on;plot(x,yp,'k*')Note: linear and quadratic fit: redefine p
9 Polynomial Fit to Example Exact: redPolynomial fit: blue
10 Beware of Extrapolation Exact: redAn Nth order polynomial has N roots!
11 Least Squares Interpolant For N points, we will have a fitting polynomial of order m < (N-1).The least squares fitting polynomial be similar to the exact fit form:Now p is N x m matrix. Since we have fewer unknown coefficient as data points, the interpolant cannot go through each point. Define the error as the amount of “miss”Sum of the (errors)2:
12 Least Squares Interpolant Minimizing the sum with respect to the coefficients a:Solving,This can be rewritten in this form,which introduces a pseudo-inverse.Reminder:for cubic fit
13 QuestionShow that the equation above leads to the following expression for the best fit straight line:
14 Matlab: Least-Squares Fit %the data to be interpolated (1d)x=[ ];y=[ ];plot(x,y,'bo')n=size(x,2)% CUBIC FITp=[ones(1,n)xx.*xx.*(x.*x)]'pinverse=inv(p'*p)*p'a=pinverse*y'yp=p*aplot(x,yp,'k*')
15 Cubic Least Squares Example What does a linear fit look like? What does a 10th order polynomial look like?Data irregularly spacedx:y:
16 Least Squares Interpolant Cubic Least Squares Fit: * is the fitting polynomialo is the given dataExact
17 Piecewise Interpolation Piecewise polynomials: fit all pointsLinear: continuity in y+, y- (fit pairs of points)Quadratic: +continuity in slopeCubic splines: +continuity in second derivativeRBFAll of the above, but smootherCan do matlab cubic splines fast?
18 Radial Basis Functions Developed to interpolate 2-D data: think bathymetry.Given depths: , interpolate to a rectangular grid.
19 Radial Basis Functions 2-D data:For each position, there is an associated value:Radial basis function (located at each point):where is the distance from xjThe radial basis function interpolant is:
20 RBF To find the unknown coefficients i, force the interpolant to go through the data points:whereThis gives N equations for the N unknown coefficients.
26 ConsistencyConsistency is the ability of an interpolating polynomial to reproduce a polynomial of a given order.The simplest consistency is constant consistency: reproduce unity.where, again,If gj(0) = 1, then a constraint results:Note: Not all RBFs have gj(0) = 1
27 RBFs and PDEs Solve a boundary value problem: The RBF interpolant is: N is the number of arbitrarily spaced points; thej are unknown coefficients to be found.
28 RBFs and PDEsIntroduce the interpolant into the governing equation andboundary conditions:These are N equations for the N unknown constants, j
29 RBFs and PDEs (3) Problem with many RBF is that the N x N matrix that has to be inverted is fully populated.RBFs with small ‘footprints’ (Wendland, 2005)1D:3D:1D: quartic in r2D: quintic in rHis notation:Advantages: matrix is sparse, but still N x N
30 Wendland 1-D RBF with Compact Support Max=1What would Wendland’s kernels look like in SPH?
31 Moving Least Squares Interpolant are monomials in x for 1D (1, x, x2, x3)x,y in 2D, e.g. (1, x, y, x2, xy, y2 ….)Note aj are functions of x
32 Moving Least Squares Interpolant Define a weighted mean-squared error:where W(x-xi) is a weighting function that decayswith increasing x-xi.Same as previous least squares approach, except for W(x-xi)
34 Moving Least Squares Interpolant Minimizing the weighted squared errors for the coefficients:,,,P same as before
35 Moving Least Squares Interpolant SolvingThe final locally valid interpolant is:
36 Moving Least Squares (1) % generate the data to be interpolated (1d) x=[ ]; y=[ ]; plot(x,y,'bo') n=size(x,2) % QUADRATIC FIT p=[ones(1,n) x x.*x]' xfit=0.30; sum= % compute msq error for it=1:18, % fiting at 18 points xfit=xfit+0.25; d=abs(xfit-x) for ic=1:n q=d(1,ic)/.51; % note 0.3 works for linear fit; 0.51 for quadratic if q <= Wd(1,ic)=0.66*(1-1.5*q*q+0.75*q^3); elseif q <= Wd(1,ic)=0.66*0.25*(2-q)^3; else Wd(1,ic)=0.0; end endMoving Least Squares (1)
37 MLS (2)Warray=diag(Wd); A=p'*(Warray*p) B=p'*Warray acoef=(inv(A)*B)*y' % QUADRATIC FIT yfit=acoef'*[1 xfit xfit*xfit]' hold on; plot(xfit, yfit,'k*') sum=sum+(3.*cos(2.*pi*xfit/3.0)-yfit)^2; end
38 MLS Fit to (Same) Irregular Data h=0.51Given data: circles; MLS: *; exact: line
Your consent to our cookies if you continue to use this website.