curve fitting student notes

119
CURVE FITTING Student Notes ENGR 351 Numerical Methods for Engineers Southern Illinois University Carbondale College of Engineering Instructor: L.R. Chevalier, Ph.D., P.E.

Upload: ludwig

Post on 24-Feb-2016

79 views

Category:

Documents


1 download

DESCRIPTION

CURVE FITTING Student Notes. ENGR 351 Numerical Methods for Engineers Southern Illinois University Carbondale College of Engineering Instructor: L.R . Chevalier, Ph.D., P.E. Applications. Need to determine parameters for saturation-growth rate model to characterize microbial kinetics. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CURVE  FITTING Student Notes

CURVE FITTINGStudent NotesENGR 351 Numerical Methods for EngineersSouthern Illinois University CarbondaleCollege of EngineeringInstructor: L.R. Chevalier, Ph.D., P.E.

Page 2: CURVE  FITTING Student Notes
Page 3: CURVE  FITTING Student Notes

Applications

Food Available, S

Spec

ific

Grow

th R

ate,

m

Need to determine parameters for saturation-growth rate model to characterize microbial kinetics

SKS

s maxmm

Page 4: CURVE  FITTING Student Notes

Applications

0

5

10

15

20

25

30

0 10 20 30

T (o C)

z (m

)

Epilimnion

Thermocline

Hypolimnion

Page 5: CURVE  FITTING Student Notes

0

0.5

1

1.5

2

0 10 20 30

T(oC)

v, 1

0-2 c

m2 /s

Applications

Interpolation of dataWhat is kinematic viscosity at 7.5º C?T (oC) v, 10-2 (cm2/s)

0 1.79234 1.56158 1.387412 1.239616 1.116820 1.010524 0.9186

Page 6: CURVE  FITTING Student Notes

We want to find the best “fit” of a curve through the data.Here we see :

a) Least squares fit b) Linear interpolation

Can you suggest another?

f(x)

x

Page 7: CURVE  FITTING Student Notes

Material to be Covered in Curve Fitting Linear Regression

Polynomial Regression Multiple Regression General linear least squares Nonlinear regression

Interpolation Lagrange polynomial Coefficients of polynomials (Collocation-

Polynomial Fit) Splines

Page 8: CURVE  FITTING Student Notes

Specific Study Objectives Understand the fundamental difference

between regression and interpolation and realize why confusing the two could lead to serious problems Understand the derivation of linear least

squares regression and be able to assess the reliability of the fit using graphical and quantitative assessments.

Page 9: CURVE  FITTING Student Notes

Specific Study Objectives Know how to linearize data by

transformation Understand situations where

polynomial, multiple and nonlinear regression are appropriate Understand the general matrix

formulation of linear least squares Understand that there is one and only

one polynomial of degree n or less that passes exactly through n+1 points

Page 10: CURVE  FITTING Student Notes

Specific Study Objectives Realize that more accurate results are

obtained if data used for interpolation is centered around and close to the unknown point Recognize the liabilities and risks

associated with extrapolation Understand why spline functions have

utility for data with local areas of abrupt change

Page 11: CURVE  FITTING Student Notes

Least Squares Regression Simplest is fitting a straight line to a set

of paired observations (x1,y1), (x2, y2).....(xn, yn)

The resulting mathematical expression is y = ao + a1x + e

We will consider the error introduced at each data point to develop a strategy for determining the “best fit” equations

Page 12: CURVE  FITTING Student Notes

xaya

xxn

yxyxna

o

ii

iiii

1

221

Let’s consider where this comes from.

Determining the Coefficients

x y0 91 72 53 44 35 16 0

012345678910

0 2 4 6 8

x

f(x)

Page 13: CURVE  FITTING Student Notes

S e y a a xri

n

i o ii

n

i

2

11

1

2

f(x)

x

Sum of the Residual Error, Sr

Page 14: CURVE  FITTING Student Notes

S e y a a xri

n

i o ii

n

i

2

11

1

2

f(x)

x

Sum of the Residual Error, Sr

Note:In this equation yi is the raw data point (dependent data) associated with xi (independent data)

Page 15: CURVE  FITTING Student Notes

S e y a a xri

n

i o ii

n

i

2

11

1

2

f(x)

x

Sum of the Residual Error, Sr

A line that models this data is:

y = ao + a1x

