Maths Algorithms in C#: Linear Least Squares Fit
When analysing data it is often useful to find an equation to show the relationship in a certain set of data. The linear least squares fit tries to do exactly that.
Given a set of data points, it tries to find a straight line with the equation y = Mx + B which best fits the data, using the least squares technique, which works out the squares of the deviations of each point and then tries to minimize those.
The full sourcecode for the MathLib library is available at https://github.com/sjmeunier/mathlib
Originally posted on my old blog, Smoky Cogs, on 23 Oct 2009
Updated 5 Oct 2016: Updated code snippet after refactoring MathLib library