X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=blobdiff_plain;f=lily%2Fleastsquares.cc;h=ab718a97f76bca922a7deed174a2836cbdb00469;hb=13e79c0250d34b6bdfbafbc551ef64e8b59b2991;hp=7f274bf4d19ca04ed146666050a12f02e304c70a;hpb=cf393d97985570aaf254a48785ad6eaa737ee4f0;p=lilypond.git diff --git a/lily/leastsquares.cc b/lily/leastsquares.cc index 7f274bf4d1..ab718a97f7 100644 --- a/lily/leastsquares.cc +++ b/lily/leastsquares.cc @@ -2,23 +2,24 @@ void Least_squares::OK() const { - assert (input.size() > 1); - Real dx = 0.0; - for (int i=1; i < input.size(); i++) + assert (input.size() > 1); + Real dx = 0.0; + for (int i=1; i < input.size(); i++) dx += abs (input[i-1].x() - input[i].x ()); - assert (dx); + assert (dx); } void Least_squares::minimise (Real &coef, Real &offset) { - OK(); - Real sx = 0.0; - Real sy = 0.0; - Real sqx =0.0; - Real sxy = 0.0; + OK(); + Real sx = 0.0; + Real sy = 0.0; + Real sqx =0.0; + Real sxy = 0.0; - for (int i=0; i < input.size();i++) { + for (int i=0; i < input.size();i++) + { Real x=input[i].x(); Real y = input[i].y(); sx += x; @@ -26,10 +27,10 @@ Least_squares::minimise (Real &coef, Real &offset) sqx += sqr (x); sxy += x*y; } - int N = input.size(); - + int N = input.size(); + - coef = (N * sxy - sx*sy)/(N*sqx - sqr (sx)); - offset = (sy - coef * sx)/N; + coef = (N * sxy - sx*sy)/(N*sqx - sqr (sx)); + offset = (sy - coef * sx)/N; }