Top Banner
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II
98

ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

ECIV 301

Programming & Graphics

Numerical Methods for Engineers

REVIEW II

Page 2: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Topics

• Introduction to Matrix Algebra• Gauss Elimination• LU Decomposition• Matrix Inversion• Iterative Methods

• Function Interpolation & Approximation• Newton Polynomials• Lagrange Polynomials

Page 3: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

Rectangular Array of Elements Represented by a single symbol [A]

Page 4: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

Row 1

Row 3

Column 2 Column m

n x m Matrix

Page 5: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

Matrix Algebra

32a

3rd Row

2nd Column

Page 6: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

m321 bbbbB

1 Row, m Columns

Row Vector

B

Page 7: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

n

3

2

1

c

c

c

c

C

n Rows, 1 Column

Column Vector

C

Page 8: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

5554535251

4544434241

3534333231

2524232221

1514131211

aaaaa

aaaaa

aaaaa

aaaaa

aaaaa

A

If n = m Square Matrix

e.g. n=m=5e.g. n=m=5Main Diagonal

Page 9: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

9264

2732

6381

4215

A

Special Types of Square Matrices

Symmetric: aSymmetric: aijij = a = ajiji

Page 10: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

9000

0700

0080

0005

A

Diagonal: aDiagonal: aijij = 0, i = 0, ijj

Special Types of Square Matrices

Page 11: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Algebra

1000

0100

0010

0001

I

Identity: aIdentity: aiiii=1.0 a=1.0 aijij = 0, i = 0, ijj

Special Types of Square Matrices

Page 12: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

nm

m333

m22322

m1131211

a000

aa00

aaa0

aaaa

A

Matrix Algebra

Upper TriangularUpper Triangular

Special Types of Square Matrices

Page 13: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

nm3n2n1n

333231

2221

11

aaaa

0aaa

00aa

000a

A

Matrix Algebra

Lower TriangularLower Triangular

Special Types of Square Matrices

Page 14: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

nm

3332

232221

1211

a000

0aa0

0aaa

00aa

A

Matrix Algebra

BandedBanded

Special Types of Square Matrices

Page 15: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Operating Rules - Equality

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

pq3p2p1p

q3333231

q2232221

q1131211

bbbb

bbab

bbbb

bbbb

B

[A]mxn=[B]pxq

n=p m=q aij=bij

Page 16: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Operating Rules - Addition

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

pq3p2p1p

q3333231

q2232221

q1131211

bbbb

bbab

bbbb

bbbb

B

[C]mxn= [A]mxn+[B]pxq

n=p

m=qcij = aij+bij

Page 17: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Operating Rules - Addition

Properties

[A]+[B] = [B]+[A]

[A]+([B]+[C]) = ([A]+[B])+[C]

Page 18: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Multiplication by Scalar

nm3n2n1n

m3333231

m2232221

m1131211

gagagaga

gagagaga

gagagaga

gagagaga

AgD

Page 19: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Multiplication

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

pq3p2p1p

q3333231

q2232221

q1131211

bbbb

bbab

bbbb

bbbb

B

[A] n x m . [B] p x q = [C] n x q

m=p

n

1kkjikij bac

Page 20: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Multiplication

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

pq3p2p1p

q3333231

q2232221

q1131211

bbbb

bbab

bbbb

bbbb

B

1nn13113

2112111111

baba

babac

11c

C

Page 21: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

Matrix Multiplication

pq3p2p1p

q3333231

q2232221

q1131211

bbbb

bbab

bbbb

bbbb

B

3nn23323

2322132123

baba

babac

23c

C

Page 22: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Multiplication - Properties

Associative: [A]([B][C]) = ([A][B])[C]

If dimensions suitable

Distributive: [A]([B]+[C]) = [A][B]+[A] [C]

Attention: [A][B] [B][A]

Page 23: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

nmm3m2m1

3n332313

2n322212

1n312111

T

aaaa

aaaa

aaaa

aaaa

A

nm3n2n1n

m3333231

m2232221

m1131211

aaaa

aaaa

aaaa

aaaa

A

Operations - Transpose

