22
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 23 CURVE FITTING Chapter 18 Function Interpolation and Approximation

ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 23 CURVE FITTING Chapter 18 Function Interpolation and Approximation

  • View
    234

  • Download
    2

Embed Size (px)

Citation preview

ECIV 301Programming & Graphics

Numerical Methods for Engineers

Lecture 23CURVE FITTING Chapter 18

Function Interpolation and Approximation

Lagrange Interpolating Polynomials

• Reformulation of Newton’s Polynomials

• Avoid Calculation of Divided Differences

n

iiin xfxLxf

0

)()(x f(x)xo f(xo )

x1 f(x1 )

x2 f(x2 )

… …

xn f(xn)

n

ijj ji

ji xx

xxxL

0

)(

Lagrange Interpolating PolynomialCardinal Functions: Product of n-1 linear factors

ni

n

ii

i

ii

i

iii xx

xx

xx

xx

xx

xx

xx

xx

xx

xxxL

1

1

1

1

2

2

1

1

Skip xi

Property:

ji if 1

ji if 0ijji xL

ExampleWrite cardinal functions and give

the Lagrange interpolating polynomial for

412)(

731

yxf

x

Other Methods

nn xaxaxaaoxf 2

21)(

Direct Evaluation

n+1 coefficients

n210

n210

y y yy yf(x)

x x x x x

n+1 Data Points

Interpolating Polynomial should represent them exactly

Other Methods

nn xaxaxaaoxf 2

21)(

Direct Evaluation

n210

n210

y y yy yf(x)

x x x x x

nn xaxaxaaoy 0

202010

nn xaxaxaaoy 1

212111

nnnnnn xaxaxaaoy 2

21

Other Methods

n

1

0

2

1211

0200

n

1

0

a

a

a

y

y

y

nnnn

n

n

xxx

xxx

xxx

Solve Using any of the methods we have learned

Other Methods

•Not the most efficient method

•Ill-conditioned matrix (nearly singular)

•If n is large highly inaccurate coefficients

•Limit to lower order polynomials

Inverse Interpolation

n321

n321

y y y yy f(x)

x x x xx

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

Xr=?Xr=?

Yr=GivenYr=Given

Inverse Interpolation

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

Xr=?Xr=?

Switch x and y and then interpolate?

Not a Good Idea!

n321

n321

x x x x x

y y y y f(x)

Yr=GivenYr=Given

Inverse Interpolation

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

Fit and nth order polynomial to x, f(x) data

Solve Equation 0 Yrxf rn

Xr=?Xr=?

Yr=GivenYr=Given

Errors in Polynomial Interpolation

n321

n321

y y y yy f(x)

x x x xx

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

It is expected that as number of nodes increases, error decreases, HOWEVER….

n

iiin xfxLxf

11

At all interpolation nodes xi Error=0At all intermediate points

Error: f(x)-fn-1(x)

f(x)

Errors in Polynomial Interpolation

Beware of Oscillations….

For Example:Consider f(x)=(1+x2)-1 evaluated at 9 points in [-5,5]And corresponding p8(x) Lagrange Interpolating Polynomial

P8(x)f(x)

Splines

Splines

Piecewise smooth polynomials

tscoefficien n3

E.G Quadratic Splines

• Function Values at adjacent polynomials are equal at interior nodes

11112

11 iiiiii xfcxbxa

112

1 iiiiii xfcxbxa

ni 2

conditions )1(2 n

E.G Quadratic Splines• First and Last Functions pass through end

points

011201 xfcxbxa i

nnnnnn xfcxbxa 2

conditions )1(2 n

conditions 2

conditions 2n

ni 2

E.G Quadratic Splines• First Derivatives at Interior nodes are equal

baxxf 20

ni 2

conditions )1(2 n

conditions 2

conditions 13 n

iii

iii

bxa

bxa

1

111

2

2

conditions 1-n

E.G Quadratic Splines• Assume Second Derivative @ First Point=0

02 10 axf

conditions )1(2 n

conditions 2

conditions 3n

conditions 1-nconditions 1

E.G Quadratic Splines• Assume Second Derivative @ First Point=0

conditions 3n

tscoefficien edundetermin 3n

Solve 3nx3n system of Equations

baC

ix on based )( and

)( on based

xf

xf

Spline Interpolation

Polynomial InterpolationPolynomial Interpolation

Spline InterpolationSpline InterpolationPolynomial InterpolationPolynomial Interpolation

Polynomial InterpolationPolynomial Interpolation