2 least-squares.cc -- implement minimise_least_squares
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "least-squares.hh"
14 minimise_least_squares (Real *coef, Real *offset,
15 Array<Offset> const &input)
22 for (int i = 0; i < input.size ();i++)
24 Real x = input[i][X_AXIS];
25 Real y = input[i][Y_AXIS];
31 int N = input.size ();
36 Real den = (N *sqx - sqr (sx));
39 programming_error ("minimise_least_squares (): Nothing to minimise");
41 *offset = N ? sy / N : 0.0;
45 *coef = (N *sxy - sx * sy) / den;
46 *offset = (sy - (*coef) * sx) / N;