26
EGR 105 Foundations of Engineering I Fall 2008 – Session 4 Excel – Plotting, Curve-Fitting, Regression

EGR 105 Foundations of Engineering I

  • Upload
    marlee

  • View
    30

  • Download
    2

Embed Size (px)

DESCRIPTION

EGR 105 Foundations of Engineering I. Fall 2008 – Session 4 Excel – Plotting, Curve-Fitting, Regression. TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A. EGR105 – Session 4 Topics. Review of Basic Plotting Data Analysis Concepts Regression Methods - PowerPoint PPT Presentation

Citation preview

Page 1: EGR 105  Foundations of Engineering I

EGR 105 Foundations of Engineering I

Fall 2008 – Session 4Excel – Plotting, Curve-Fitting, Regression

Page 2: EGR 105  Foundations of Engineering I

EGR105 – Session 4 Topics

• Review of Basic Plotting• Data Analysis Concepts • Regression Methods• Example Function Discovery• Regression Tools in Excel• Homework Assignment

Page 3: EGR 105  Foundations of Engineering I

Analysis of x-y Data

• Independent versus dependent variables

independent

depe

nden

ty = f (x)

x

y

Page 4: EGR 105  Foundations of Engineering I

Simple PlottingGenerate X and Y data to Plot

Page 5: EGR 105  Foundations of Engineering I

Common Types of Plots: Y=3X2

logy = log3 + 2logxy = 3x2

Straight Line on log-log Plot!

Normal

Semi-log: log x

log-log: log y-log x

Page 6: EGR 105  Foundations of Engineering I

Finding Other Values

• Interpolation– Data between known points

• Regression – curve fitting

– Simple representation of data– Understand workings of system – Useful for prediction

• Extrapolation– Data beyond the measured range

datapoints

Page 7: EGR 105  Foundations of Engineering I

Curve-Fitting - Regression

• Useful for noisy or uncertain data – n pairs of data (xi , yi)

• Choose a functional form y = f(x) • polynomial• exponential • etc.

and evaluate parameters for a “close” fit

Page 8: EGR 105  Foundations of Engineering I

What Does “Close” Mean?• Want a consistent rule• Common is the least squares fit (SSE):

(x1,y1) (x2,y2)

(x3,y3) (x4,y4)

x

y

e3

ei = yi – f(xi), i =1,2,…,n

n

1i

2ieSSE

sum

squa

red

erro

rs

Page 9: EGR 105  Foundations of Engineering I

Quality of the Fit:

Notes: is the average y value0 R2 1closer to 1 is a “better” fit

SST

SSE12 R

n

1i

2ieSSE

n

yy1i

2i )(SST

x

y

yy

y

Page 10: EGR 105  Foundations of Engineering I

Linear Regression

• Functional choice y = m x + b slope

intercept

• Squared errors sum to

• Set m and b derivatives to zero

2SSE

iii bxmy

0SSE

0SSE

bm

Page 11: EGR 105  Foundations of Engineering I

Further Regression Possibilities:

• Could force intercept: y = m x + c• Other two parameter ( a and b ) fits:

– Logarithmic: y = a ln x + b– Exponential: y = a e bx

– Power function: y = a x b

• Other polynomials with more parameters:– Parabola: y = a x2 + bx + c– Higher order: y = a xk + bxk-1 + …

Page 12: EGR 105  Foundations of Engineering I

Excel’s Regression Tool• Highlight your chart• On chart menu, select “add trendline”• Choose type:

– Linear, log, polynomial, exponential, power• Set options:

– Forecast = extrapolation – Select y intercept– Show R2 value on chart– Show equation on chart

Page 13: EGR 105  Foundations of Engineering I

Linear & Quartic Curve Fit Example

Better fit but does it make sense with expected behavior?

Y

Y

X

X

Page 14: EGR 105  Foundations of Engineering I

Example Function DiscoveryHow to find the best relationship

• Look for straight lines on log axes: linear on semilog x y = a ln x + b linear on semilog y y = a e bx

linear on log log y = a x b • No rule for 2nd or higher order

polynomial fits

Page 15: EGR 105  Foundations of Engineering I

Previous EGR105 Project

Discover how a pendulum’s timing is impacted by the:

– length of the string?– mass of the bob?

1. Take experimental data – string, weights, rulers, and watches

2. Analyze data and “discover” relationships

Page 16: EGR 105  Foundations of Engineering I

 

 

Experimental Setup:

Page 17: EGR 105  Foundations of Engineering I

One Team’s Results:time (sec)

13.73 27.47 41.20 54.94121.5 3.5 3.5 3.5 3.5114.0 3.4 3.4 3.4 3.4105.0 3.3 3.3 3.3 3.3

97.0 3.1 3.1 3.1 3.185.0 2.9 2.9 2.9 2.979.0 2.8 2.8 2.8 2.867.5 2.6 2.6 2.6 2.658.5 2.4 2.4 2.4 2.450.0 2.3 2.3 2.3 2.343.0 2.1 2.1 2.1 2.113.0 1.2 1.2 1.2 1.2

mass (grams)

leng

th (

inch

es)

Mass appears to have no impact, but length does

Page 18: EGR 105  Foundations of Engineering I

To determine the effect of length, first plot the data:

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

0.0 20.0 40.0 60.0 80.0 100.0 120.0 140.0

length (inches)

tim

e (

seco

nd

s)

Page 19: EGR 105  Foundations of Engineering I

Try a linear fit:

y = 0.02x + 1.1692

R2 = 0.9776

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

0.0 20.0 40.0 60.0 80.0 100.0 120.0 140.0

length (inches)

tim

e (

seco

nd

s)

Page 20: EGR 105  Foundations of Engineering I

Force a zero intercept:

y = 0.0332x

R2 = 0.4832

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

4.5

0.0 20.0 40.0 60.0 80.0 100.0 120.0 140.0

length (inches)

tim

e (

seco

nd

s)

Page 21: EGR 105  Foundations of Engineering I

Try a quadratic polynomial:

y = -0.0002x2 + 0.0551x

R2 = 0.9117

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

0.0 20.0 40.0 60.0 80.0 100.0 120.0 140.0

length (inches)

tim

e (

seco

nd

s)

Page 22: EGR 105  Foundations of Engineering I

Try logarithmic:

y = 1.0349Ln(x) - 1.6506

R2 = 0.9609

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

0.0 20.0 40.0 60.0 80.0 100.0 120.0 140.0

length (inches)

tim

e (

seco

nd

s)

Page 23: EGR 105  Foundations of Engineering I

Try power function:

y = 0.3504x0.4774

R2 = 0.9989

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

0.0 20.0 40.0 60.0 80.0 100.0 120.0 140.0

length (inches)

tim

e (

seco

nd

s)

Page 24: EGR 105  Foundations of Engineering I

On log-log axes, a nice straight line:

)log()log()log( lbatalt b

1.0

10.0

1.0 10.0 100.0 1000.0

length (inches)

tim

e (

seco

nd

s)

Power Law Relation:

b

Page 25: EGR 105  Foundations of Engineering I

Elastic Bungee Cord Models Determined by Curve Fitting the Data

• Linear Model (Hooke’s Law): • Nonlinear Cubic Model: 3

32

21)( sksksksF kssF )(

Linear Fit

Cubic Fit Better and it Makes Sense with the Physics

Force (lb)

sl

ll

LengthOriginal

Elongation

o

o

Collected Data

Page 26: EGR 105  Foundations of Engineering I

Homework AssignmentSee passed out sheet or course web site