numerical interpolation...numerical interpolation:definitions given a set of measurements (or...

41
Numerical Interpolation Overview Motivation Lagrange Polynomials Newton Interpolation (Divided Differences) Method Interpolation Using Splines Linear, Quadratic, Cubic ITCS 4133/5133: Numerical Comp. Methods 1 Numerical Interpolation

Upload: others

Post on 07-Mar-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Numerical Interpolation

Overview

� Motivation

� Lagrange Polynomials

� Newton Interpolation (Divided Differences) Method

� Interpolation Using Splines

⇒ Linear, Quadratic, Cubic

ITCS 4133/5133: Numerical Comp. Methods 1 Numerical Interpolation

Page 2: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Numerical Interpolation:Definitions

Given a set of measurements (or function values) at a set of points, toestimate the values at unknown sample points.

� Many engineering problems, instruments (scanners, cameras, etc)measure data at a discrete set of points (digitization)

� Subsequent analysis requires evaluation of the function at otherpoints (within the function domain).

� Interpolation methods permit approximate functions to be fit over theknown points.

� Interpolants can be linear, quadratic, cubic and multidimensional.

ITCS 4133/5133: Numerical Comp. Methods 2 Numerical Interpolation

Page 3: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Motivation

ITCS 4133/5133: Numerical Comp. Methods 3 Numerical Interpolation

Page 4: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Motivation

ITCS 4133/5133: Numerical Comp. Methods 4 Numerical Interpolation

Page 5: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Method of Undetermined Coefficients

� Use an nth order polynomial as the interpolant:

f (x) = b0 + b1x + b2x2 + · · · + bnx

n

� Use the known values (x, f (x) pairs) to determine the coefficients ofthe polynomial.

ITCS 4133/5133: Numerical Comp. Methods 5 Numerical Interpolation

Page 6: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Method of Undetermined Coefficients:LinearInterpolant

x xi i+1

f(x)

xx

f(x)

f (x)− f (xi)

x− xi

=f (xi+1)− f (xi)

xi+1 − xi

f (x) = f (xi) +x− xi

xi+1 − xi

[f (xi+1)− f (xi)]

� x is chosen to lie between xi and xi+1, the nearest neighbors.

� Linear interpolant uses the product of the derivative (dy/dx) and thedeviation (x − xi) as a correction term to the base function valuef (xi).

ITCS 4133/5133: Numerical Comp. Methods 6 Numerical Interpolation

Page 7: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Lagrange Interpolation

� Earlier methods restrict the discrete data to be within a constantinterval.

� For many applications, data collection cannot be controlled, and weend up with data at unequal intervals, for instance, xi, f (xi), i =1, . . . N

Given a set of values xi, f (xi), i = 1, . . . N , where f (xi) is the functionvalue at xi, Lagrange interpolating equation for any point x0 is given by

f (x) =

n∑i=1

wi(x)f (xi)

where wis are the weights, and are a function of x0, and given by

wi(x) =

∏nj 6=i,j=1(x− xj)∏nj 6=i,j=1(xi − xj)

ITCS 4133/5133: Numerical Comp. Methods 7 Numerical Interpolation

Page 8: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Lagrange Interpolation(contd)

� Lagrange form for straightline through 2 points:

p(x) =(x− x2)

(x1 − x2)y1 +

(x− x1)

(x2 − x1)y2

� Lagrange form of a parabola through 3 points:

p(x) = w1(x)y1 + w2(x)y2 + w3(x)y3

=(x− x2)(x− x3)

(x1 − x2)(x1 − x3)y1 +

(x− x1)(x− x3)

(x2 − x1)(x2 − x3)y2 +

(x− x1)(x− x2)

(x3 − x1)(x3 − x2)y3

� Notice that the equations pass through all the points (xk, yk)

ITCS 4133/5133: Numerical Comp. Methods 8 Numerical Interpolation

Page 9: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Lagrange Interpolation:Example

x = [−2, 0,−1, 1, 2]

y = [4, 2,−1, 1, 8]

ITCS 4133/5133: Numerical Comp. Methods 9 Numerical Interpolation

Page 10: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Lagrange Interpolation:Algorithm

(Left) Compute Coefficients (Right) Evaluate Polynomial

ITCS 4133/5133: Numerical Comp. Methods 10 Numerical Interpolation

Page 11: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Lagrange Interpolation:Difficulties

⇒ Adding additional points to the function - does not improve the curveshape.

⇒ Also, must redo the entire computation from scratch.

ITCS 4133/5133: Numerical Comp. Methods 11 Numerical Interpolation

Page 12: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Lagrange Interpolation:Analysis

◦ Lagrange formulation is of the form (for a straight line)

L(x) = L1y1 + L2y2

◦ Consider x1 = 0, x2 = 1; then the basis lines are

L1 : −x + 1, L2 : y = x

ITCS 4133/5133: Numerical Comp. Methods 12 Numerical Interpolation

Page 13: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Newton Interpolation Polynomials

� These methods can successively generate the polynomials to inter-polate discrete data

Let Pn(x) be the nth order Lagrange polynomial representing f (x) atx1, x2, . . . xn,

Pn(x) = a1+ a2(x− x1) + a3(x− x1)(x− x2) + · · · +an(x− x1)(x− x1) . . . (x− xn−1)

By evaluating the function at x1, x2, ... we can solve for a1, a2, ...., etc.

a1 = Pn(x1) = f (x1) = y1

ITCS 4133/5133: Numerical Comp. Methods 13 Numerical Interpolation

Page 14: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Newton Interpolation Polynomials (contd.)

To obtain a1,

f (x1) + a2(x2 − x1) = Pn(x2) = f (x2) = y2

a2 =y2 − y1)