Page 24: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Operations - Inverse

[A] [A]-1

[A] [A]-1=[I]

If [A]-1 does not exist[A] is singular

Page 25: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Operations - Trace

5554535251

4544434241

3534333231

2524232221

1514131211

aaaaa

aaaaa

aaaaa

aaaaa

aaaaa

A

Square Matrix

tr[A] = tr[A] = aaiiii

Page 26: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Linear Equations in Matrix Form

10z8y3x5

6z3yx12

24z23y6x10

Page 27: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

23610

3112

835

z

y

x

24

6

10 6

z

y

x

3112

24

z

y

x

23610

10

z

y

x

835

Page 28: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss EliminationConsider

1035 yx(Eq 1)

5810 yx(Eq 2)

Solution

5.7

5.6

y

x

20610 yx2*(Eq 1)

5810 yx(Eq 2)

Solution

5.7

5.6

y

x!!!!!!

Scaling Does Not Change the SolutionScaling Does Not Change the Solution

Page 29: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss EliminationConsider

20610 yx(Eq 1)

152 y(Eq 2)-(Eq 1)

Solution

5.7

5.6

y

x!!!!!!

20610 yx(Eq 1)

5810 yx(Eq 2)

Solution

5.7

5.6

y

x

Operations Do Not Change the SolutionOperations Do Not Change the Solution

Page 30: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

10835 zyx

2423610 zyx

6312 zyx

Example

Forward Elimination

Page 31: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

10835 zyx

24z23y6x10

zyx 835

5

1210

5

12

6312 zyx

-

305

81

5

310 zyx 302.162.60 zyx

Page 32: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

10835 zyx

24z23y6x10

6312 zyx 302.162.60 zyx

Substitute 2nd eq with new

Page 33: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

10835 zyx

24z23y6x10

302.162.60 zyx

zyx 835

5

1010

5

10-

439120 zyx

Page 34: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

10835 zyx

24z23y6x10

302.162.60 zyx

Substitute 3rd eq with new

439120 zyx

Page 35: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

10835 zyx

302.162.60 zyx

439120 zyx

zy 2.162.6

2.6

12 30

2.6

12-

064.62645.700 zyx

Page 36: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

10835 zyx

30970 zyx

Substitute 3rd eq with new

439120 zyx 064.62645.700 zyx

Page 37: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

Forward Elimination

064.62

30

10

645.700

2.162.60

835

z

y

x

Page 38: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination

Back Substitution

118.8645.7/064.62 z

0502.26

2.6

118.82.1630

y

6413.0

5

118.880502.26310

x

064.62

30

10

645.700

2.162.60

835

z

y

x

Page 39: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Elimination – Potential Problem

10830 zyx

2423610 zyx

6312 zyx

Pivoting

6312 zyx

10830 zyx

Page 40: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Partial Pivoting

nn

nnnnn

lll

n

n

n

b

b

b

b

x

x

x

x

aaaa

aaaa

aaaaaaaa

aaaa

3

2

1

3

2

1

321

ln321

3333231

2232221

1131211

a32>a22

al2>a22

NO

YES

Page 41: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Partial Pivoting

nn

nnnnn

n

n

lll

n

b

b

b

b

x

x

x

x

aaaa

aaaa

aaaaaaaa

aaaa

3

2

1

3

2

1

321

2232221

3333231

ln321

1131211

Page 42: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Full Pivoting

• In addition to row swaping

• Search columns for max elements

• Swap Columns

• Change the order of xi

• Most cases not necessary

Page 43: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU Decomposition

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

2

1

x

x

x

Page 44: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU DecompositionPIVOTS

Column 1PIVOTS

Column 2

03333.0

1.0 02713.0

Page 45: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU Decomposition

As many as, and in the location of, zeros

UpperTriangular

MatrixU

01200.1000

29333.000333.70

2.01.03

Page 46: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU DecompositionPIVOTS

Column 1

PIVOTSColumn 2

LowerTriangular

Matrix

1

1

1

0

0

0

L

03333.0

1.0 02713.0

Page 47: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU Decomposition

102713.01.0

0103333.0

001

=