Page 16: CURVE  FITTING Student Notes

S e y a a xri

n

i o ii

n

i

2

11

1

2

f(x)

x

Sum of the Residual Error, Sr

Page 17: CURVE  FITTING Student Notes

S e y a a xri

n

i o ii

n

i

2

11

1

2

f(x)

x

y a a xi o i 1

Sum of the Residual Error, Sr

Page 18: CURVE  FITTING Student Notes

To determine the values for ao and a1, differentiatewith respect to each coefficient

Sa

y a a x

Sa

y a a x x

r

oi o i

ri o i i

2

2

1

11

Note: we have simplified the summation symbols.What mathematics technique will minimize Sr?

Determining the Coefficients

Page 19: CURVE  FITTING Student Notes

Sa

y a a x

Sa

y a a x x

r

oi o i

ri o i i

2

2

1

11

Setting the derivative equal to zero will minimizing Sr.If this is done, the equations can be expressed as:

0

01

12

y a a x

y x a x a xi o i

i i o i i

Determining the Coefficients

Page 20: CURVE  FITTING Student Notes

0

01

12

y a a x

y x a x a xi o i

i i o i i

Note:

We have two simultaneous equations, with two unknowns, ao and a1.

What are these equations? (hint: only place terms with ao and a1 on the LHS of the equations)

What are the final equations for ao and a1?

a nao o

Determining the Coefficients

Page 21: CURVE  FITTING Student Notes

na x a y

x a x a x y

an x y x y

n x x

a y a x

o i i

i o i i i

i i i i

i i

o

1

21

1 2 2

1

These first twoequations are calledthe normal equations

Determining the Coefficients

Page 22: CURVE  FITTING Student Notes

ExampleDetermine the linear equation for the following datax y0 91 72 53 44 35 16 0

012345678910

0 2 4 6 8

x

f(x)

Strategy

Page 23: CURVE  FITTING Student Notes

StrategySet up a table

x y xy x2

Sx Sy Sxy Sx2

From these values determine the average values of x and y (x- and y-bar)Calculate a0 and a1

Page 24: CURVE  FITTING Student Notes

Error f(x)

x

1

2

nSs

yyS

ty

it

The most common measure of the “spread” of a sample is the standard deviation about the mean:

Page 25: CURVE  FITTING Student Notes

Coefficient of determination r2:

rS S

St r

t

2

r is the correlation coefficient

Error

Page 26: CURVE  FITTING Student Notes

rS S

St r

t

2

The following signifies that the line explains 100 percent of the variability of the data:

Sr = 0 r = r2 = 1

If r = r2 = 0, then Sr = St and the fit is invalid.

Error

Page 27: CURVE  FITTING Student Notes

ExampleDetermine the R2 value for the following datax y0 91 72 53 44 35 16 0

012345678910

0 2 4 6 8

x

f(x)

Strategy

Page 28: CURVE  FITTING Student Notes

StrategyComplete table

x y xy x2 ymodel e2 (y-yavg)2

Sx Sy Sxy Sx2 SSr SSt

Calculate Sr, StDetermine R2

Page 29: CURVE  FITTING Student Notes

Data 1 Data 2 Data 3 Data 410 8.04 10 9.14 10 7.46 8 6.588 6.95 8 8.14 8 6.77 8 5.7613 7.58 13 8.74 13 12.74 8 7.719 8.81 9 8.77 9 7.11 8 8.8411 8.33 11 9.26 11 7.81 8 8.4714 9.96 14 8.10 14 8.84 8 7.046 7.24 6 6.13 6 6.08 8 5.254 4.26 4 3.10 4 5.39 19 12.5012 10.84 12 9.13 12 8.15 8 5.567 4.82 7 7.26 7 6.42 8 7.915 5.68 5 4.74 5 5.73 8 6.89

Consider the following four sets of data

Page 30: CURVE  FITTING Student Notes

y = 0.5001x + 3.0001R2 = 0.6665

0

2

4

6

8

10

12

14

0 5 10 15

x

y

y = 0.5x + 3.0009R2 = 0.6662

0

2

4

6

8

10

12

14

0 5 10 15

x

y

y = 0.4999x + 3.0017R2 = 0.6667

0

2

4

6

8

10

12

14

0 5 10 15 20

x

y

y = 0.4997x + 3.0025R2 = 0.6663

0

2

4

