EGR 105 Foundations of Engineering I
Fall 2008 – Session 4Excel – Plotting, Curve-Fitting, Regression
EGR105 – Session 4 Topics
• Review of Basic Plotting• Data Analysis Concepts • Regression Methods• Example Function Discovery• Regression Tools in Excel• Homework Assignment
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
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
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
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
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
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
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 + …
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
Linear & Quartic Curve Fit Example
Better fit but does it make sense with expected behavior?
Y
Y
X
X
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
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
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
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)
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)
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)
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)
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)
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)
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
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