This is the original matrix!!!!!!!!!!

01200.1000

29333.000333.70

2.01.03

102.03.0

3.071.0

2.01.03

Page 48: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU Decomposition

4.71

3.19

85.7

102713.01.0

0103333.0

001

3

2

1

y

y

y

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

2

1

x

x

x

L y b

Page 49: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU Decomposition

4.71

3.19

85.7

102713.01.0

0103333.0

001

3

2

1

y

y

y

L y b

85.71 y

5617.190333.03.19 12 yy

0843.70)02713.0(1.04.71 213 yyy

Page 50: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU Decomposition85.71 y

5617.190333.03.19 12 yy

0843.70)02713.0(1.04.71 213 yyy

0843.70

5617.19

85.7

01200.1000

29333.000333.70

2.01.03

Page 51: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

LU Decomposition

• Ax=b

• A=LU - LU Decomposition

• Ly=b- Solve for y

• Ux=y - Solve for x

Page 52: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Inversion

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

2

1

x

x

x

bxA

Page 53: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Inversion

[A] [A]-1

[A] [A]-1=[I]

If [A]-1 does not exist[A] is singular

Page 54: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Inversion

b xA bxA 1A 1A

I

Page 55: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Inversion

bAx 1

Solution

Page 56: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Matrix Inversion

• To calculate the invert of a nxn matrix solve n times :

nj

2j

1j

nj

2j

1j

nnn2n1

2n2221

1n1211

a

a

a

aaa

aaa

aaa

nj ,,2,1

otherwise

ji if

0

1ij

Page 57: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Iterative Methods

Recall Techniques for Root finding of Single Equations

Initial Guess

New Estimate

Error Calculation

Repeat until Convergence

Page 58: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Seidel

3

2

1

3

2

1

333231

232221

131211

b

b

b

x

x

x

aaa

aaa

aaa

11

31321211 a

xaxabx

22

32312122 a

xaxabx

33

23213133 a

xaxabx

Page 59: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Seidel

11

1

11

1312111

00

a

b

a

aabx

22

23112121

2

0

a

axabx

33

1232

113131

3 a

xaxabx

First Iteration: 0,0,0 321 xxx

Better Estimate

Better Estimate

Better Estimate

Page 60: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss Seidel

11

1313

121212

1 a

xaxabx

22

1323

212122

2 a

xaxabx

33

2232

213132

3 a

xaxabx

Second Iteration: 13

12

11 ,, xxx

Better Estimate

Better Estimate

Better Estimate

Page 61: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Gauss SeidelIteration Error:

%1001

, ji

ji

ji

ia x

xx

s

Convergence Criterion:

n

jij

ijii aa1

nnn2n1

2n2221

1n1211

aaa

aaa

aaa

Page 62: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Jacobi Iteration

3

2

1

3

2

1

333231

232221

131211

b

b

b

x

x

x

aaa

aaa

aaa

11

31321211 a

xaxabx

22

32312122 a

xaxabx

33

23213133 a

xaxabx

Page 63: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Jacobi Iteration

11

1

11

1312111

00

a

b

a

aabx

22

2321212

00

a

aabx

33

3231313

00

a

aabx

First Iteration: 0,0,0 321 xxx

Better Estimate

Better Estimate

Better Estimate

Page 64: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Jacobi Iteration

11

1313

121212

1 a

xaxabx

22

1323

112122

2 a

xaxabx

33

1232

113132

3 a

xaxabx

Second Iteration: 13

12

11 ,, xxx

Better Estimate

Better Estimate

Better Estimate

Page 65: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Jacobi Iteration

Iteration Error:

%1001

, ji

ji

ji

ia x

xx

s

Page 66: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Determinants

nnn2n1

2n2221

1n1211

aaa

aaa

aaa

A

nnn2n1

2n2221

1n1211

aaa

aaa

aaa

det

AA

Are composed of same elements

Completely Different Mathematical Concept

Page 67: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Determinants

2221

1211

aa

aaA

Defined in a recursive form

2x2 matrix

122122112221

1211det aaaaaa

aaA

Page 68: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

DeterminantsDefined in a recursive form

3x3 matrix

3231

222113

3331

232112

3332

232211

det

aa

aaa

aa

aaa

aa

aaa

A

333231

232221

131211

aaa

aaa

aaa

Page 69: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

333231

232221

131211

aaa

aaa

aaa

Determinants

3332

232211 aa

aaa

3231

222113

3331

232112 aa

aaa

aa

aaa

3332

2322

aa

aaMinor a11

Page 70: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

333231

232221

131211

aaa

aaa

aaa

Determinants

3331

2321

aa

aaMinor a12

3332

232211 aa

aaa

3331

232112 aa

aaa

3231

222113 aa

aaa

Page 71: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

333231

232221

131211

aaa

aaa

aaa

Determinants

3231

2221

aa

aaMinor a13

3332

232211 aa

aaa

3331

232112 aa

aaa

3231

222113 aa

aaa

Page 72: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Singular Matrices

3

2

1

3

2

1

333231

232221

131211

b

b

b

x

x

x

aaa

aaa

aaa

If det[A]=0 solution does NOT exist

Page 73: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Determinants and LU Decomposition

nnaaaaD 332211det U

33

2322

131211

00

0

a

aa

aaa

)operations pivoting no (if detdet UA D

Page 74: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Curve Fitting

Often we are faced with the problem…

x y0.924 -0.003880.928 -0.00743

0.93283 0.005690.93875 0.00188

0.94 0.01278

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

what value of y corresponds to x=0.935?

Page 75: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

Curve Fitting

Question 1: Is it possible to find a simple and convenient formula that reproduces the points exactly?

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

e.g. Straight Line ?

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

…or smooth line ?

…or some other representation?

Interpolation

Page 76: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Curve FittingQuestion 2: Is it possible to find a simple and convenient formula that represents data approximately ?

-0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

e.g. Best Fit ?

Approximation

Page 77: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Linear Interpolation

iii

iii xx

xx

xfxfxfxf

1

11

Slope of Line

1st DIVIDED DIFFERENCEf [xi+1,xi]

First order interpolating polynomial

ii

ii

i

ii

xx

xfxf

xx

xfxf

1

11

Page 78: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Function Interpolation

Quadratic Interpolation

Better Accuracy if

2nd Order Polynomial -0.01

-0.005

0

0.005

0.01

0.015

0.92 0.925 0.93 0.935 0.94 0.945

x

12102 iii xxxxbxxbbxf

Page 79: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

General Form of Newton’s Interpolating Polynomials

011 , xxfb

00 xfb

0122 ,, xxxfb

110

212

01

0

nn

n

xxxxxxb

xxxxb

xxb

b

xf

110 ,, nn xxxfb

Page 80: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

)(

Page 81: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

Page 82: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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)

