1 #include "leastsquares.hh"
5 Least_squares::OK() const
7 assert (input
.size() > 1);
9 for (int i
=1; i
< input
.size(); i
++)
10 dx
+= abs (input
[i
-1][X_AXIS
] - input
[i
][X_AXIS
]);
16 Least_squares::minimise (Real
&coef
, Real
&offset
)
23 for (int i
=0; i
< input
.size();i
++)
25 Real x
=input
[i
][X_AXIS
];
26 Real y
= input
[i
][Y_AXIS
];
37 Real den
= (N
*sqx
- sqr (sx
));
39 programming_error ("Least_squares::minimise(): Nothing to minimise");
40 coef
= (N
* sxy
- sx
*sy
)/den
;
41 offset
= (sy
- coef
* sx
)/N
;