6

8

10

12

14

0 5 10 15

x

y

Com

mon

Sen

se!!!

!

Page 31: CURVE  FITTING Student Notes

Linearization of non-linear relationships

Some data is simply ill-suited for linear least squares regression....

or so it appears.

f(x)

x

Page 32: CURVE  FITTING Student Notes

P

tln P

t

slope = r

intercept = ln P0

P P eort

Linea

rize

why?

EXPONENTIALEQUATIONS

Page 33: CURVE  FITTING Student Notes

P P e

P P e

P e

P rt

rt

rt

rt

0

0

0

0

ln ln

ln ln

ln

slope = rintercept = ln Po

Can you see the similaritywith the equation for a line:

y = ao + a1x

lnP

t

Page 34: CURVE  FITTING Student Notes

P P e

P P e

P e

P rt

rt

rt

rt

0

0

0

0

ln ln

ln ln

ln

ln P

t

slope = rintercept = ln P0

After taking the natural logof the y-data, perform linearregression.From this regression:

The value of ao will give usln (P0). Hence, P0 = eao

The value of a1 will give us rdirectly.

Page 35: CURVE  FITTING Student Notes

POWER EQUATIONS

log Q

log H

Q

H

acHQ

Here we linearizethe equation bytaking the log ofH and Q data.What is the resultingintercept and slope?

(Flow over a weir)

Page 36: CURVE  FITTING Student Notes

Q cH

Q cH

c Hc a H

a

a

a

log log

log loglog log

log Q

log H

slope = a

intercept = log c

Page 37: CURVE  FITTING Student Notes

So how do we getc and a fromperforming regressionon the log H vs log Qdata?From : y = ao + a1x

ao = log c

c = 10ao

a1 = a

log Q

log H

slope = a

intercept = log c

Q cH

Q cH

c Hc a H

a

a

a

log log

log loglog log

Page 38: CURVE  FITTING Student Notes

m

S1/m

1/ S

SATURATION-GROWTHRATE EQUATION

SKS

s maxmm

slope = Ks/mmax

intercept = 1/mmax

Here, m is the growth rate of a microbial population,mmax is the maximum growth rate, S is the substrate or food concentration, Ks is the substrate concentration at a value of m = mmax/2

Page 39: CURVE  FITTING Student Notes

ExampleGiven the data below, determine

the coefficients a and b for the equation y=axb

x y1 3.12 263 1104 250

0.5 1 1.5 2 2.5 3 3.5 4 4.50

50

100

150

200

250

300

Raw D...

x

y

Strategy

Page 40: CURVE  FITTING Student Notes

StrategyStart a table. For y=axb you need

a log-log table and graph.x y log x log y

Perform linear regression on the log-log dataBased on y = a0 + a1x, calculate log a = a0 therefore a = 10a0

b=a1

Page 41: CURVE  FITTING Student Notes

Residual ErrorLinear: y = ao + a1x

21

22ioimodelir xaayyyeS

Power: y = axb

222 b

imodelir iaxyyyeS

Exponential: y=aexb

222 bx

imodeliriaeyyyeS

Page 42: CURVE  FITTING Student Notes

ExampleX Y Ymodel

1 0.7 0.82 1.7 1.63 3.3 3.14 7.3 6.25 10.9 12.16 22.7 23.9

y = 0.407e 0.679x

Given the following results, determine Sr.Strategy

Page 43: CURVE  FITTING Student Notes

StrategyCalculate e2 = (yi – ymodel)2 for each

(x,y) pairDetermine Se2 = Sr

Page 44: CURVE  FITTING Student Notes

Demonstration with ExcelX Y1 0.72 1.73 3.34 7.35 10.96 22.7

0

5

10

15

20

25

0 2 4 6 8

x

y

See: 2012-L4-NonlinearRegressionExample.xlsx

Page 45: CURVE  FITTING Student Notes

General Comments of Linear RegressionYou should be cognizant of the fact

that there are theoretical aspects of regression that are of practical importance but are beyond the scope of this bookStatistical assumptions are

inherent in the linear least squares procedure

Page 46: CURVE  FITTING Student Notes

x has a fixed value; it is not random and is measured without errorThe y values are independent

random variable and all have the same varianceThe y values for a given x must be

normally distributed

General Comments of Linear Regression

Page 47: CURVE  FITTING Student Notes

