Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

13
Dr. Jie Zou PHY 3320 1 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Transcript of Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Page 1: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

1

Chapter 5

Curve Fitting and Interpolation: Lecture (I)

Page 2: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

2

Outline Introduction

Curve Fitting? Interpolation?

Engineering applications Measurement of damping in a fluid Measurement of the dependence of air

resistance on velocity in a wind tunnel experiment

Collocation-Polynomial fit Interpolation

(1) Lagrange interpolation formula

Page 3: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

3

Introduction Curve fitting? – To fit a

smooth and continuous function (curve) to the available discrete data.

A familiar example: In the Free-fall lab in General Physics I, you are asked to fit a function (quadratic) to the data of position v.s. time.

Two approaches:(1) Collocation: The approximating

function passes through all the data points. Usually used when the data are known to be accurate.

(2) Least-square regression: The approximating curve represents the general trend of the data. Usually used when the data appear to have significant error.

Figure 5.1 Collocation-Fitting polynomials

Page 4: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

4

Introduction (cont.) Interpolation? – The process of

estimating an intermediate value from a set of discrete (or tabulated) values.

The collocation function is often called an interpolating function.

Polynomial interpolation is most commonly used. Others: trigonometric or exponential function.

Different forms of Polynomial interpolation(1) Lagrange interpolation-Lecture (I)(2) Newton forward or backward interpolation-Lecture

(II)

Page 5: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

5

Engineering applications

Example 5.1: An experiment to measure the damping of a solid body in a fluid.

Page 6: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

6

Available Data Points

Assuming an exponential function to fit the data: (t) = a ebt.

Determine a and b use certain curve fitting technique.

t (s) 0.0 1.5 3.7 5.2 7.1 9.6 11.8

(deg)

110.0

77.5 44.7 31.5 20.1 11.6 7.0

Page 7: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

7

Engineering applications (cont.)

Wind tunnel experiment to measure how the force of air resistance depends on velocity.

Page 8: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

8

Available Data Points

Assuming a polynomial quadratic fit: Fu = cdv2.

Determine cd use certain curve fitting technique

v (m/s)

10 20 30 40 50 60 70 80

F (N) 25 70 380 550 610 1220

830 1450

Page 9: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

9

Collocation-Polynomial Fit Available data points: (xi,yi), i=0,1,2, ,n. Consider a polynomial of order n: f(x)=y=a0+a1x+a2x2++an-1xn-1+anxn. Let the polynomial passes through all the points

(xi,yi); a system of (n+1) linear algebraic equations; (n+1) unknown coefficients a0, a1, ,an:yi=a0+a1xi+a2xi

2++an-1xin-1+anxi

n, i=0,1,2, ,n. The matrix form: [B]a=y, where

nnnnnnn

n

n

y

y

y

a

a

a

xxxx

xxxx

xxxx

B

1

0

1

0

32

131

211

030

200

, ,

1

1

1

yaWe can use Gauss Elimination to solve for ai’s.

Page 10: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

10

Example 5.4 The data on the voltage e (V) v.s. time t

(s) in an circuit are given by the following: t = 0, 0.005 s, and 0.01 s; e = 0, 110 V, and 0 V.

Choose a polynomial to exactly fit the data. (1) Find the coefficients using MATLAB built-in

functions (code) (2) Find the coefficients using Gauss

Elimination (Code) (3) Plot both the discrete data points and the

polynomial fitting function on the same graph. (4) Check if the fitting curve pass through all

the date points.

Page 11: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

11

Interpolation-(1) Lagrange Interpolation Formula

Example: Three data points (xi, yi), i=0,1,2.

Basic idea: Express the polynomial in an alternative way

f(x)=y=a0(x-x1)(x-x2) +a1(x-x0)(x-x2) +a2(x-x0)(x-x1)

Set f(xi) = yi, we have

y0 =a0(x0-x1)(x0-x2), y1=a1(x1-x0)(x1-x2), and

y2 = a2(x2-x0)(x2-x1)

Easy Solution for ai, i=0,1,2 (see next slide).

Page 12: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

12

Lagrange Interpolation Formula (cont.)

n

i

n

ijjji

n

ijjji

ii

xxayxf

nixx

ya

xxxx

ya

xxxx

ya

xxxx

ya

0 ,0

,0

1202

22

2101

11

2010

00

and ,,1,0 ,

general,In

, ,

Page 13: Dr. Jie Zou PHY 33201 Chapter 5 Curve Fitting and Interpolation: Lecture (I)

Dr. Jie Zou PHY 3320

13

Example 5.5 (a) Develop a Lagrange interpolation

polynomial that passes through the points (0,0), (0.005,110), and (0.01,0). (b) Evaluate the function at an intermediate point x = 0.0025 or 2.5x10-3. (1) By hand. (2) Write an M-file MyLagrange.m. A

copy of the code will be handed out later.