Page 83: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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)

Page 84: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Other Methods

nn xaxaxaaoxf 2

21)(

Direct Evaluation

n+1 coefficients

n321

n321

y y y yy f(x)

x x x xx

n+1 Data Points

Interpolating Polynomial should represent them exactly

Page 85: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Other Methods

nn xaxaxaaoxf 2

21)(

Direct Evaluation

n321

n321

y y y yy f(x)

x x x xx

nn xaxaxaaoy 1

212111

nn xaxaxaaoy 2

222212

nnnnnn xaxaxaaoy 2

21

Page 86: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

Page 87: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Other Methods

•Not the most efficient method

•Ill-conditioned matrix (nearly singular)

•If n is large highly inaccurate coefficients

•Limit to lower order polynomials

Page 88: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

X=?X=?

Page 89: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

X=?X=?

Switch x and y and then interpolate?

Not a Good Idea!

Page 90: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Splines

Page 91: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Splines

Piecewise smooth polynomials

Page 92: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

tscoefficien n3

Page 93: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

Page 94: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

Page 95: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

Page 96: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

Page 97: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

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

Page 98: ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.

Spline Interpolation

Polynomial InterpolationPolynomial Interpolation

Spline InterpolationSpline InterpolationPolynomial InterpolationPolynomial Interpolation

Polynomial InterpolationPolynomial Interpolation