0% found this document useful (0 votes)
105 views3 pages

1.105 Solid Mechanics Laboratory: Least Squares Fit of Straight Line To Data

1. The document describes fitting a straight line to a data set of (x,y) coordinate point pairs using the least squares method to minimize error. 2. The least squares method finds the slope (m) and y-intercept (b) of the "best fit" line by setting the partial derivatives of the error function to zero. 3. This results in two linear equations that can be solved to determine the slope and intercept, and thus the best fit line through the data points.

Uploaded by

prieten20006936
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views3 pages

1.105 Solid Mechanics Laboratory: Least Squares Fit of Straight Line To Data

1. The document describes fitting a straight line to a data set of (x,y) coordinate point pairs using the least squares method to minimize error. 2. The least squares method finds the slope (m) and y-intercept (b) of the "best fit" line by setting the partial derivatives of the error function to zero. 3. This results in two linear equations that can be solved to determine the slope and intercept, and thus the best fit line through the data points.

Uploaded by

prieten20006936
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

105 Solid Mechanics Laboratory


Least Squares Fit of Straight Line to Data
We start with a data set of n points, xj, yj, through which we wish to t a straight line y = mx + b .
yj j

th

point

In the gure, we show 11 pairs of x,y values, xj,yj where n is the


number of points, n = 11. A jth point is shown as a shaded cir
cle.

Say we try to t a line by eye; we might draw a line as dis


played in the next graph.

y y = mx+b
yj y(xj) j

xj

th point
(yj - y(xj))

The aim now is to set m, the slope of our best t line and b, its
intercept with the y axis. The criteria we use is to minimize the least square error of the y coordinate. (This is not the only cri terion that might be usefully applied. Can you think of another?) That is we seek to choose m and b to minimize the quantity

Error =
x
xj

j=1

[y(x j) y j]

We can imagine moving the line around to minimize this sum. Thats in effect what is going through my mind as I eyeball a best t line. You might, hold the slope, m, constant and slide the line up and down until it looks good. Or you might pin the line at its y intercept, b, at x= 0 and rotate the line around until it looks even better. Or, better yet, we can rely upon the differential calculus and set the partial derivatives of this Error sum with respect to both m and b to zero - they are independent variables - in order to nd their values exactly. This we do now. We have: Error = m

j=1

2 [ mx j + b y j ] x j = 0

and

Error = b

j=1

2 [ mx j + b y j ] 1 = 0

Given the n pairs of points xj,yj , these can be taken as two linear equations for determining the slope and intercept. Rewriting, canceling the common factor, 2, we have

n n n 2 xj m + x j b = xj yj j = 1 j = 1 j=1

and n n n xj m + 1 b = yj j = 1 j = 1 j=1

1.105

September 24, 2003

LL Bucciarelli

Dividing all by n, the number of points, and noting that the sum of 1, n times is just equal to n, we have two linear equations for the unknowns m and b. The coefcients appearing in these two are set by the values of the data point pairs, xj,yj .

1 -n

j=1

1 2 x j m + -n
n

j=1 and

1 x j b = -n

j=1

xj yj

1 -n
The solution is: 1 -n

j=1

1 - x j m + b = -n

j=1

yj
1 x j -n

j=1 j=1 j=1 j=1 b = --------------------------------------------------------------------------------------------------------------------------------------- 2 n n 2 1 1 -x j -xj n n j=1 j=1

1 y j -n

2 1 x j -n

xj yj

and yj j=1 j=1 j=1 m = -----------------------------------------------------------------------------------------------------2 n n 2 1 1 -x j -xj n n j=1 j=1 1 -n

1 x j y j -n

1 x j -n

or, letting

1 x = -n

j=1 j=1 j=1 j=1 the rst sum is just the mean of xj, the second, the mean of yj, etc., we have more simply: 2 y x x xy b = -------------------------------2 2 x [x] Example 1. Given the three pairs of points: x 1 6 2 y 1 2 6
y = 3
yj

xj

1 y = -n

yj

1 xy = -n

xj yj

1 x = -n
2

xj

recognizing

and

xy x y m = --------------------- 2 2 x [x]

n = 3 and x = 3 y = 3 xy = 3

The averages compute to those shown at the right. With these we nd


b = 3.43 and m = 0.143

x
xj

= 3

The best t line is shown.

x = 3

1.105

September 24, 2003

LL Bucciarelli

You might have expected another result, e.g., a line through the origin, passing through the point 1,1. But consider the criterion we applied: The error we minimize is proportional to the vertical distance between the data point and the line. Try computing the error of the best t line and compare it with a line through 0,0 and 1,1. We note that the best t line goes through a point dened by the mean of xj and yj. You can verify this, in general, checking to see if, when you put x = x, you obtain y from y = mx + b .

Try adding another point or two to the set of three given. E.g., the points 0,0 and/or 6,6. What happens to the best t line?

1.105

September 24, 2003

LL Bucciarelli

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy