20
Empirical Model Building Ib: Objectives: By the end of this class you should be able to: Determine the coefficients for any of the basic two parameter models Plot the data and resulting fits Calculate and describe residuals Palm, Section 5.5 Download file FnDiscovery.mat and load into MATLAB

Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

  • Upload
    lisbet

  • View
    39

  • Download
    1

Embed Size (px)

DESCRIPTION

Empirical Model Building Ib: Objectives: By the end of this class you should be able to:. Determine the coefficients for any of the basic two parameter models Plot the data and resulting fits Calculate and describe residuals. Palm, Section 5.5 - PowerPoint PPT Presentation

Citation preview

Page 1: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Empirical Model Building Ib: Objectives:

By the end of this class you should be able to:

• Determine the coefficients for any of the basic two parameter models

• Plot the data and resulting fits• Calculate and describe residuals

Palm, Section 5.5

Download file FnDiscovery.mat and load into MATLAB

Page 2: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

1. Below are three graphs of the same dataset. What is the name and equation of the likely model

that would match this data?

0 10 20 300

20

40

60

80

100

x

y

Linear Graph

0 10 20 3010

-1

100

101

102

x

y

Semilog Graph

100

101

102

10-1

100

101

102

x

y

Log-Log Graph

Page 3: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

2. Here are the plots for another dataset. Name the model and write its equation for this case

0 5 10 15 20 25 300

50

100

150

200

250

300

350

400

x

y

Linear Graph

0 5 10 15 20 25 3010

-1

100

101

102

103

x

y

Semilog Graph

100

101

102

10-1

100

101

102

103

x

y

Log-Log Graph

Page 4: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

How would you

define the Best Fit

line?

0 0 . 5 1 1 . 5 20

2

4

6

8

1 0

F o r c e ( lb s . )

Leng

th In

crea

se (i

n.)

Page 5: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Fitting a Linear equation via matricese.g., Fitting the Spring data

• Model: y = mx + b • Setup: 1. Design Matrix: >> X = [ones(length(Force),1),

Force]2. Response Vector >> Y= Length

• Fit: find the fitted parameters >> B = X \ Y B will be

• Predict: calculate predicted y for each x>> Lhat = X*B

• Plot: plot the result >> plot(Force, Length, ‘p’, Force, Lhat) (plus

labels ...)

m

b

Page 6: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

A Linear Model & it’s Design Matrix

64.11

15.11

47.01

01

X

y = b(1) + mx Linear Model:

Design Matrix:

>> X = [ ones(4, 1), L’ ]Matlab Syntax: (to convert a row vector of x values to a design matrix)

Page 7: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Fitting a Linear Equation in Matrix Form

4

3

2

1

64.11

15.11

47.01

01

2.8

9.5

5.2

0

m

b

XY

>> B = X\Y

Matrix Equation:

The Full Matrices

MATAB Syntax for finding the parameter matrix

Page 8: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Linear Equation in Matrix Form

00.5

08.0

64.11

15.11

47.01

01

3.8

8.5

4.2

08.0

XY ˆ

fits: >> yhat = X*B

residuals: >> res = Y - X*B

Page 9: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Fitting Transformed models

• Same as linear model except set up design matrix (X) and response vector (Y) using the transformed variables

• e.g., the capacitor discharge from last time

• straight line on a semilog plot what model is implied?

Exponential y = b10mx

or in this example V = b10mt

what is its linearized (transformed) formlog(V) = log(b) + mt

Page 10: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

E.G., Fitting the capacitor discharge data

Model: Last lecture we found the data was straight on a semilog plot implying an exponential model. For the base-ten model the equations are: V = b10mt or log(V) = log(b) + mt

Setup: 1. Design Matrix: >> X = [ones(length(t),1), t]2. Response Vector >> Y= log10(V)

Fit: determine parameters >> B = X \ Y

Predict: Predict: >> logVhat = X*BUntransform: >> Vhat = 10.^logVhat

orUntransform >> b = 10^B(1), m = B(2)Predict >> Vhat = b*10.^(m.*t)

Plot: either on linear or semilog plot

Page 11: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Equation Fit Parameters

linear x vs. yb = B(1)m= B(2)

power log(x) vs. log(y)

b=10^B(1) m=B(2),

exponential

x vs. ln(y)b=e^B(1) m=B(2),

x vs. log(y)b=10^B(1) m=B(2)

Function Discovery (Review) 2. Fitting Parameters (m & b)

bmxy

mbxy

mxbey

mxby 10

Page 12: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Fitting a 2-parameter models

Model: Identify Functional Form• Plot data

•is it linear ? •is it monotonic?

• Log-Log (loglog(x,y)) semilog (semilogy(x,y))• look for straight graph

Setup:

Transform Data to Linearize

Create X & Y matrices Fit linear model to transformed data

Predict and Untransform Parameters to m & b

Plot:

Plot data and predicted equation.

“Normal Data” “Transformed Data”

Page 13: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Class Exercise:

For problems 3 (x2 vs. y2) from last class:• What type of model will likely fit this data?

(from last time)• Determine the full model including

parameter values. • Plot the data and the fitted curve on one

plot

For problem 2 (x1 vs. y1), repeat the above.

Page 14: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:
Page 15: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

x y

1 5

2 8

3 10

4 20

5 21

6 29

7 34

8 36

9 45

Please plot this data and determine: • the likely model • parameters (m&b)(data is available in FnDiscovery.mat)

plot resulting data and model

Page 16: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

A Reminder of Some Nomenclature:

y response (dependent variable) vector yi an individual response

x predictor (independent variable) vectorxi an individual predictor value

the predicted value (the fits) an individual predicted value (fit)

y

iy

Page 17: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

0 1 2 3 4 5 6 7 8 9 100

5

10

15

20

25

30

35

40

45

50

x

y

Experimental Data

Fit: y = 5.02*x - 1.97

Page 18: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Residuals:• What is left after subtracting model from data:

residuals = y – yhat

• Represents what is not fit by the model

• Ideal model should capture all systematic information

• Residuals should contain only random error

• Plot residuals and look for patterns

Page 19: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

What to look for in a residual plot:

1. Does the residual plot look correct? data should vary about zerosum of residuals must equal zero

2. Are there any patterns in the residuals?, e.g., curvature: high center, low ends or

low center, high ends

changes is variability: the spread of the data in the y direction should be constant

3. How big are the residuals?(what is the magnitude of the y axis)

Page 20: Empirical Model Building Ib: Objectives: By the end of this class you should be able to:

Thermocouple Calibration Data is it linear?

• Plot this data Does it look linear?

• Fit a linear model

• Determine the residualsPrepare a residuals plot

• Is it linear?

• (data is available in FnDiscovery.mat)

mV (mV) T(C)

0 0 0.3910 10.0000 0.7900 20.0000 1.1960 30.0000 1.6120 40.0000 2.0360 50.0000 2.4680 60.0000 2.9090 70.0000 3.3580 80.0000 3.8140 90.0000 4.2790 100.0000