Professional Documents
Culture Documents
Curve Fitting 1
Curve Fitting By
Least-Squares Regression
and
Spline Interpolation
Part 7
Engineering Computation
Curve fitting
Curve Fitting:
Given a set of points:
- experimental data
- tabular data
- etc.
Fit a curve (surface) to the points so that we can easily evaluate
f(x) at any x of interest.
Engineering Computation
Curve fitting
Curve Fitting:
Engineering Computation
Curve Fitting:
1. We have discussed Least-Squares Regression where the
function is "best fit" to points but does not necessarily pass
through the points.
interpolation
extrapolation
Engineering Computation
Engineering Computation
Objective:
Obtain low order approximation (curve or surface) that
"best fits" data
Note:
Because the order of the approximation is < the number
of data points, the curve or surface can not pass through
all points.
We will need a consistent criterion for determining the
"best fit."
Typical Usage:
Scattered (experimental) data
Develop empirical models for analysis/design.
Engineering Computation
Least-Squares Regression:
yi
xi
Engineering Computation
Least-Squares Regression:
yi
xi
Engineering Computation
Least-Squares Regression:
3. Develop a "model" an approximate relationship between y
and x:
y = mx +b
4. Use the model to predict or estimate y for any given x.
5. "Best fit" of the data requires:
Optimal way of finding parameters (e.g., slope and
intercept of a straight line.
Perhaps optimize the selection of the model form
(i.e., linear, quadratic, exponential, ...).
That the magnitudes of the residual errors do not vary in
any systematic fashion. [In statistical applications, the
residual errors should be independent and identically
distributed.]
Engineering Computation
10
Least-Squares Regression
Given: n data points: (x1,y1), (x2,y2), (xn,yn)
Obtain: "Best fit" curve:
f(x) =a0 Z0(x) + a1 Z1(x) + a2 Z2(x)++ am Zm(x)
ai's are unknown parameters of model
Zi's are known functions of x.
We will focus on two of the many possible types of regression
models:
Simple Linear Regression
Z0(x) = 1 & Z1(x) = x
General Polynomial Regression
Z0(x) = 1, Z1(x)= x, Z2(x) = x2, , Zm(x)= xm
>> x=linspace(0,1,20);
>> y=2*x+1+0.1*randn(20,1);
>> plot(x,y,'.')
>> xx=[ones(20,1), x];
>> b=regress(y,xx)
b=
>> yy=xx*b;
1.0115
>> hold on
1.9941
>> plot(x,yy,k-')
Engineering Computation
12
Sr ei2
i 1
Engineering Computation
13
measured
value
y
yi
ei
modeled
value
x
xi
Our "best fit" will be the function which minimizes the sum of
squares of the residuals:
Sr
i 1
yi
Sr
ei2
a jZ j (x i )
i 1
i 1
j1
yi a 0 Z0 (xi ) a1Z1(x i ) a 2 Z2 (x i ) a m Zm (x i ) 2
n
Engineering Computation
14
Sr e
2
i
i 1
( yi a0 Z0 ( xi ) am Z m ( xi ))
i 1
Sr
2
a 0
Z (x )(y a Z (x ) ... a
0
Sr
2
a1
i 1
n
Z (x )(y a Z (x ) ... a
Sr
2
a m
m Zm (x i ))
m Zm (x i ))
i 1
n
Z
i 1
m (x i )(yi
a 0 Z0 (x i ) ... a m Zm (x i ))
Engineering Computation
(m+1) = # unknowns
Z0 x1
Z x
Z 0 2
Z0 x n
Z0 x1
Z1x 2
Z1x n
Zm x1
Zm x 2
Zm x n
15
Engineering Computation
or
=0
S r
= 0 = 2 [Z]T[Z]{A} 2 [Z]T{Y}
a i
[Z]T[Z]{A} = [Z]T{Y}
Engineering Computation
[Z]T[Z]{A} = [Z]T{Y}
17
Engineering Computation
1 1
x x
2
1
1 x1
1 1 x 2 a 0 1 1
xn
a1 x1 x 2
1
x
n
y1
1 y 2
x n
yn
18
Engineering Computation
19
Normal Equations
[Z]T[Z] {A} = [Z]T{Y}
upon multiplying the matrices become
n
xi
i1
xi
yi
a 0 i1
i 1
n
n
a1
2
xi
x i yi
i 1
i1
Normal Equations
for Linear Regression
C&C Eqs. (17.4-5)
(This form works well
for spreadsheets.)
Engineering Computation
20
n
a1
x y x y
i i
i 1
i 1
i 1
2
xi
i 1
i 1
2
xi
1
yi a1
n
i 1
y a1x
1
a0
n
i 1
xi
Engineering Computation
21
y y x x
i
a1
i 1
2
x
i
i 1
which is easier and numerically more stable, but the 2nd equation
remains the same:
a 0 y a1x
Curve Fitting 22
y = a1eb1x
Curve Fitting 23
5
y = a2x
b2
2
a3=5
b3=1..10
20
40
60
80
a3x
y=
b3 + x
100
Engineering Computation
Goodness of fit
24
Engineering Computation
Goodness of fit
Sr ei2 ( yi y 'i )2
Spread of the data around the mean:
St
(yi - y) 2
25
Engineering Computation
Goodness of fit
26
Coefficient of determination
describes how much of variance is explained by
the regression equation
St - Sr
r =
St
2
Engineering Computation
27
Precision :
If the spread of the points around the line is of similar
magnitude along the entire range of the data,
Then one can use
sy
Sr
n (m 1)
Engineering Computation
28
Statistics
Chapra and Canale in sections PT5.2, 17.1.3 and 17.4.3 discuss
the statistical interpretation of least squares regression and some
of the associated statistical concepts.
The statistical theory of least squares regression is elegant,
powerful, and widely used in the analysis of real data
throughout the sciences.
See Lecture Notes pages X-14 through X-16.