x2 − x1

Similarly,

a3 =

y3−y2

x3−x2− y2−y1

x2−x1

x3 − x1

⇒ Calculations can be made in a systematic manner using divided dif-ferences of the function values.

ITCS 4133/5133: Numerical Comp. Methods 14 Numerical Interpolation

Page 15: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Divided Differences

Zeroth Divided Difference

f [xi] = f (xi)

First Divided Difference

f [xi, xi+1] =f [xi+1]− f [xi]

xi+1 − xi

Second Divided Difference

f [xi, xi+1, xi+2] =f [xi+1, xi+2]− f [xi, xi+1]

xi+2 − xi

ITCS 4133/5133: Numerical Comp. Methods 15 Numerical Interpolation

Page 16: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Divided Differences (contd.)

kth Divided Difference

f [xi, xi+1, . . . xi+k] =f [xi+1, . . . , xi+k]− f [xi, . . . , xi+k−1]

xi+k − xi

Pn(x) can thus be expressed as

Pn(x) = f [x0] +

n∑k=1

f [x0, x1, . . . , xk](x− x0)(x− x1) . . . (x− xk−1)

ITCS 4133/5133: Numerical Comp. Methods 16 Numerical Interpolation

Page 17: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Newton Interpolation: Example

ITCS 4133/5133: Numerical Comp. Methods 17 Numerical Interpolation

Page 18: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Newton Interpolation: Additional Points

◦ Additional points added does not require the calculations to be re-peated from scratch.

ITCS 4133/5133: Numerical Comp. Methods 18 Numerical Interpolation

Page 19: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Newton Interpolation: Algorithm

ITCS 4133/5133: Numerical Comp. Methods 19 Numerical Interpolation

Page 20: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Newton Interpolation: Analysis

� Especially convenient when x-spacing is constant

� Can add new points to compute higher order polynomials withoutrestarting the computation, i.e. incrementally.

◦ Example: for points (0, 1), (1, 3), (2, 6), basis functions are P1(x) =1, P2(x) = x, P3(x) = x(x− 1)

◦ Polynomial is

N(x) = 1 + 2(x− 0) + 0.5(x− 0)(x− 1)ITCS 4133/5133: Numerical Comp. Methods 20 Numerical Interpolation

Page 21: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Polynomial Interpolation: Difficulties

ITCS 4133/5133: Numerical Comp. Methods 21 Numerical Interpolation

Page 22: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Spline Interpolation

Motivation

� Using higher order polynomials can sometimes be inaccurate, espe-cially when a function f (x) has abrupt local changes

� In these instances, it can be better to use lower order polynomials,termed splines

� Splines are typically linear, quadratic or cubic

� Examples include Hermite, Bezier, B-Spline, Catmull-Rom

ITCS 4133/5133: Numerical Comp. Methods 22 Numerical Interpolation

Page 23: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Linear Splines

⇒ Connects adjacent points with linear segments

f1(x) = f (x1) +f (x2)− f (x1)

