2 least-squares.cc -- implement minimise_least_squares
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "least-squares.hh"
14 minimise_least_squares (Real *coef, Real *offset,
15 vector<Offset> const &input)
22 for (vsize i = 0; i < input.size ();i++)
24 Real x = input[i][X_AXIS];
25 Real y = input[i][Y_AXIS];
32 int count = input.size ();
37 Real den = (count * sqx - sqr (sx));
40 programming_error ("minimise_least_squares (): Nothing to minimise\n"
41 "This means that vertical spacing is triggered\n"
42 "before line breaking\n");
44 *offset = count ? sy / count : 0.0;
48 *coef = (count * sxy - sx * sy) / den;
49 *offset = (sy - (*coef) * sx) / count;