Associated Topics || Dr. Math Home || Search Dr. Math

### Curve Fitting

```
Date: 12/13/96 at 10:37:22
From: Jeff Hunsaker
Subject: Convert points into a line

Dear Dr. Math,

Given several points on a graph,  how can I convert those points into
a line?  The business problem might be:  I know Company XYZ has the
following sales numbers...

1995 - \$2mil
1996 - \$3mil
1997 - \$2.5mil

I would like to know the overall pattern (i.e. derive the slope of a
line constructed from the points (1,2), (2,3), (3,2.5) with years on
the X axis and sales on the Y axis).

Thanks in advance for any assistance.

Jeff...
```

```
Date: 12/13/96 at 12:56:33
From: Doctor Rob
Subject: Re: Convert points into a line

Jeff, you ask a very good question, and one with very interesting and
far-reaching applications.

The basic fact is that two points determine a line.  The slope of the
line connecting (x1,y1) and (x2,y2) is given by (y2-y1)/(x2-x1).  You
have three points, and sometimes you will have many more than that.
Two things can happen:

1) The points lie on the same line.  Then the slopes of the lines
connecting all pairs of points will be the same, and will be the slope
of that common line.  This is a *very* lucky occurrence, and, of
course, it is the simple case.

2) The points do not lie on the same line (are not "colinear").  Then
there is no line passing through all the points.

The best you can do is to find a line that comes as close to all the
points as possible. There are several ways of measuring how close a
line is to a point. The one most commonly used requires that for each
x-coordinate, you measure the square of the difference between the
y-coordinate of the point and the line there. You will add up these
squares, and then try to minimize that sum. When the sum is small,
this gives the "best" fitting line to the data.  This procedure is
called Least-Squares Fitting.

The formula for the slope of the best Least-Squares Fit line is:

(Sum xi)(Sum yi) - N (Sum (xi*yi))
m = ----------------------------------
(Sum xi)^2 - N (Sum (xi^2))

where N is the number of points, and the points are
(x1, y1), (x2, y2), ..., (xi, yi), ... (xN, yN), and all the sums run
from i=1 to i=N.  The formula for the y-intercept is:

(Sum xi)(Sum (xi*yi)) - (Sum (xi^2))(Sum yi)
b = ----------------------------------------
(Sum xi)^2 - N (Sum (xi^2))

The equation of the line is then y = m*x + b.

Now you can use the data from the problem statement above to figure
out the best line for that particular data set.

HINTS:  N = 3,  (Sum xi) = 5988,  (Sum yi) = 7500000,  (Sum (xi^2)) =
11952050,  so the denominator is 5988^2 - 3*11952050 = -6.

If you need more help, feel free to write back to us.

-Doctor Rob,  The Math Forum
Check out our web site!  http://mathforum.org/dr.math/
```
Associated Topics:
High School Equations, Graphs, Translations

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search