x2 − x1), x1 ≤ x ≤ x2

... ...

fn−1(x) = f (xn−1) +f (xn)− f (xn−1)

xn − xn−1), xn−1 ≤ x ≤ xn

and satisfies the following condition

fi(xi+1) = fi+1(xi), for i = 1, 2, ...

Notes

⇒ Linear splines interpolate (or intersect) all the input discrete points.

⇒ They are thus, discontinuous at the data points.ITCS 4133/5133: Numerical Comp. Methods 23 Numerical Interpolation

Page 24: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Quadratic Splines

� A quadratic function is defined between each pair of adjacent points,

fi(x) = aix2 + bix + ci, for i = 1, 2, . . . , n− 1

requiring 3(n− 1) equations to solve for the 3(n− 1) unknowns

ITCS 4133/5133: Numerical Comp. Methods 24 Numerical Interpolation

Page 25: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Quadratic Splines

Necessary Conditions

⇒ Splines pass through the data points:

fi(xi) = f (xi) = aix2i + bixi + ci, for i = 1, 2, . . . , n− 1

fi(xi+1) = f (xi+1) = aix2i+1 + bixi+1 + ci, for i = 1, 2, . . . , n− 1

⇒ Splines are continuous at the interior points (equal first derivatives)

2aixi+1 + bi = 2ai+1xi+1 + bi+1, for i = 1, 2, . . . , n− 2

⇒ Arbitrary: set second derivative for spline between first 2 data pointsto zero,

a1 = 0

resulting in the 3(n− 1) conditions to solve for the coefficients.

ITCS 4133/5133: Numerical Comp. Methods 25 Numerical Interpolation

Page 26: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Quadratic Splines: Example

◦ Dataset used

ITCS 4133/5133: Numerical Comp. Methods 26 Numerical Interpolation

Page 27: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Quadratic Splines: Example(contd)

ITCS 4133/5133: Numerical Comp. Methods 27 Numerical Interpolation

Page 28: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Quadratic Splines: Example(contd)

ITCS 4133/5133: Numerical Comp. Methods 28 Numerical Interpolation

Page 29: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Quadratic Splines: Example(contd)

ITCS 4133/5133: Numerical Comp. Methods 29 Numerical Interpolation

Page 30: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Cubic Splines

� A cubic function is defined between each pair of adjacent points,

fi(x) = aix3 + bix

2 + cix + di, for i = 1, 2, . . . , n− 1

requiring 4(n− 1) equations to solve for the 3(n− 1) unknowns

ITCS 4133/5133: Numerical Comp. Methods 30 Numerical Interpolation

Page 31: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Cubic Splines

Necessary Conditions

⇒ Splines pass through the data points:

fi(xi) = f (xi) = aix3i + bix

2i + cixi + di, for i = 1, 2, . . . , n− 1

fi(xi+1) = f (xi+1) = aix3i+1 + bix

2i+1 + cixi+1 + di, for i = 1, 2, . . . , n− 1

⇒ Splines are continuous at the interior points (equal first derivatives)

3aix2i+1 + bixi+1 + ci = 3ai+1x

2i+1 + bi+1xi+1 + ci+1, for i = 1, 2, . . . , n− 2

⇒ Set second derivative at first and last end point to zero,

6a1x1 + b1 = 0

6an−1xn + bn−1 = 0

resulting in the 4(n− 1) conditions to solve for the coefficients.ITCS 4133/5133: Numerical Comp. Methods 31 Numerical Interpolation

Page 32: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Application: Cubic Splines in GeometricModeling

Implicit form

F (x, y, z) = 0

Parametric form

x(t) = x(t)

y(t) = y(t)

z(t) = z(t)

Example: Lines

y = mx + c (Implicit)x(t) = x0 + t(x1 − x0) (Parametric)y(t) = y0 + t(y1 − y0) (Parametric)

ITCS 4133/5133: Numerical Comp. Methods 32 Numerical Interpolation

Page 33: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Cubic Polynomials

x(u) = axu3 + bxu

2 + cxu + dx

y(u) = ayu3 + byu

2 + cyu + dy

z(u) = azu3 + bzu

2 + czu + dz

0 ≤ u ≤ 1.

which can be written in matrix form as

Q(u) =[x(u) y(u) z(u)

]=[u3 u2 u 1

] ax ay az

bx by bz

cx cy cz

