X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2Fleastsqs.hxx;h=3889cf7a3e15bdc1a4f5a9cea63dd7f33d843fff;hb=ce54997be569ebcac4222321e7ae3fecccd01324;hp=af7bdb351893956e9ee38e923e6965ea729f4aa9;hpb=82459a2802a939434f9fc5b88d2b2aea58f0043d;p=simgear.git diff --git a/simgear/math/leastsqs.hxx b/simgear/math/leastsqs.hxx index af7bdb35..3889cf7a 100644 --- a/simgear/math/leastsqs.hxx +++ b/simgear/math/leastsqs.hxx @@ -1,8 +1,11 @@ -// leastsqs.h -- Implements a simple linear least squares best fit routine -// +/** + * \file leastsqs.hxx + * Implements a simple linear least squares best fit routine. + */ + // Written by Curtis Olson, started September 1997. // -// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -14,57 +17,63 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ -/// #ifndef _LEASTSQS_H #define _LEASTSQS_H -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif - +#endif -/* -Least squares fit: -y = b0 + b1x +/** +Classical least squares fit: - n*sum(xi*yi) - (sum(xi)*sum(yi)) -b1 = -------------------------------- - n*sum(xi^2) - (sum(xi))^2 +\f[ + y = b_0 + b_1 * x +\f] +\f[ + b_1 = \frac{n * \sum_0^{i-1} (x_i*y_i) - \sum_0^{i-1} x_i* \sum_0^{i-1} y_i} + {n*\sum_0^{i-1} x_i^2 - (\sum_0^{i-1} x_i)^2} +\f] -b0 = sum(yi)/n - b1*(sum(xi)/n) +\f[ + b_0 = \frac{\sum_0^{i-1} y_i}{n} - b_1 * \frac{\sum_0^{i-1} x_i}{n} +\f] */ - void least_squares(double *x, double *y, int n, double *m, double *b); -/* incrimentally update existing values with a new data point */ + +/** + * Incrimentally update existing values with a new data point. + */ void least_squares_update(double x, double y, double *m, double *b); -/* - return the least squares error: +/** + @return the least squares error:. +\f[ - (y[i] - y_hat[i])^2 - ------------------- - n + \frac{(y_i - \hat{y}_i)^2}{n} +\f] */ double least_squares_error(double *x, double *y, int n, double m, double b); -/* - return the maximum least squares error: +/** + @return the maximum least squares error. - (y[i] - y_hat[i])^2 +\f[ + (y_i - \hat{y}_i)^2 +\f] */ double least_squares_max_error(double *x, double *y, int n, double m, double b);