Find a "best fit" equation

Here's an article comparing two ways to fit a line to data. One thing to watch out for is that there is a direct solution that is correct in theory but can have numerical problems. The article shows why that method can fail and gives another method that is better.


Although you can use an iterative approach, you can directly calculate the slope and intercept of a line given a set of observations using a least-squares approach. See the "Univariate Linear Case" section of the Wikipedia article on linear regression for how to calculate the coefficients a and b in y = a + bx given sets of (x,y) points.


Method of Least Squares http://en.wikipedia.org/wiki/Least_squares. This book Numerical Recipes 3rd Edition: The Art of Scientific Computing (Hardcover) has all you need for algorithms to implement Least Squares and other techniques.

Tags:

Php

Math