]> git.donarmstrong.com Git - lilypond.git/blob - src/leastsquares.cc
release: 0.0.24
[lilypond.git] / src / leastsquares.cc
1 #include "leastsquares.hh"
2
3 void
4 Least_squares::minimise(Real &coef, Real &offset)
5 {
6     Real sx = 0.0;
7     Real sy = 0.0;
8     Real sqx =0.0;
9     Real sxy = 0.0;
10
11     for (int i=0; i < input.size();i++) {
12         Real x=input[i].x;
13         Real y = input[i].y;
14         sx += x;
15         sy += y;
16         sqx += sqr(x);
17         sxy += x*y;
18     }
19     int N = input.size();
20     
21
22     coef = (N * sxy - sx*sy )/(N*sqx - sqr(sx));
23     offset = (sy - coef * sx)/N;
24         
25 }