simgear  3.5.0 [next] git://gitorious.org/fg/simgear.git
SimGear - Simulator Construction Tools
leastsqs.hxx File Reference

Go to the source code of this file.

Functions

void least_squares (double *x, double *y, int n, double *m, double *b)
 
double least_squares_error (double *x, double *y, int n, double m, double b)
 
double least_squares_max_error (double *x, double *y, int n, double m, double b)
 
void least_squares_update (double x, double y, double *m, double *b)
 

Detailed Description

Implements a simple linear least squares best fit routine.

Definition in file leastsqs.hxx.

Function Documentation

void least_squares ( double *  x,
double *  y,
int  n,
double *  m,
double *  b 
)

Classical least squares fit:

\[ y = b_0 + b_1 * x \]

\[ 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} \]

\[ b_0 = \frac{\sum_0^{i-1} y_i}{n} - b_1 * \frac{\sum_0^{i-1} x_i}{n} \]

Definition at line 46 of file leastsqs.cxx.

double least_squares_error ( double *  x,
double *  y,
int  n,
double  m,
double  b 
)
Returns
the least squares error:.

\[ \frac{(y_i - \hat{y}_i)^2}{n} \]

Definition at line 97 of file leastsqs.cxx.

double least_squares_max_error ( double *  x,
double *  y,
int  n,
double  m,
double  b 
)
Returns
the maximum least squares error.

\[ (y_i - \hat{y}_i)^2 \]

Definition at line 118 of file leastsqs.cxx.

void least_squares_update ( double  x,
double  y,
double *  m,
double *  b 
)

Incrimentally update existing values with a new data point.

Definition at line 71 of file leastsqs.cxx.