OK

© All Rights Reserved

35 views

OK

© All Rights Reserved

- Floater Hormann
- Cubic Spline Interpolation
- Lagrange Interpolation
- Toolbox 2007
- Least Square Fit
- cv njumail
- Hookes Law Applied to a Meter Stick SPH4U Lab 1
- 00077569 Analysis and Interpretation of Water-Oil-Ratio Performance
- Horne Ostenberg Sleep
- Aiaa-1997-3725-958 Optimal External Configuration Design of Unguided Missiles
- Module-22-resource-estimation-exercises.pdf
- Differentiation
- Sales Forecasting From Encyclopedia
- echeverria2012 (1)
- Error evaluation for IDW mineral reserve estimates - Li Zhanglin, Wang Ping
- Survey Mutual-Information-Based Registration of Medical Images
- Statistics.docx
- 1512020
- Psd
- Rohling Pr

You are on page 1of 14

At the end of this lecture, you will be able to:

explain the difference between curve fitting and interpolation

decide whether curve fitting or interpolation should be used for a particular application

interpolate values between data points using linterp and interp with cspline.

fit equations using line, regress, linfit, and genfit.

Background

Thermophysical and transport property data are often needed in engineering calculations. Quantities such as he

capacities, thermal conductivities, diffusivities, densities, and viscosities are measured experimentally and the results

are found in handbooks and journal articles. Usually, the data are not published for every condition that may be

experienced in real life problems. For example, vapor pressures might be published for at 310 K and 320 K, but you may

need the value at 315 K. In such situations, two options are available: interpolating and curve fitting.

Interpolation is determining a new point between two existing points. For example, if I measured the heat capacity to

be 10 J/mol/K at 300K and 20 J/mol/K at 310 K, I might reasonably estimate the heat capacity at 305 K to be 15

J/mol/K.

Curve Fitting is determining a function that closely matches the data. For example, the data may look like a straight

line, so we can determine the slope and intercept that gives a line that matches the data the best. The Antoine Equation

is a familiar function that "fits" the temperature dependence of vapor pressures well.

A few notes:

1. Interpolation can really be thought of as a special case of curve fitting where the function is forced to pass through

every data point.

2. Interpolation is generally done linearly or with cubic splines. Cubic splines means a third-order polynomial is

generated connecting the points rather than a straight line.

3. Extrapolation is defined as predicting values beyond the range of the available data. For example, vapor pressures

were measured at 310 K and 320 K, I could interpolate to obtain a value for a value between 310 K and 320 K, but I

would be extrapolating if I used the same points to obtain a value for 305 K or 325 K. Thus, the uncertainties are

greater for extrapolated values compared to interpolated values.

4. You generally use curve fitting when you know a function that matches the data well. When you don't know a

