polynomial interpolation you will frequently have occasions to estimate intermediate values between...

16
Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate must pass through the actual data points - this makes interpolation more restrictive than fitting. The most common method for this purpose is polynomial interpolation, where an (n- 1) th order polynomial is solved that passes through n data points: f ( x) a 1 a 2 x a 3 x 2 a n x n 1 MATLAB version : f ( x) p 1 x n 1 p 2 x n 2 p n 1 x p n

Upload: ellen-hines

Post on 02-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Polynomial Interpolation

• You will frequently have occasions to estimate intermediate values between precise data points.

• The function you use to interpolate must pass through the actual data points - this makes interpolation more restrictive than fitting.

• The most common method for this purpose is polynomial interpolation, where an (n-1)th order polynomial is solved that passes through n data points:

f (x) a1 a2xa3x2 anx

n 1

MATLAB version :

f (x) p1xn 1 p2x

n 2 pn 1x pn

Page 2: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Determining Coefficients

• Since polynomial interpolation provides as many basis functions as there are data points (n), the polynomial coefficients can be found exactly using linear algebra.

• MATLAB’s built in polyfit and polyval commands can also be used - all that is required is making sure the order of the fit for n data points is n-1.

Page 3: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Polynomial Interpolation Problems

• One problem that can occur with solving for the coefficients of a polynomial is that the system to be inverted is in the form:

• Matrices such as that on the left are known as Vandermonde matrices, and they are very ill-conditioned - meaning their solutions are very sensitive to round-off errors.

x1n 1 x1

n 2 x1 1x2n 1 x2

n 2 x2 1 xn 1n 1 xn 1

n 2 xn 1 1xnn 1 xn

n 2 xn 1

p1

p2

pn 1

pn

f x1 f x2

f xn 1 f xn

Page 4: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Newton Interpolating Polynomials

• Another way to express a polynomial interpolation is to use Newton’s interpolating polynomial.

• The differences between a simple polynomial and Newton’s interpolating polynomial for first and second order interpolations are:

))(()()()(2

)()()(1

NewtonSimpleOrder

21312122

3212

1211211

xxxxbxxbbxfxaxaaxfnd

xxbbxfxaaxfst

Page 5: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Newton Interpolating Polynomials (cont)

• The first-order Newton interpolating polynomial may be obtained from linear interpolation and similar triangles, as shown.

• The resulting formula based on known points x1 and x2 and the values of the dependent function at those points is:

f1 x f x1 f x2 f x1 x2 x1

x x1

Page 6: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Newton Interpolating Polynomials (cont)

• The second-order Newton interpolating polynomial introduces some curvature to the line connecting the points, but still goes through the first two points.

• The resulting formula based on known points x1, x2, and x3 and the values of the dependent function at those points is:

f2 x f x1 f x2 f x1 x2 x1

x x1

f x3 f x2 x3 x2

f x2 f x1 x2 x1

x3 x1

x x1 x x2

Page 7: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Newton Interpolating Polynomials (cont)

• In general, an (n-1)th Newton interpolating polynomial has all the terms of the (n-2)th polynomial plus one extra.

• The general formula is:

where

and the f[…] represent divided differences.

fn 1 x b1 b2 x x1 bn x x1 x x2 x xn 1

b1 f x1 b2 f x2, x1 b3 f x3, x2, x1

bn f xn, xn 1,, x2 , x1

Page 8: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Divided Differences

• Divided difference are calculated as follows:

• Divided differences are calculated using divided difference of a smaller number of terms:

f xi , x j f xi f x j xi x j

f xi , x j , xk f xi , x j f x j , xk

xi xk

f xn, xn 1,, x2 , x1 f xn, xn 1,, x2 f xn 1, xn 2,, x1 xn x1

Page 9: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Example

• Approximate the function with a third order polynomial through x values 1,4,5,6.

xxf ln)(

Page 10: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Oscillations

• Higher-order polynomials can not only lead to round-off errors due to ill-conditioning, but can also introduce oscillations to an interpolation or fit where they should not be.

• In the figures below, the dashed line represents a function, the circles represent samples of the function, and the solid line represents the results of a polynomial interpolation:

Page 11: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Introduction to Splines

• An alternative approach to using a single (n-1)th order polynomial to interpolate between n points is to apply lower-order polynomials in a piecewise fashion to subsets of data points.

• These connecting polynomials are called spline functions.

• Splines minimize oscillations and reduce round-off error due to their lower-order nature.

Page 12: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Spline Development

• Spline function (si(x))coefficients are calculated for each interval of a data set.

• The number of data points (fi) used for each spline function depends on the order of the spline function.

Page 13: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Cubic Splines

• While data of a particular size presents many options for the order of spline functions, cubic splines are preferred because they provide the simplest representation that exhibits the desired appearance of smoothness.– Linear splines have discontinuous first derivatives– Quadratic splines have discontinuous second derivatives

and require setting the second derivative at some point to a pre-determined value*but*

– Quartic or higher-order splines tend to exhibit the instabilities inherent in higher order polynomials (ill-conditioning or oscillations)

Page 14: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Piecewise Interpolation in MATLAB

• MATLAB has several built-in functions to implement piecewise interpolation. The first is spline:

yy=spline(x, y, xx)This performs cubic spline interpolation. If y contains two more values than x has entries, then the first and last value in y are used as the derivatives at the end points (i.e. clamped)

Page 15: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Example

• Generate data:x = linspace(-1, 1, 9);y = 1./(1+25*x.^2);

• Calculate 100 model points anddetermine a cubic spline interpolationxx = linspace(-1, 1);yy = spline(x, y, xx);

• Calculate actual function values at model points and data points, the 9-point interpolation (solid), and the actual function (dashed), yr = 1./(1+25*xx.^2)plot(x, y, ‘o’, xx, yy, ‘-’, xx, yr, ‘--’)

Page 16: Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate

Clamped Example• Generate data w/ first derivative information:

x = linspace(-1, 1, 9);y = 1./(1+25*x.^2);yc = [1 y -4]

• Calculate 100 model points anddetermine a cubic spline interpolationxx = linspace(-1, 1);yyc = spline(x, yc, xx);

• Calculate actual function values at model points and data points, the 9-point clamped interpolation (solid), and the actual function (dashed), yr = 1./(1+25*xx.^2)plot(x, y, ‘o’, xx, yyc, ‘-’, xx, yr, ‘--’)