The regression of y versus x is not the same as x versus yThe error of y versus x is not the

same as x versus y

General Comments of Linear Regression

Page 48: CURVE  FITTING Student Notes

The regression of y versus x is not the same as x versus yThe error of y versus x is not the

same as x versus yf(x)

x

y-di

rect

ion

x-direction

General Comments of Linear Regression

Page 49: CURVE  FITTING Student Notes

Polynomial Regression

One of the reasons you were presented with the theory behind linear regression was to allow you the insight behind similar procedures for higher order polynomials y = a0 + a1xmth - degree polynomial

y = a0 + a1x + a2x2 +....amxm + e

Page 50: CURVE  FITTING Student Notes

S y a a x a x a xr i o i i m im 1 2

2 2......

Based on the sum of the squares of the residuals

Polynomial Regression

Page 51: CURVE  FITTING Student Notes

S y a a x a x a xr i o i i m im 1 2

2 2......

1. Take the derivative of the above equation with respect to each of the unknown coefficients: i.e. the partial with respect to a2

Sa

x y a a x a x a xri i o i i m i

m

2

21 2

22 .....

Polynomial Regression

Page 52: CURVE  FITTING Student Notes

2. These equations are set to zero to minimize Sr, i.e. minimize the error.

3. Set all unknowns values on the LHS of the equation.

a x a x a x a x x yo i i i m im

i i2

13

24 2 2 .....

Polynomial Regression

Page 53: CURVE  FITTING Student Notes

4. This set of normal equations result in m+1 simultaneous equations which can be solved using matrix methods to determine a0, a1, a2......am

Polynomial Regression

Page 54: CURVE  FITTING Student Notes

i2i2

4i1

3io

2i

ii23i1

2ioi

i22i1io

yxaxaxax

yxaxaxax

yaxaxan

Polynomial Regression

Page 55: CURVE  FITTING Student Notes

Multiple Linear RegressionA useful extension of linear

regression is the case where y is a linear function of two or more variables y = ao + a1x1 + a2x2

We follow the same procedure y = ao + a1x1 + a2x2 + e

Page 56: CURVE  FITTING Student Notes

Multiple Linear Regression

For two variables, we would solve a 3 x 3 matrixin the following form:

n x xx x x xx x x x

aaa

yx yx y

i i

i i i i

i i i i

i

i i

i i

1 2

12

1 1 2

2 1 22

2

0

1

2

1

2

[A] and {c}are clearly based on data given for x1, x2 and y to solve for the unknowns in {x}.

Page 57: CURVE  FITTING Student Notes

InterpolationGeneral formula for an n-th order

polynomial y = a0 + a1x + a2x2 +....amxm

For m+1 data points, there is one, and only one polynomial of order m or less that passes through all pointsExample: y = a0 + a1x

fits between 2 points 1st order

Page 58: CURVE  FITTING Student Notes

Linear InterpolationTemperature, C Density, kg/ m3

0 999.95 1000.010 999.715 999.120 998.2

How would you approach estimating the density at 17 C?

Page 59: CURVE  FITTING Student Notes

???999.1 > r > 998.2r

T15 20

998.

2

999.

1

Temperature, C Density, kg/ m3

0 999.95 1000.010 999.715 999.120 998.2

Page 60: CURVE  FITTING Student Notes

Assume a straight line between the known data.Then calculate the slope.

T15201.9992.998r

r

T15 20

998.

2

999.

1

Page 61: CURVE  FITTING Student Notes

Assuming this linear relationship is constant,the slope is the same between the unknown point and a known point.

T15171.999r

r

r

T15 20

998.

2

999.

117

Page 62: CURVE  FITTING Student Notes

Therefore, the slope of one interval will equal the slope of the other interval.

T15171.999

15201.9992.998

r

r

Solve for r

r

T15 20

998.

2

999.

1

17

Page 63: CURVE  FITTING Student Notes

f x f xf x f x

x xx xo1

1 0

1 00

998 2 999 120 15

998 220 17

. . .

r

Alternate interpretation

0101 xxaaxf

the intercept is f(x0) the slope is a finite difference approx. of dy/dx

Page 64: CURVE  FITTING Student Notes

f(x)

x

true solution

smaller intervalsprovide a better estimate

12

Page 65: CURVE  FITTING Student Notes

f(x)

x

true solution1

2