function, you interpolate. (Functions for fitting can come from simple observation, experience, trial and error, or

theory.

2. Interpolating

Demonstration

Consider the following time/temperature measured in an experiment data. I would like to know the values of the

temperature at all times, not just the whole minutes.

0 298

1 300

2 300

3 305

Time min Temp

4 305

K

5 310

6 312

7 318

8 317

9 322

Linear Interpolation

Linear interpolation is done by using the linterp function which has three arguments. It takes the form:

y new := linterp(xdata,ydata,x new).

Key Points:

1. The last argument of linterp is the value of x at which you want to estimate y.

2. The last argument can be a variable if a function is defined. This allows you to use the

interpolation over and over which is useful for graphing or integrating data.

Instead of using a line to interpolate between data points, a cubic polynomial may be used to connect the points.

This is done by using the interp and cspline functions.

tempnew interp( cspline( Time Temp) Time Temp 4.5min) tempnew 307.335 K

Temp_spline( t) interp( cspline( Time Temp) Time Temp t) Temp_spline( 4.5min) 307.335 K

Alternatively, you can first calculate cspline and then feed the results to interp.

Visualization

330

Temp 320

Temp_linterp( t)

Temp_spline ( t)

310

300

290

0 200 400 600

Time t t

3. Curve Fitting

Background

line (or slope and intercept)

regress

linfit

genfit

Each utility can fit certain types of equations. line will return the slope and intercept of the linear relationship

that best fit the data. regress is used to return the polynomial that best represents the data. linfit may be

used to fit data to expressions which are linear combinations of functions. genfit may be used to fit data to

functions of any type.

Each fitting method can fit the functions of those above it in the list. For example, regress can do the same

thing that line can because a line is just a 1st order polynomial. Since a line is also a linear combination of

functions, linfit can also be used. Genfit can be used in any case.

Syntax

line ( xdata ydata)

Demonstration

Determine the best fit line to the time/temperature data used above.

0

0

0 0

0 298

1 60

1 300

2 120

2 300

3 180

3 305

Time 4 240 s Temp 4 305 K

5 300

5 310

6 360

6 312

7 420

7 318

8 480

8 317

9 540

9 322

Intercept K

Time Temp 296.4

line K/min

min K 2.733 Slope

Question: What are the units on the intercept and the slope?

Key Points:

1. The arguments to the line function must be dimensionless.

2. You must determine the units yourself.

K

slope ( Time Temp) 2.733 intercept ( Time Temp) 296.4 K

min

Key Point: You don't need to remove the units on the input data if you use slope and intercept

instead of line.

Visualization

330

Temp

320

Temp_linterp( t)

Temp_spline ( t)

Temp_linear( t) 310

300

290

0 200 400 600

Time t t

Syntax

vs := regress(xdata,ydata,order_of_polynomial) interp(vs,xdata,ydata,xnew)

Demonstration

The heat capacity of water as a function of temperatures has been measured in a calorimeter. The data are

found in the matrices below. Fit the data to a fourth order polynomial.

D

0 1

0 273.15 7.617104

kmol 1000mol

1 293.15 7.536104

2 313.15 7.534104

3 333.15 7.536104

4 353.15 7.556104 0 1 J

Tempexp D K Cpexp D

5 373.15 7.595104 kmol K

6 393.15 7.653104

7 413.15 7.725104

8 433.15 7.813104

9 453.15 7.928104

The regress function will give the coefficients of each term in the polynomial.

3

3

4

Tempexp Cpexp 276.37

vs regress 4

K J

vs 2.09

mol K 3

8.125 10

5

1.412 10

9.37 10 9

Key Point: The output of regress is a matrix. The first three rows are NOT the coefficients, they

are values needed if interp is going to be used. The fourth row is the coefficient on the x0 term

(the constant) The fifth row is the coefficient on the x1 term. The last row is the coefficient on

the xn term.

Tempexp Cpexp

Cpregress( t) interp vs t

K J

Cpregress( 350 ) 75.528

mol K

Question: What are the units on the temperature and heat capacity?

Key Point: Using regress with interp means you cannot include units in the function.

2

t

3 4

Cpregress( t) vs vs vs vs vs

t t t J

3 4 K 5 K 6 K 7 K mol K

J

Cpregress( 350K) 75.528

mol K

Check the Results

95

90

Cpexp

85

Cpregress( t)

80

75

300 400 500

Tempexp t

Often, the expression we wish to use to fit the data is not a polynomial but a linear combination of functions. A linear

combination of functions is one where each term only has one fitting parameter. For example,

y = A B sin( x ) C exp( x )

is a linear combination of functions. Only one fitting parameter is found in each term and they are multiplying the term.

The following are NOT linear combinations of functions.

y = A B sin( x C) D exp

x

y = A sin( B x ) C exp( x )

E

In the first expression, B is inside the sine function. Thus, the B dependence is not linear. In the second equation,

multiple fitting parameters appear in the last two terms.

Syntax

term1

F( x ) =

term2

= linfit( xdata ydata F)

term_n

The terms in the F(x) matrix are the functional forms of each term without the coefficient. For example, if the

function to fits is

y = A B sin( x ) C exp( x )

term1 would be 1, term2 would be sin(x) and term3 would be exp(x).

Demonstration

Experimental data for the liquid density of acetone is found in the matrices below. Fit this data to the following

expression.

2 4

0.35 3 3

Y = A B 1 C 1 D 1 where

T T T 1 T

TC TC TC TC

E

D

0 1

TC 508.2

0 183.15 15.679

1 198.15 15.406

0 1 kmol

2 216.97 15.062 Tempexp D K exp D

3

3 223.15 14.943 m

4 233.15 14.752

5 234.79 14.736

6 243.15 14.561

7 253.15 14.37

8 255.7 14.345

9 263.15 14.18

1

0.35

1 x

TC

2

5.671

3

1 x Tempexp exp 1.316

F( x ) TC

linfit F 36.436

K kmol 44.882

1 x

m

3

TC

23.221

4

x

3

1 T

C

Key Point: Linfit does not like units on its input data so divide them out.

Create a function with the results of linfit.

2 4

0.35 3 3

t t t t kmol

( t) 1 1 1 1

0 1 TC K 2 TC K 3 TC K 4 TC K

m3

Key Point: Put in the units explicitly when you define the function.

4

1.6 10

4

1.4 10

4

1.2 10

exp

( t) 4

1 10

3

8 10

3

6 10

200 300 400 500

Tempexp t

When the function to fit is not a line, polynomial, or linear combination, you must use genfit.

Key Point: Only use genfit if you have to, genfit requires good guesses and it is easier to make errors with genfit.

Syntax

y( x)

y( x )

0

guessA0

y( x )

g ( x ) = guessA1

1 guess =

= genfit xdata ydata guess g

guessAn

y( x )

n

Demonstration

Experimental data for the vapor pressure of acetone is contained in the matrices below. Fit the data to the

Antoine Equation:

B

ln( Psat) = A

TC

D 0 1

0 1 Tempexp D K Psatexp D Pa

0 203.65 58.928

1 212.45 119.72

2 234.05 797.13

3 243.25 1.581103

4 253.34 3.48103

5 259.18 4.267103

6 262.12 5.182103

7 282.23 1.484104

8 265.04 6.005103

9 267.05 6.853103

The Antoine Equation must be fit using genfit. The first thing needed is the partial derivatives of the

function with respect to each parameter (constant). You can do the derivatives in your head or

using Mathcad.

aone

azero

t atwo

d aone

azero t a 1

dazero two

d aone 1 you cannot use [ notation for the subscripts.

azero t a a

daone two two t

d aone aone

azero t a

datwo two

2

atwo t

Create the g(x,a) matrix. (Note: this doesn't have to be called g.)

aone

zero

a

t atwo

1

g ( t a) 1

atwo t

aone

2

atwo t

a

a 1 Key Points:

0 t a2 1. Genfit requires a the constants be a matrix variable. Use [

notation.

1 2. One common mistake is to interchange the t and the a order

g ( t a) 1 when defining g(t,a). This must not be done.

a t

2

a

1

2

a t2

Key Point: You should have a guess value for each constant in your

50 equation.

ag 3000

50

21.662

Tempexp Psatexp

a genfit ln ag g a 2.997 103

K Pa

33.723

Key Points:

1. If genfit doesn't converge, try a new guess value.

2. Notice that the y data is ln(Psat) as required by the original

equation.

3. You cannot have units on the data so divide them out.

4. The last argument in genfit is the name of the matrix containing

the partial derivatives. Do not put g(t,a); it is just g.

Define the function with the correct parameters.

a 1

Psat( t) exp a Pa 4

0 Psat( 300K) 3.311 10 Pa

t

a

K 2

Check the fit by plotting Key Point: You must always check to make sure the fit is good by

plotting. If it doesn't fit well, change your guess and ensure you did

not make a mistake.

6

5 10

6

4 10

6

Psatexp 3 10

Psat( t) 6

2 10

6

1 10

0

200 300 400 500

Tempexp t

Extra Practice

1 2

2 1

Fit the data given in the matrices to the right to the following expression.

X Y

3 3

4 2

y ( x ) = 0 cos 1 x 2 x 3

5 4

6 3

0 cos 1 x 2 x 3

cos x .2 0.682

1

g

2.5

3.146

g ( x ) x sin x genfit X Y g g

0 1 .40 0.405

.10 1.109

2

1

0 1

y ( x ) cos x x

2 3

5

3

y( xx)

Y

2

0

0 2 4 6

xx X

- Floater HormannUploaded byLa Tino
- Cubic Spline InterpolationUploaded byAshwini Kumar Pal
- Lagrange InterpolationUploaded byFarah Sofhia Mohd Zin
- Toolbox 2007Uploaded byborakas2011
- Least Square FitUploaded byMuhammad Awais
- cv njumailUploaded byapi-425293056
- Hookes Law Applied to a Meter Stick SPH4U Lab 1Uploaded bymarina
- 00077569 Analysis and Interpretation of Water-Oil-Ratio PerformanceUploaded byriochig
- Horne Ostenberg SleepUploaded bykyyyyliet
- Aiaa-1997-3725-958 Optimal External Configuration Design of Unguided MissilesUploaded bydaoud
- Module-22-resource-estimation-exercises.pdfUploaded bygeologer
- DifferentiationUploaded bysalviano81
- Sales Forecasting From EncyclopediaUploaded bymugdha09
- echeverria2012 (1)Uploaded byrasim_m1146
- Error evaluation for IDW mineral reserve estimates - Li Zhanglin, Wang PingUploaded byDario Rojas Iruri
- Survey Mutual-Information-Based Registration of Medical ImagesUploaded byBoda Kishan
- Statistics.docxUploaded bytamann2004
- 1512020Uploaded byFelipe Pires
- PsdUploaded byTeo Andrade Farfán
- Rohling PrUploaded byKathleen Franklin
- POLARIZATION IMAGING FOR REMOTE SENSINGUploaded byAshfaq Ahmed
- Sas Gplot Slides 1 26 2011Uploaded bymiriyamsatyanarayana
- Fast Color SpaceUploaded byDAVID

- Glencore - Preparing for Successful Interivew.pdfUploaded byWelsinsin Kevin Sin
- beginners-guide-psychometric-test-jobtestprep.pdfUploaded bySriraghuraman Gopal Rathnam
- ArcNLET AGIS-based Software to Simulate Ground Water NitrateUploaded byWelsinsin Kevin Sin
- okUploaded byWelsinsin Kevin Sin
- manual_4_1Uploaded byJuan Pérez
- 10.1016@j.marpetgeo.2018.02.002Uploaded byWelsinsin Kevin Sin
- 10.1016@j.ijrmms.2018.01.044Uploaded byWelsinsin Kevin Sin
- Для Просмотра Статьи Разгадайте Капчу_2Uploaded byWelsinsin Kevin Sin
- NPVUploaded byLa Ode Raemaka
- SHillUploaded bysrivasthu
- International CV A4Uploaded byzaheerabbasi
- European Cv FormatUploaded bySzima Szabolcs
- Ust Rat Pub HistoryUploaded byWelsinsin Kevin Sin
- gag-ch-21-170717044359Uploaded byWelsinsin Kevin Sin
- Underground Pressure Characteristics Analysis in Back-gully Mining of Shallow Coal Seam Under a Bedrock Gully SlopeUploaded byWelsinsin Kevin Sin
- Underground Mining of Thick Coal SeamsUploaded byWelsinsin Kevin Sin
- Coats Elements of Reservoir SimulationUploaded byWelsinsin Kevin Sin
- Reserve Estimation Methods_00_IntroductionUploaded byviya7
- Black Oil Definitions.pdfUploaded byianherzog
- Volumetric CalculationsUploaded byFuad Mohamed A. Alamin
- Osullivan InterfacesUploaded byWelsinsin Kevin Sin
- Minemax Scheduler White PaperUploaded byWelsinsin Kevin Sin
- CourseOutline_MINE4260_2014Uploaded byWelsinsin Kevin Sin
- Stratigraphy, Exploration and EOR Potential of the TensleepCasper Formations, SE WyomingUploaded byWelsinsin Kevin Sin
- WGRFC Basin DelineationUploaded byWelsinsin Kevin Sin
- Python Sending EmailUploaded byWelsinsin Kevin Sin

- DPB-1000 Service V1.9Uploaded byFred G Manda
- CIPD - 4DEPUploaded byWissam Aoudi
- LH5116Uploaded byLuis Gajardo Vasquez
- Action Plan on Echo Training on Nutritional Assessment- ILIGAN CITYUploaded byVon Tatil
- Data Modeling 101Uploaded byparthasc
- Mark R. Leary- The Curse of The Self (Unplugged)Uploaded byTing Wu
- Wika Electrical Temperature Measuring InstrumentsUploaded byDragoi Alexandrina
- Course Outline Consumer Behavior UpdatedUploaded bykhanbaba1998
- direct instruction lesson plan template wwiUploaded byapi-285080423
- Mindfulness Glossary of TermsUploaded bymykolayovych
- 13-AndreaPapini.pdfUploaded byCharles Callahan
- 45_1_non_pmtrc_tsts_sngl_smplUploaded bytarek moahmoud khalifa
- fb_structuredText.pdfUploaded byalejandrobarillas
- e Types StrategyFormulation&Implementation Merged _GL v0.1Uploaded byGiorgiLobjanidze
- 1000 Solved Problems in Fluid k Subram 20347920Uploaded byRhiscptreohLtusocan
- Mind MappingUploaded byLungani Sibindi
- Deadlock Avoidance in Train SchedulingUploaded byframazza
- IRM.Press.Managing.Multimedia.Semantics.eBook-kB.pdfUploaded byMilena Stefanova
- Problem Solving in MathematicsUploaded byNor Hasmira Zainy
- Foundalis_dissertationUploaded bystasko_g
- Asrock Ion 330HT DTS GuideUploaded bykenw
- 2002 Torsvik Etal BATLASUploaded byquispesolanopaul
- Samsung Wisenet Smt 3233 Data SheetUploaded byJohn Carlos Montes Gutierrez
- Dräger AirShield Isolette C400 - User ManualUploaded byAnton Funji DeLarge
- TNB Case StudyUploaded bybobbymaly
- Graphical Based Password Using Keystroke Dynamic Authentication System For Banking ApplicationUploaded byAnonymous vQrJlEN
- Administrative Assistant or Clerk or Receptionist or Event PlannUploaded byapi-121366632
- Verae Alchemiae doctrinaUploaded byPrabhasvara
- 30598-816-01A2Uploaded byMehdi Taheri
- MYP GlossaryUploaded byLennoxMeldrum