LeastSquareFitAlgorithm.txt Given n points (x1, y1) ... (xn, yn) We consider this a tabulation of function values yi = f(xi) Compute coefficients ci i=1..r such that the function g = cr x^r + cr-1 x^r-1 + ... + c1 x + c0 minimizes sum(yi-g(xi)) is a Least Square Fit over the points. Algorithm: build matrix A, vector Y and solve for vector C A*C=Y where all sum's are over i=0,n-1 the x,y points r is the order of the approximating polynomial, max(r)=n // | sum(1.0) sum(x[i]^1) sum(x[i]^2) ... sum(x[i]^r-1) | | sum(x[i]^1) sum(x[i]^2) sum(x[i]^3) ... sum(x[i]^r) | A = | sum(x[i]^2) sum(x[i]^3) sum(x[i]^4) ... sum(x[i]^r+1 | | ... ... ... ... ... | | sum(x[i]^r-1) sum(x[i]^r) sum(x[i]^r+1) ... sum(x[i]^2r-1) | | sum(y[i]) | | sum(x[i]^1 * y[i]) | Y = | sum(x[i]^2 * y[i]) | | ... | | sum(x[i]^r-1 * y[i]) | See "Evaluate" and "Integrate" for the uses of the coefficients.