Least Squares Fitting of Data to a Curve

[Pages:64]Least Squares Fitting of Data to a Curve

Gerald Recktenwald Portland State University Department of Mechanical Engineering

gerry@me.pdx.edu

These slides are a supplement to the book Numerical Methods with Matlab: Implementations and Applications, by Gerald W. Recktenwald, c 2000?2007, Prentice-Hall, Upper Saddle River, NJ. These slides are copyright c 2000?2007 Gerald W. Recktenwald. The PDF version of these slides may be downloaded or stored or printed only for noncommercial, educational use. The repackaging or sale of these slides in any form, without written consent of the author, is prohibited. The latest version of this PDF file, along with other supplemental material for the book, can be found at recktenwald or web.cecs.pdx.edu/~gerry/nmm/.

Version 0.82 November 6, 2007

page 1

Overview

? Fitting a line to data Geometric interpretation Residuals of the overdetermined system The normal equations

? Nonlinear fits via coordinate transformation ? Fitting arbitrary linear combinations of basis functions

Mathematical formulation Solution via normal equations Solution via QR factorization ? Polynomial curve fits with the built-in polyfit function ? Multivariate fitting

NMM: Least Squares Curve-Fitting

page 2

Fitting a Line to Data

Given m pairs of data: (xi, yi), i = 1, . . . , m

Find the coefficients and such that

F (x) = x +

is a good fit to the data Questions: ? How do we define good fit? ? How do we compute and after a definition of "good fit" is obtained?

NMM: Least Squares Curve-Fitting

page 3

Plausible Fits

Plausible fits are obtained by adjusting the

5

slope () and intercept (). Here is a

graphical representation of potential fits to a

4

particular set of data

y

3

Which of the lines provides the best fit?

2

1 123456 x

NMM: Least Squares Curve-Fitting

page 4

The Residual

The difference between the given yi value

5

and the fit function evaluated at xi is

4

ri = yi - F (xi)

y

= yi - (xi + )

3

ri is the residual for the data pair (xi, yi).

ri is the vertical distance between the known data and the fit function.

2 1

123456 x

NMM: Least Squares Curve-Fitting

page 5

Minimizing the Residual

Two criteria for choosing the "best" fit

X

X

minimize |ri| or minimize ri2

For statistical and computational reasons choose minimization of = P ri2 X m

= [yi - (xi + )]2

i=1

The best fit is obtained by the values of and that minimize .

NMM: Least Squares Curve-Fitting

page 6

Orthogonal Distance Fit

An alternative to minimizing the

y

residual is to minimize the orthogonal

distance to the line. Minimizing P d2i is known as the Orthogonal Distance Regression

problem.

See, e.g., ?Ake Bjo?rk, Numerical Methods for Least Squares Problems,

1996, SIAM, Philadelphia.

d3

d4

d2 d1

x1

x2

x3

x4

NMM: Least Squares Curve-Fitting

page 7

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download