Alternative approach would be to include a third point and estimate f(x) from a 2nd order polynomial.

Page 66: CURVE  FITTING Student Notes

f(x)

x

true solution

Alternative approach would be to include a third point and estimate f(x) from a 2nd order polynomial.

Page 67: CURVE  FITTING Student Notes

Lagrange Interpolating Polynomial

f x L x f x

L xx xx x

n i ii

n

ij

i jjj i

n

0

0

where P designates the “product of”The linear version of this expression is at n=1

Page 68: CURVE  FITTING Student Notes

f x L x f x

L xx xx x

f x xx x

f x x xx x

f x

n i ii

n

ij

i jjj i

n

0

0

11

0 10

0

1 01

Linear version: n=1

Your text shows you how to do n=2 (second order).What would third order be?

Page 69: CURVE  FITTING Student Notes

f x L x f x

L xx xx x

fx x x x x x

x x x x x xf x

n i ii

n

ij

i jjj i

n

0

0

31 2 3

0 1 0 2 0 30

.......

Note:x0 isnot being subtractedfrom the constantterm x

Page 70: CURVE  FITTING Student Notes

f x L x f x

L xx xx x

fx x x x x x

x x x x x xf x

n i ii

n

ij

i jjj i

n

0

0

31 2 3

0 1 0 2 0 30

.......

Note:x0 isnot being subtractedfrom the constantterm x or xi = x0 inthe numeratoror the denominatorj= 0

Page 71: CURVE  FITTING Student Notes

f x L x f x

L xx xx x

fx x x x x x

x x x x x xf x

x x x x x xx x x x x x

f x

n i ii

n

ij

i jjj i

n

0

0

31 2 3

0 1 0 2 0 30

0 2 3

1 0 1 2 1 31

.......

Page 72: CURVE  FITTING Student Notes

f x L x f x

L xx xx x

fx x x x x x

x x x x x xf x

x x x x x xx x x x x x

f x

n i ii

n

ij

i jjj i

n

0

0

31 2 3

0 1 0 2 0 30

0 2 3

1 0 1 2 1 31

.......

Note:x1 isnot being subtractedfrom the constantterm x or xi = x1 inthe numeratoror the denominatorj= 1

Page 73: CURVE  FITTING Student Notes

f x L x f x

L xx xx x

fx x x x x x

x x x x x xf x

x x x x x xx x x x x x

f x

x x x x x xx x x x x x

f x

n i ii

n

ij

i jjj i

n

0

0

31 2 3

0 1 0 2 0 30

0 2 3

1 0 1 2 1 31

0 1 3

2 0 2 1 2 32

......

Note:x2 isnot being subtractedfrom the constantterm x or xi = x2 inthe numeratoror the denominatorj= 2

Page 74: CURVE  FITTING Student Notes

f x L x f x

L xx xx x

fx x x x x x

x x x x x xf x

x x x x x xx x x x x x

f x

x x x x x xx x x x x x

f x

x x x x x xx x x x x x

f x

n i ii

n

ij

i jjj i

n

0

0

31 2 3

0 1 0 2 0 30

0 2 3

1 0 1 2 1 31

0 1 3

2 0 2 1 2 32

0 1 2

3 0 3 1 3 23

Note:x3 isnot being subtractedfrom the constantterm x or xi = x3 inthe numeratoror the denominatorj= 3

Page 75: CURVE  FITTING Student Notes

Example

Temperature, C Density, kg/ m3

0 999.95 1000.010 999.715 999.120 998.2

Determine the densityat 17o C using a 2nd order Lagrange Interpolating Polynomial

998

998.5

999

999.5

1000

1000.5

0 5 10 15 20 25

Temp

Dens

ity

Strategy

Page 76: CURVE  FITTING Student Notes

StrategyDetermine the number of data

points needed 2nd Order – 3 points 3rd Order – 4 points

Chose the data points for the formulaWrite out the formula without the

dataAdd the dataSolve

Page 77: CURVE  FITTING Student Notes

Coefficients of an Interpolating Polynomial

y = a0 + a1x + a2x2 +....amxm

HOW CAN WE BE MORE STRAIGHT FORWARD IN GETTING VALUES?

Page 78: CURVE  FITTING Student Notes

2

222102

2121101

2020100

xaxaaxf

xaxaaxf

xaxaaxf

