]> git.mxchange.org Git - simgear.git/blob - simgear/math/leastsqs.hxx
Update a few more instances of my email address.
[simgear.git] / simgear / math / leastsqs.hxx
1 /**
2  * \file leastsqs.hxx
3  * Implements a simple linear least squares best fit routine.
4  */
5
6 // Written by Curtis Olson, started September 1997.
7 //
8 // Copyright (C) 1997  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA  02111-1307, USA.
24 //
25 // $Id$
26
27
28 #ifndef _LEASTSQS_H
29 #define _LEASTSQS_H
30
31
32 #ifndef __cplusplus                                                          
33 # error This library requires C++
34 #endif                                   
35
36
37 /**
38 Classical least squares fit:
39
40 \f[
41     y = b_0 + b_1 * x
42 \f]
43
44 \f[
45     b_1 = \frac{n * \sum_0^{i-1} (x_i*y_i) - \sum_0^{i-1} x_i* \sum_0^{i-1} y_i}
46           {n*\sum_0^{i-1} x_i^2 - (\sum_0^{i-1} x_i)^2}
47 \f]
48
49 \f[
50     b_0 = \frac{\sum_0^{i-1} y_i}{n} - b_1 * \frac{\sum_0^{i-1} x_i}{n}
51 \f]
52 */
53 void least_squares(double *x, double *y, int n, double *m, double *b);
54
55
56 /**
57  * Incrimentally update existing values with a new data point.
58  */
59 void least_squares_update(double x, double y, double *m, double *b);
60
61
62 /**
63   @return the least squares error:.
64 \f[
65
66     \frac{(y_i - \hat{y}_i)^2}{n}
67 \f]
68 */
69 double least_squares_error(double *x, double *y, int n, double m, double b);
70
71
72 /**
73   @return the maximum least squares error.
74
75 \f[
76     (y_i - \hat{y}_i)^2
77 \f]
78 */
79 double least_squares_max_error(double *x, double *y, int n, double m, double b);
80
81
82 #endif // _LEASTSQS_H
83
84