lsqufit - function to perform a least squares fit to data (linear or exponential).
void lsqufit( float x[], float y[], int npts, int isw1, float *slope, float *intercept, float *lsqe, float *r2 )
Basic Seismic Utilities (BSU) function performs least squares fit to (x,y) data. One may choose a straight line or exponential fit. That is,
y=slope*x + intercept
or
y=A*exp(slope*x)
where the usual log (base e) transformation is performed:
log(y)=slope*x + log(A)
The quality of
the fit is given by the coefficient of determination, r2
(0<r2<1). A good fit will have r2-->1. A bad fit
will have r2-->0. Here, good or bad refer to how well the
data follow the data model (straight line).
C-language version.
Arguments
x[] (float)
Independent variable
y[] (float)
Dependent variable
npts (int)
Number of samples
isw1 (int)
Switch to select type of fit
0=straight line
1=exponential
*slope (float)
Pointer to slope determined by fit.
*intercept (float)
Pointer to intercept determined by fit.
*lsqe (float)
Pointer to least squares error of fit
*r2 (float)
Pointer to coefficient of determination 0<r2<1
NOTE: |
For an example, see this function used in bgaz.c |
bgaz(1)
No known bugs
Copyright © 2024 by Paul Michaels
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 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., 675 Mass Ave, Cambridge, MA 02139, USA.
P. Michaels, PE. <[email protected]>