Top Banner
Interpolation Methods Robert A. Dalrymple Johns Hopkins University
40

Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Dec 15, 2015

Download

Documents

Eden Varty
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Interpolation Methods

Robert A. Dalrymple

Johns Hopkins University

Page 2: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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).

Page 3: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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)?

Page 4: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Linear Interpolation

Given two points, (x1,y1), (x2,y2): Fit a straight line between the points.

y(x) = a x +b

a=(y2-y1)/(x2-x1), b= (y1 x2-y2 x1)/(x2-x1), Use this equation to find y values for any

x1 < x < x2

Page 5: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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 be

with N+1 unknown values, ai, of the Nth order polynomial

Page 6: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Polynomial InterpolantForce the interpolant through the four points to get four equations:

Rewriting:

The solution is found by inverting p

Page 7: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Example

Data are: (0,2), (1,0.3975), (2, -0.1126), (3, -0.0986).

Fitting a cubic polynomial through the four points gives:

Page 8: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Matlab code for polynomial fitting

% the data to be interpolated (in 1D) x=[-0.2 .44 1.0 1.34 1.98 2.50 2.95 3.62 4.13 4.64 4.94]; y=[2.75 1.80 -1.52 -2.83 -1.62 1.49 2.98 0.81 -2.14 -2.93 -1.81]; plot(x,y,'bo') n=size(x,2)% CUBIC FIT p=[ones(1,n) x x.*x x.*(x.*x)]' a=p\y' %same as a=inv(p)*y' yp=p*a hold on; plot(x,yp,'k*')

Note: linear and quadratic fit: redefine p

Page 9: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Polynomial Fit to Example

Exact: redPolynomial fit: blue

Page 10: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Beware of Extrapolation

An Nth order polynomial has N roots!

Exact: red

Page 11: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Least Squares InterpolantFor 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:

Page 12: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Least Squares InterpolantMinimizing 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

Page 13: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Question

Show that the equation above leads to the following expression for the best fit straight line:

Page 14: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Matlab: Least-Squares Fit

%the data to be interpolated (1d) x=[-0.2 .44 1.0 1.34 1.98 2.50 2.95 3.62 4.13 4.64 4.94]; y=[2.75 1.80 -1.52 -2.83 -1.62 1.49 2.98 0.81 -2.14 -2.93 -1.81]; plot(x,y,'bo') n=size(x,2)% CUBIC FIT p=[ones(1,n) x x.*x x.*(x.*x)]' pinverse=inv(p'*p)*p' a=pinverse*y' yp=p*a plot(x,yp,'k*')

Page 15: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Cubic Least Squares Example

x: -0.2 .44 1.0 1.34 1.98 2.50 2.95 3.62 4.13 4.64 4.94y: 2.75 1.80 -1.52 -2.83 -1.62 1.49 2.98 0.81 -2.14 -2.93 -1.81

Data irregularly spaced

Page 16: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Least Squares InterpolantCubic Least Squares Fit: * is the fitting polynomial o is the given data

Exact

Page 17: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Piecewise Interpolation

Piecewise polynomials: fit all points

Linear: continuity in y+, y- (fit pairs of points)

Quadratic: +continuity in slope

Cubic splines: +continuity in second derivative

RBFAll of the above, but smoother

Page 18: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Radial Basis FunctionsDeveloped to interpolate 2-D data: think bathymetry.Given depths: , interpolate to a rectangular grid.

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 19: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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 xj

The radial basis function interpolant is:

Page 20: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBF

To find the unknown coefficients i, force the interpolant to go through the data points:

where

This gives N equations for the N unknown coefficients.

Page 21: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBF

Morse et al., 2001

Page 22: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Multiquadric RBF

MQ:

RMQ:

Hardy, 1971; Kansa, 1990

Page 23: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBF Example11 (x,y) pairs: (0.2, 3.00), (0.38, 2.10), (1.07, -1.86), (1.29, -2.71), (1.84, -2.29), (2.31, 0.39), (3.12, 2.91), (3.46, 1.73), (4.12, -2.11), (4.32, -2.79), (4.84, -2.25) SAME AS BEFORE

Page 24: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBF ErrorsLog10 [sqrt (mean squared errors)] versus c: Multiquadric

Page 25: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBF ErrorsLog10 [ sqrt (mean squared errors)] versus c: Reciprocal Multiquadric

Page 26: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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

Page 27: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBFs and PDEsSolve a boundary value problem:

The RBF interpolant is:

N is the number of arbitrarily spaced points; thej are unknown coefficients to be found.

Page 28: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBFs and PDEs

Introduce the interpolant into the governing equation andboundary conditions:

These are N equations for the N unknown constants, j

Page 29: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

RBFs and PDEs (3)

Problem with many RBF is that the N x N matrix thathas to be inverted is fully populated.

RBFs with small ‘footprints’ (Wendland, 2005)

1D:

3D:

His notation:

Advantages: matrix is sparse, but still N x N

Page 30: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Wendland 1-D RBF with Compact Support

h=1Max=1

Page 31: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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

Page 32: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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)

Page 33: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Weighting Function

q=x/h

Page 34: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Moving Least Squares InterpolantMinimizing the weighted squared errors for the coefficients:

,, ,

Page 35: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Moving Least Squares InterpolantSolving

The final locally valid interpolant is:

Page 36: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Moving Least Squares (1)

% generate the data to be interpolated (1d) x=[-0.2 .44 1.0 1.34 1.98 2.50 2.95 3.62 4.13 4.64 4.94]; y=[2.75 1.80 -1.52 -2.83 -1.62 1.49 2.98 0.81 -2.14 -2.93 -1.81]; plot(x,y,'bo') n=size(x,2)% QUADRATIC FIT p=[ones(1,n) x x.*x]' xfit=0.30; sum=0.0 % 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 <= 1. Wd(1,ic)=0.66*(1-1.5*q*q+0.75*q^3); elseif q <= 2. Wd(1,ic)=0.66*0.25*(2-q)^3; else Wd(1,ic)=0.0; end end

Page 37: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

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

Page 38: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

MLS Fit to (Same) Irregular Data

Given data: circles; MLS: *; exact: line

h=0.51

Page 39: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

.3

.5

1.0

1.5

Varying h Values

Page 40: Interpolation Methods Robert A. Dalrymple Johns Hopkins University.

Conclusions

There are a variety of interpolation techniques for irregularly spaced data:

Polynomial Fits

Best Fit Polynomials

Piecewise Polynomials

Radial Basis Functions

Moving Least Squares