This is a 2nd order polynomial.

We need three data points.

Plug the value of xi and f(xi)directly into equations.

This gives three simultaneous equationsto solve for a0 , a1 , and a2

Page 79: CURVE  FITTING Student Notes

ExampleDetermine the densityat 17o C using the method of “Coefficient of Interpolating Polynominals”. Base your solution on a 2nd order polynomial.

998

998.5

999

999.5

1000

1000.5

0 10 20 30

Temp

Dens

ity

Temperature, C Density, kg/ m3

0 999.95 1000.010 999.715 999.120 998.2

Strategy

Page 80: CURVE  FITTING Student Notes

Strategy Recognize that you are solving for a0, a1 and a2

for the formula y = a0 + a1x + a2x2

Determine the three points you need for the problem

Recognize that the x-value associate with a0 is x0 = 1

Set up the following matrix

3

2

1

2

1

0

233

222

211

111

yyy

aaa

xxxxxx

Page 81: CURVE  FITTING Student Notes

Spline InterpolationOur previous approach was to

derive an nth order polynomial for n+1 data points.An alternative approach is to apply

polynomials to subset of data pointsSuch connecting polynomials are

called spline functionsAdaptation of drafting techniques

Page 82: CURVE  FITTING Student Notes

Spline interpolation is an adaptation of the drafting technique of using a spline to draw smooth curvesthrough a series of points

Page 83: CURVE  FITTING Student Notes

Spline interpolation is an adaptation of the drafting technique of using a spline to draw smooth curvesthrough a series of points

Page 84: CURVE  FITTING Student Notes

Spline interpolation is an adaptation of the drafting technique of using a spline to draw smooth curvesthrough a series of points

Page 85: CURVE  FITTING Student Notes

Spline interpolation is an adaptation of the drafting technique of using a spline to draw smooth curvesthrough a series of points

Page 86: CURVE  FITTING Student Notes

Linear Splines

f x f x m x x x x xf x f x m x x x x x

f x f x m x x x x xwhere

mf x f x

x x

n n n n n

ii i

i i

0 0 0 0 1

1 1 1 1 2

1 1 1 1

1

1

Page 87: CURVE  FITTING Student Notes

112

1 cxbxa

Quadratic Spline

Page 88: CURVE  FITTING Student Notes

222

2 cxbxa

Quadratic Spline

Page 89: CURVE  FITTING Student Notes

332

3 cxbxa

Quadratic Spline

Page 90: CURVE  FITTING Student Notes

442

4 cxbxa

Quadratic Spline

Page 91: CURVE  FITTING Student Notes

112

1 cxbxa

222

2 cxbxa

332

3 cxbxa

442

4 cxbxa

Quadratic Spline

Page 92: CURVE  FITTING Student Notes

APPROACHSHOW EXAMPLE

PRESENT THEORY

Page 93: CURVE  FITTING Student Notes

ExampleA well pumping at 250 gallons per minute has observation wells located at 15, 42, 128, 317 and 433 ft away along a straight line from the well.After three hours of pumping, the following drawdowns in the five wells were observed: 14.6, 10.7, 4.8,1.7 and 0.3 ft respectively. Derive equations of each quadratic spline.

02468

10121416

0 100 200 300 400 500

Distance from well (ft)

Draw

dow

n (ft

)

Strategy

Page 94: CURVE  FITTING Student Notes

11

21

11112

11

iiiiii

iiiiii

xfcxbxa

xfcxbxa

15 14.642 10.7

128 4.8317 1.7433 0.3

02468

10121416

0 100 200 300 400 500

Distance from well (ft)Dr

awdo

wn

(ft)

Strategy Determine how many

segments and equations you have

Determine the two equations that go to each internal point

Determine the equation that goes to each end point

Determine the equations for the first derivatives at each internal point

Page 95: CURVE  FITTING Student Notes

What are the equations?

02468

10121416

0 100 200 300 400 500

Distance from well (ft)

Draw

dow

n (ft

)

a1x2 + b1x + c1 = ya2x2 + b2x + c2 = ya3x2 + b3x + c3 = y

a4x2 + b4x + c4 = y

Page 96: CURVE  FITTING Student Notes

02468

10121416

0 100 200 300 400 500

Distance from well (ft)

Draw

dow

n (ft

)

a x b x c f x

a x b x c f xi i i i i i

i i i i i i

