natural cubic interpolation - mcmaster...

16
Natural Cubic Interpolation Jingjing Huang 10/24/2012

Upload: others

Post on 20-Apr-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Natural Cubic Interpolation

Jingjing Huang

10/24/2012

Page 2: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Interpolation

• Construct a function crosses known points

• Predict the value of unknown points

Page 3: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Interpolation in modeling

3

Page 4: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Interpolation

• Polynomial Interpolation – Same polynomial for all points

– Vandermonde Matrix, ill-conditioned

• Lagrange Form – Hard to evaluate

• Piecewise Interpolation – Different polynomials for each interval

Page 5: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Lagrange form Given k+1 points Define: where

Page 6: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Lagrange form

Page 7: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Lagrange form

• Example: interpolate f(x) = x2, for x = 1,2,3

Page 8: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

How to represent models • Specify every point along a model?

– Hard to get precise results

– Too much data, too hard to work with generally

• Specify a model by a small number of “control points”

– Known as a spline curve or just spline

8

Page 9: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Spline Interpolation

• For some cases, polynomials can lead to erroneous results because of round off error and overshoot.

• Alternative approach is to apply lower-order polynomials to subsets of data points. Such connecting polynomials are called spline functions.

9

Page 10: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Spline Interpolation Definition

• Given n+1 distinct knots xi such that:

with n+1 knot values yi find a spline function

with each Si(x) a polynomial of degree at most n.

Page 11: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Tangent

• The derivative of a curve represents the tangent vector to the curve at some point

11

dx

dtt( )

x t( )

Page 12: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

(a)Linear spline

– Derivatives are not continuous

– Not smooth

(b) Quadratic spline

– Continuous 1st derivatives

(c) Cubic spline

– Continuous 1st & 2nd derivatives

– Smoother

12

Page 13: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

• Why cubic?

– Good enough for some cases

– The degree is not too high to be easily solved

13

Page 14: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Natural Cubic Spline Interpolation

• Si(x) = aix3 + bix

2 + cix + di (Given n points) – 4 Coefficients with n-1 subintervals = 4n-4 equations

– There are 4n-6 conditions

• Interpolation conditions

• Continuity conditions

• Natural Conditions

– S’’(x0) = 0

– S’’(xn) = 0

– O(n3)

Page 15: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Natural Cubic Spline Interpolation

• A clever method

– Construct S(x)

Lagrange Form thought

– Solve tridiagonal matrix

Using decompt & solvet (2-1)

– Evaluate of S(z)

Locate z in some interval (using binary search)

Using Horner’s rule to evaluate

Page 16: Natural Cubic Interpolation - McMaster Universityqiao/courses/cs4xo3/tutorials/CubicSpline.pdfNatural Cubic Interpolation Jingjing Huang 10/24/2012 . Interpolation •Construct a function

Thanks