18
Computers in Civil Computers in Civil Engineering Engineering 53:081 Spring 2003 53:081 Spring 2003 Lecture #15 Lecture #15 Spline Interpolation Spline Interpolation

Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Embed Size (px)

Citation preview

Page 1: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Computers in Civil Computers in Civil EngineeringEngineering

53:081 Spring 200353:081 Spring 2003

Lecture #15Lecture #15

Spline InterpolationSpline Interpolation

Page 2: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Newton Interpolation ProblemNewton Interpolation ProblemIn some cases Newton Interpolation (while going through all the data points) gives problematic results because of round-off errors and overshoot. This happens in the vicinity of an abrupt change.

Simple, low order, piecewise polynomials (splines) give better results.

Linear splines

Page 3: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Spline ConceptSpline Concept

112

1 cxbxa 22

22 cxbxa

332

3 cxbxa

)( 0xf)( 1xf

)( 2xf

)( xf

0x 1x 2x 3x x

)( 3xf11

21 cxbxa

222

2 cxbxa 33

23 cxbxa

)( 0xf)( 1xf

)( 2xf

)( xf

0x 1x 2x 3x

)( 3xf

i = 0 i = 1 i = 2 i = 3

In terva l 1 In terva l 2 In terva l 3

Use low order (most often 3rd order), piecewise polynomials

Page 4: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Origin of Term SplineOrigin of Term Spline

Page 5: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Main drawback: lack of smoothness or, discontinuous derivatives – but it’s the best you can do with piecewise linear!

21111

21111

10000

)()()(

)()()(

)()()(

xxxxxmxfxf

xxxxxmxfxf

xxxxxmxfxf

nnnn

Linear SplinesLinear Splines

x1086420

2First-order spline

f x( )

Page 6: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Linear Spline InterpolationLinear Spline Interpolation

jx 0x

)( jxf

)( 0xf

im

Page 7: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

If we require that the mth order derivatives to be smooth, m+1 order spline must be used.

For n+1 data points there are n intervals involved, thus, there are 3n coefficients to evaluate.

Thus, 3n conditions are required.

Quadratic SplinesQuadratic Splines

iiii cxbxaxf 2)(

x1086420

2

Second-order spline

f x( )

Quadratic (second order) splines, have first derivative continuous at knots.

Page 8: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Conditions RequiredConditions Required

I. The function values must be equal at the interior points (2n-2 conditions)

II. The first and last functions must pass through the end points (2 conditions)

III. The first derivatives at the interior points must be equal (n-1 conditions)

IV. Assume that the second derivative is zero at the first point (1 condition)

iiii cxbxaxf 2)(

x1086420

2

Second-order spline

f x( )

Page 9: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Quadratic Splines: Condition IQuadratic Splines: Condition I

The function values must be equal at the interior points (2n-2 conditions)

1112

111)( iiiiii cxbxaxf

nicxbxaxf iiiiii ,2for )( 112

11

iiii cxbxaxf 2)(

x1086420

2

Second-order spline

f x( )

Page 10: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Quadratic Splines: Condition IIQuadratic Splines: Condition II

The first and last functions must pass through the end points (2 conditions)

1012010 )( cxbxaxf

nnnnnn cxbxaxf 2)(

iiii cxbxaxf 2)(

x1086420

2

Second-order spline

f x( )

Page 11: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

The first derivatives at the interior points must be equal (n-1 conditions)

Quadratic Splines: Condition IIIQuadratic Splines: Condition III

nibxabxa iiiiii ,222 1111 for

iiii cxbxaxf 2)(

x1086420

2

Second-order spline

f x( )

Page 12: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Quadratic Splines Condition Quadratic Splines Condition IVIV

Assume that the second derivative is zero at the first point (1 condition)

The first 2 points will be connected with a straight line.

01 a

iiii cxbxaxf 2)(

x1086420

2

Second-order spline

f x( )

Page 13: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Quadratic SplinesQuadratic Splines

The 3n unknowns can be obtained by solving a system of linear equations (3n by 3n)

See example 18.9 in the textbook for a worked example.

1112

111)( iiiiii cxbxaxf

nicxbxaxf iiiiii ,2)( 112

11 for

1012010 )( cxbxaxf

nnnnnn cxbxaxf 2)(nibxabxa iiiiii ,222 1111 for

01 a

1(a)

3

2(a)

4

1(b)

2(b)

Page 14: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Cubic SplinesCubic Splines

iiiii dxcxbxaxf 3)(

x1086420

2

Cubicspline Interpolating

(Newton) cubic

f x( )

Page 15: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Cubic SplinesCubic Splines

For n+1 data points, there are 4n unknowns to evaluate. Thus, 4n conditions are required:

iiiii dxcxbxaxf 3)(General form:

I. The function values must be equal at the interior points (2n-2 conditions)

II. The first and last functions must pass through the end points (2 conditions)

III. The first derivatives at the interior points must be equal (n-1 conditions)

IV. The second derivatives at the interior points must be equal (n-1 conditions)

V. The second derivatives at the end points are zero (2 conditions)

Page 16: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Cubic SplinesCubic Splines

Solve 4n by 4n system of linear equations Solve n-1 by n-1 system of linear equations

(derived using Lagrange polynomials)

Two methods of solving for the unknown coefficients:

Page 17: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

MATLAB SplinesMATLAB Splines

yy=spline(x,y,xx)

Two functions for one-dimensional interpolation

SPLINE:

y=interp1(x,y,xi,’nearest’)INTERP1:y=interp1(x,y,xi,’linear’)y=interp1(x,y,xi,’spline’)y=interp1(x,y,xi,’cubic’)

Page 18: Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation

Next:Next:

Numerical IntegrationNumerical Integration