1 1

21 1 1 1

12

1 1

(42)2 a1 + 42b1 + c1 = 10.7(42)2 a2 + 42 b2 + c2 = 10.7

15 14.642 10.7

128 4.8317 1.7433 0.3

Solution

Page 97: CURVE  FITTING Student Notes

02468

10121416

0 100 200 300 400 500

Distance from well (ft)

Draw

dow

n (ft

)

16,384a2 + 128b2 + c2 = 4.816,384 a3 + 128 b3 + c3 = 4.8

a x b x c f x

a x b x c f xi i i i i i

i i i i i i

1 1

21 1 1 1

12

1 1

15 14.642 10.7

128 4.8317 1.7433 0.3

Solution

Page 98: CURVE  FITTING Student Notes

02468

10121416

0 100 200 300 400 500

Distance from well (ft)

Draw

dow

n (ft

) 100,489a3 + 317b3 + c3 = 1.7100,489a4 + 317b4 + c4 = 1.7

a x b x c f x

a x b x c f xi i i i i i

i i i i i i

1 1

21 1 1 1

12

1 1

15 14.642 10.7

128 4.8317 1.7433 0.3

Solution

Page 99: CURVE  FITTING Student Notes

(15)2a1 + 15 b1 + c1 = 14.6 187,489a4 + 433b4 + c4 = 0.3Similarly,the equationsincludethe end points

02468

10121416

0 100 200 300 400 500

Distance from well (ft)

Draw

dow

n (ft

)

15 14.642 10.7

128 4.8317 1.7433 0.3

Solution

Page 100: CURVE  FITTING Student Notes

2 21 1 1 1a x b a x bi i i i i

The first derivative at the interior knots must be equal.

2a1 (42) + b1 = 2a2 (42) + b2

2a2 (128) + b2 = 2a3 (128) + b3

2a3 (317) + b3 = 2a4 (317) + b4

02468

10121416

0 100 200 300 400 500

Distance from well (ft)

Draw

dow

n (ft

)

15 14.642 10.7

128 4.8317 1.7433 0.3

Solution

Page 101: CURVE  FITTING Student Notes

Addition the last condition a1 = 0

You should be able to set these equations into a matrix to solve for ai , bi, and ci for i = 1,3

....end of problem

15 14.642 10.7

128 4.8317 1.7433 0.3

Solution

Page 102: CURVE  FITTING Student Notes

Splines To ensure that the mth derivatives are

continuous at the “knots”, a spline of at least m+1 order must be used 3rd order polynomials or cubic splines

that ensure continuous first and second derivatives are most frequently used in practice Although third and higher derivatives

may be discontinuous when using cubic splines, they usually cannot be detected visually and consequently are ignored.

Page 103: CURVE  FITTING Student Notes

Splines The derivation of cubic splines is

somewhat involved First illustrate the concepts of spline

interpolation using second order polynomials. These “quadratic splines” have

continuous first derivatives at the “knots” Note: This does not ensure equal

second derivatives at the “knots”

Page 104: CURVE  FITTING Student Notes

Quadratic Spline

1.The function must be equal at the interior knots. This condition can be represented as:

a x b x c f x

a x b x c f x

i i i i i i

i i i i i i

1 12

1 1 1 1

12

1 1

note: we are referencing the same x and f(x)

Page 105: CURVE  FITTING Student Notes

a x b x c f x

a x b x c f xi i i i i i

i i i i i i

1 1

21 1 1 1

12

1 1

This occurs between i = 2, n

Using the interior knots (n-1) this will provide2n -2 equations.

Quadratic Spline

Page 106: CURVE  FITTING Student Notes

2. The first and last functions must pass through the end points. This will add two more equations.

a x b x c f x

a x b x c f xn n n n n n

1 02

1 0 1 0

2

We now have 2n - 2 +2 = 2n equations.

How many do we need?

Quadratic Spline

Page 107: CURVE  FITTING Student Notes

3. The first derivative at the interior knots must be equal.

This provides another n-1 equations for 2n + n-1 =3n -1.

We need 3n

2 21 1 1 1a x b a x bi i i i i

Quadratic Spline

Page 108: CURVE  FITTING Student Notes

4. Unless we have some additional information regarding the functions or their derivatives, we must make an arbitrary choice in order to successfully compute the constants.5. Assume the second derivative is zero at the first point. The visual interpretation of this condition is that the first two points will be connected by a straight line. a1 = 0

