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

Download Report

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

Chapter 5

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

Outline

    Introduction   Curve Fitting?

Interpolation?

Engineering applications   Collocation-Polynomial fit Interpolation  Measurement of damping in a fluid Measurement of the dependence of air resistance on velocity in a wind tunnel experiment (1) Lagrange interpolation formula Dr. Jie Zou PHY 3320 2

Introduction

Figure 5.1 Collocation-Fitting polynomials Dr. Jie Zou PHY 3320    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) (2)

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

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

3

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. (1) (2) Different forms of Polynomial interpolation Lagrange interpolation-Lecture (I) Newton forward or backward interpolation-Lecture (II) Dr. Jie Zou PHY 3320 4

Engineering applications

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

Dr. Jie Zou PHY 3320 5

Available Data Points

t (s) 0.0

1.5

 (deg) 110.0 77.5

3.7

44.7

5.2

31.5

7.1

20.1

9.6

11.6

11.8

7.0

  Assuming an exponential function to fit the data:  (

t

) =

a e bt

.

Determine technique.

a

and

b

use certain curve fitting 6 Dr. Jie Zou PHY 3320

Engineering applications (cont.)

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

Dr. Jie Zou PHY 3320 7

Available Data Points

v (m/s) 10 F (N) 25 20 70 30 380 40 550 50 610 60 70 1220 830 80 1450   Assuming a polynomial quadratic fit:

F u c d v

2 .

= Determine c technique d use certain curve fitting 8 Dr. Jie Zou PHY 3320

Collocation-Polynomial Fit

             1 1 1 Available data points: (x i ,y i ), i=0,1,2,  ,n.

Consider a polynomial of order n:

f(x)=y=a 0 +a 1 x+a 2 x 2 +

+a n-1 x n-1 +a

The matrix form: [B]a=y, where

n x n

.

Let the polynomial passes through all the points (x system of (n+1) linear algebraic equations; (n+1) unknown coefficients a 0 , a 1 ,  ,a n : y i =a 0 +a 1 x i +a 2 x i 2 +  +a n-1 x i n-1 +a n x i n , i=0,1,2,  ,n.

i ,y i ); a 

x

0

x

1

x

0 2

x

1 2 

x

0 3

x

1 3    

x

0

n x

1

n x x

2

x

3 

n n n

Dr. Jie Zou PHY 3320

x n n

        ,

a

      

a a a

1 

n

0       ,

y

      

y

0

y

1

y n

       We can use Gauss Elimination to solve for

a i

’s.

9

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.

Dr. Jie Zou PHY 3320 10

Interpolation-(1) Lagrange Interpolation Formula

  Example: Three data points (x i , y i ), i=0,1,2.

Basic idea:  Express the polynomial in an alternative way

f(x)=y=a 0 (x-x 1 )(x-x 2 ) +a 1 (x-x 0 )(x-x 2 ) +a 2 (x-x 0 )(x-x 1 )

y 0

Set f(x i ) = y i , we have

=a 0 (x 0 -x 1 )(x 0 -x 2 ), y 1 =a 1 (x 1 -x 0 )(x 1 -x 2 ),

and

y 2

= a 2 (x 2 -x 0 )(x 2 -x 1 )

Easy Solution for

a i

,

i

=0,1,2 (see next slide). Dr. Jie Zou PHY 3320 11

Lagrange Interpolation Formula (cont.)

a

0  

x

0 

x

1

y

 0

x

0 

x

2  ,

a

1  

x

1 

x

0

y

1 

x

1 

x

2  ,

a

2  

x

2 

x

0

y

 2

x

2 

x

1  In general,

f a i

j

 0

n

  ,

j

x i i y i

x j

 ,

i

 0 , 1 , 

n

, and 

y

i n

0

a i j

0

n

     ,

j

x i

x j

 Dr. Jie Zou PHY 3320 12

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.

Dr. Jie Zou PHY 3320 13