dx dy dz

= U · C

Q(u) is the curve evaluated at u.

ITCS 4133/5133: Numerical Comp. Methods 33 Numerical Interpolation

Page 34: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Cubic Polynomials(contd.)

Q′(u) =

[d

dtx(t)

d

dty(t)

d

dtz(t)

]=

d

dt

[U · C

]is the tangent vector (velocity) of the curve at u and C is the coefficientmatrix.

C = M ·G

where M is known as a basis matrix and G, the geometry vector, thatdescribes the constraints of the curve formulation.

ITCS 4133/5133: Numerical Comp. Methods 34 Numerical Interpolation

Page 35: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Cubic Polynomials(contd.)

Hence

Q(u) = U ·M ·G

or,

Q(u) =[x(u) y(u) z(u)

]

=[u3 u2 u 1

] m00 m01 m02 m03m10 m11 m12 m13m20 m21 m22 m23m30 m31 m32 m33

G0

G1G2G3

ITCS 4133/5133: Numerical Comp. Methods 35 Numerical Interpolation

Page 36: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Example

P1

P2P3

P4

ITCS 4133/5133: Numerical Comp. Methods 36 Numerical Interpolation

Page 37: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Notes:

� Basis (or blending) functions shape the control points into a curvesegment.

� Why use control points? Can be interactively ‘pulled’ to alter thecurve shape - a key to interactive design and modeling.

� Blending functions can either interpolate or approximate the controlpoints.

� B-Spline and Bezier basis functions are the most popular.

� Cubics are most popular from a computational point of view.

� Easily extended to higher degree curves.

� B-Spline/Bezier surfaces in 3D - straightforward extension of B-Spline/Bezier curves.

ITCS 4133/5133: Numerical Comp. Methods 37 Numerical Interpolation

Page 38: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Parametric Representation of Cubic Curves

Q(u) = U ·M ·G

Hermite Formulation

� Constraints: (G = P0, P3, R0, R3), P0, P3 are end points (u =0 and u = 1), R0, R3 are tangent vectors at P0 and P3.

� Parameterization Interval: 0.0....1.0

� Basis Functions: Bi = {2u3−3u2+1,−2u3+3u2, u3−2u2+u, u3−u2}

Q(u) =[x(u) y(u) z(u)

]=[u3 u2 u 1

] 2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0

P0

P3R0R3

= U ·MH ·GH

ITCS 4133/5133: Numerical Comp. Methods 38 Numerical Interpolation

Page 39: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Derivation of MH

Q(u) = au3 + bu2 + cu + d

Q(u) =[u3 u2 u 1

]•

abcd

Q′(u) =

[3u2 2u 1 0

]•

abcd

Q(0)

Q(1)Q′(0)Q′(1)

=

0 0 0 11 1 1 10 0 1 03 2 1 0

•a

bcd

ITCS 4133/5133: Numerical Comp. Methods 39 Numerical Interpolation

Page 40: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Derivation of MH(contd.)

Q(0)Q(1)Q′(0)Q′(1)

=

0 0 0 11 1 1 10 0 1 03 2 1 0

•a

bcd

a

bcd

=

2 −2 1 1−3 3 −2 −10 0 1 01 0 0 0

•Q(0)

Q(1)Q′(0)Q′(1)

= MH •

Q(0)Q(1)Q′(0)Q′(1)

ITCS 4133/5133: Numerical Comp. Methods 40 Numerical Interpolation

Page 41: Numerical Interpolation...Numerical Interpolation:Definitions Given a set of measurements (or function values) at a set of points, to estimate the values at unknown sample points

Bezier Curve Formulation

� Constraints: G = (P0, P1, P2, P3) which is the control point mesh, withR0 = Q′(0) = 3(P1 − P0), R3 = Q′(1) = 3(P3 − P2)

� Parameterization Interval: 0.0....1.0

� Basis Functions: Bi = {(1− u)3, 3u(1− u)2, 3u2(1− u), u3}

Q(u) =[x(u) y(u) z(u)

]=[u3 u2 u 1

] −1 3 −3 13 −6 3 0−3 3 0 01 0 0 0

P0

P1P2P3

= U ·MB ·GB

Bezier form is advantageous since the curve is controlled completely bypoints, in contrast to tangent vectors and points.

ITCS 4133/5133: Numerical Comp. Methods 41 Numerical Interpolation