Quadratic Spline

Page 109: CURVE  FITTING Student Notes

Cubic Splines

Third order polynomialNeed n+1 = 3+1 = 4 intervalsConsequently there are 4n

unknown constants to evaluateWhat are these equations?

f x a x b x c x di i i i i 3 2

Page 110: CURVE  FITTING Student Notes

Cubic Splines The function values must be equal at

the interior knots (2n -2) The first and last functions must pass

through the end points (2) The first derivatives at the interior knots

must be equal (n-1) The second derivatives at the interior

knots must be equal (n-1) The second derivative at the end knots

are zero (2)

Page 111: CURVE  FITTING Student Notes

Cubic Splines The function values must be equal at

the interior knots (2n -2) The first and last functions must pass

through the end points (2) The first derivatives at the interior knots

must be equal (n-1) The second derivatives at the interior

knots must be equal (n-1) The second derivative at the end knots

are zero (2)

Page 112: CURVE  FITTING Student Notes

Previous Exam QuestionGiven the following data, develop the simultaneous equations for a quadratic spline. Express your final answers in matrix form.

x f(x)1 0.504 4.606 1.507 3.00

0.00

1.00

2.00

3.00

4.00

5.00

6.00

7.00

0 1 2 3 4 5 6 7 8

x

f(x)

Page 113: CURVE  FITTING Student Notes

0.00

1.00

2.00

3.00

4.00

5.00

6.00

7.00

0 1 2 3 4 5 6 7 8

x

f(x)

Interior knots:16a1 + 4b1 + c1 = 4.616a2 + 4b2 + c2 = 4.6

36a2 + 6b2 + c2 = 1.536a3 + 6b3 + c3 = 1.5

End conditionsa1 + b1 + c1 = 0.549a3 + 7b3 + c3 = 3.0

First derivative continuous at interior knots8a1 + b1 = 8a2 + b2

12a2 + b2 = 12a3 + b3

Extra equationa1 =0

x f(x)1 0.504 4.606 1.507 3.00

(4, 4.6)

Page 114: CURVE  FITTING Student Notes

Interior knots:16a1 + 4b1 + c1 = 4.6 16a2 + 4b2 + c2 = 4.636a2 + 6b2 + c2 = 1.5 36a3 + 6b3 + c3 = 1.5

4 1 0 0 0 0 0 00 0 16 4 1 0 0 00 0 36 6 1 0 0 00 0 0 0 0 36 6 11 1 0 0 0 0 0 00 0 0 0 0 49 7 11 0 8 1 0 0 0 00 0 12 1 0 12 1 0

4.64.61515053 000

1

1

2

2

2

3

3

3

bcabcabc

.

...

End conditionsa1 + b1 + c1 = 0.5 49a3 + 7b3 + c3 = 3.0First derivative cont. at interior knots8a1 + b1 = 8a2 + b2 12a2 + b2 = 12a3 + b3

Extra equationa1 =0

Page 115: CURVE  FITTING Student Notes

SPECIAL NOTE

On the surface it may appear that a third order approximation using splines would be inferior to higher order polynomials.

Consider a situation where a spline may perform better:

A generally smooth function undergoes an abrupt change in a region of interest.

Page 116: CURVE  FITTING Student Notes

The abrupt changeinduces oscillationsin interpolating polynomials.

In contrast,the cubic splineprovides amuch moreacceptableapproximation

Page 117: CURVE  FITTING Student Notes

Specific Study Objectives

Understand the fundamental difference between regression and interpolation and realize why confusing the two could lead to serious problems Understand the derivation of linear least

squares regression and be able to assess the reliability of the fit using graphical and quantitative assessments.

Page 118: CURVE  FITTING Student Notes

Specific Study Objectives Know how to linearize data by

transformation Understand situations where

polynomial, multiple and nonlinear regression are appropriate Understand the general matrix

formulation of linear least squares Understand that there is one and only

one polynomial of degree n or less that passes exactly through n+1 points

Page 119: CURVE  FITTING Student Notes

Specific Study ObjectivesRealize that more accurate results

are obtained if data used for interpolation is centered around and close to the unknown pointRecognize the liabilities and risks

associated with extrapolationUnderstand why spline functions

have utility for data with local areas of abrupt change