[Previous]
[Next]
NAME:
lsqCircleFit
PURPOSE:
Least square fitting a circle to a set of points
CATEGORY:
gen/idl/toolbox/math
CALLING SEQUENCE:
FUNCTION lsqCircleFit, x, y, chisq=chisq
INPUTS:
x array[n,m] or array[2,n,m]; type: any
m sets of n x-coordinates
if y is not specified than x must be of the form x[2,n,m]
with x[0,*,*] the x-values and x[1,*,*] the y-values.
y array[n,m]; type: any
m sets of n y-coordinates matching the x-array
OUTPUTS:
R array[3] or array[3,m]; type: float or double
x-coordinate and y-coordinate of center, followed by the radius
OPTIONAL OUTPUT PARAMETERS:
chisq=chisq
scalar or array[m]; type: float
residual 'chi-square' = sqrt ( sqrt( (1/N)*Sum( ((x-x0)^2+(y-y0)^2-R^2)^2 ) ) )
INCLUDE:
@compile_opt.pro ; On error, return to caller
CALLS: ***
SubArray, SyncArgs
CALLED BY:
even_light, even_light_corrections
PROCEDURE:
> If both x and y is specified than it is allowed to specify only one set of x-value
x[n] with multiple sets of y-values y[n,m]. Each of the sets of y-values is combined
with the set of x-values.
> Standard least square fit.
Each row in the input arrays x and y is fitted to a circle. A separate center and radius
is returned for each of the rows.
MODIFICATION HISTORY:
MAR-2000, Paul Hick (UCSD/CASS)
FEB-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu), added SyncArgs call.
[Previous]
[Next]
NAME:
lsqLinearFit
PURPOSE:
Least-squares fit of function of N independent variables
CATEGORY:
gen/idl/toolbox/math
CALLING SEQUENCE:
FUNCTION lsqLinearFit, f,x,y,z,t, $
yzero = yzero , $
unit = unit , $
torigin = torigin , $
weights = weights
INPUTS:
f array[n]; type: float
function values
f can be a time structure (see keywords unit and torigin)
OPTIONAL PARAMETERS:
x array[n] or array[m,n]; type: float; default: findgen(n)
array[n ]: n 1-dimensional position vectors
array[m,n]; n m-dimensional position vectors
If x is the only argument specified (i.e. y,z,t
are NOT present) then x can be a time structure
(see keywords unit and torigin)
y,z,t array[n] (same as x); type: float
n position vectors [x,y,z,t].
weights=weights
array[n] (same as x); type: float
weights for each data points
(usually proportional to the inverse of the variance)
/yzero fits to a linear function with no leading constant
(i.e. it fits to a linear function that goes through
the origin x=y=z=t=0)
The intercept Result[0] is explicitly set to zero
in this case.
torigin=torigin
array[1]; type: time structure; default: none
unit=unit scalar; type: integer; default: TimeUnit(/day)
if f and/or x are time structures then the lsq fit
is done using the specified time units relative
to time origin 'torigin'.
If torigin is not defined then it is defined
internally (as the earliest time specified in f
and x, truncated to time units of 'unit')
OUTPUTS:
Result array[m+1]; type: float
least-square fit parameters of the linear
function fitted to the points.
OPTIONAL PARAMETERS:
torigin=torigin
array[1]; type: time structure
If f and/or x are time structures and torigin
is not defined as input then the internally
defined value is returned here.
INCLUDE:
@compile_opt.pro ; On error, return to caller
CALLED BY:
smei_star_lsqfit
SEE ALSO:
circlefit, normalfit
CALLS: ***
InitVar, IsTime, IsType, MEAN, SuperArray, TimeGet, TimeLimits, TimeUnit
PROCEDURE:
For 1,2,3 and 4-dim fits the solution is evaluated directly
from analytic expressions. For higher dimensions a matrix
inversion is used.
MODIFICATION HISTORY:
FEB-2003, Paul Hick (UCSD/CASS)
SEP-2006, Paul Hick (UCSD/CASS)
Added /yzero.
DEC-2006, Paul Hick (UCSD/CASS)
Added keywords unit and torigin
MAY-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
Added weights keyword.
[Previous]
[Next]
NAME:
lsqNormalFit
PURPOSE:
Find least squares fit to a data series x,y
CATEGORY:
gen/idl/toolbox/math
CALLING SEQUENCE:
FUNCTION lsqNormalFit, xin, yin , $
plotx = plotx , $
oplotx = oplotx, $
worst = worst , $
xfit = xfit , $
yfit = yfit , $
_extra = _extra
INPUTS:
x,y arrays to be fitted
OPTIONAL INPUT PARAMETERS:
/plot data points and fit are plotted
/oplot the fit is plotted using the current user scale
/worst will also plot the worst possible fit
OUTPUTS:
A fltarr(5,2)
A[*,0] represents the best fit; A[*,1] represents the worst fit
The equation for the straight line fit:
A[0,i]*(x-A[1,i])+A[2,i]*(y-A[3,i]) = 0
A[1,i] is the average of the x-array
A[3,i] is the average of the y-array
A[4,i] is the residual average distance of the `normalized' data points to the fit.
INCLUDE:
@compile_opt.pro ; On error, return to caller
CALLS: ***
InitVar, POLY_FIT
CALLED BY:
even_light_info, qLine_FitPlot, vu_correlate, vu_insitucurve
PROCEDURE:
The x and y arrays are `normalized' by dividing the arrays by their
respective standard deviations. The resulting arrays are fitted by
minimizing the perpendicular distance to a straight line fit.
The result is symmetric: interchanging x and y arrays will give the same fit.
MODIFICATION HISTORY:
JUN-1994, Paul Hick (UCSD/CASS)
AUG-1999, Paul Hick (UCSD/CASS); added title keyword
APR-2000, Paul Hick (UCSD/CASS); added _extra keyword
FEB-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu); changed the main plotting command to
use the input arrays directly for plotting.
[Previous]
[Next]
NAME:
lsqQuadraticFit
PURPOSE:
Fits points to a quadratic polynomial
CATEGORY:
gen/idl/toolbox/math
CALLING SEQUENCE:
FUNCTION lsqQuadraticFit, x, y, chisq=chisq
INPUTS:
x array[n,m] or array[2,n,m]; type: any
m sequences of n x-coordinates
if m=1 then the last dimension may be absent
if y not specified then x must be of the form x[2,n,m] with
x[0,*,*] the x-values and x[1,*,*] the y-values
y array[n,m]; type: any
m sequences of n y-coordinates matching the x-array
OUTPUTS:
R array[3] or array[3,m]; type: double
the 3 fitted constants in
y = R[0]+R[1]*x+R[2]*x^2
OPTIONAL OUTPUT PARAMETERS:
chisq=chisq
scalar, or array[m]; type: double
residual chisq.
INCLUDE:
@compile_opt.pro ; On error, return to caller
CALLS: ***
IsType, SubArray, SyncArgs
CALLED BY:
even_light, even_light_corrections
PROCEDURE:
> If both x and y is called then it is allowed to specify only
one set of x-values, x[n] and multiple sets of y-values, y[n,m]
In that case each y-series is combined with x.
> The same can be accomplished with the IDL function poly_fit.
polyfit uses a matrix inversion; here we use the analytic solution.
MODIFICATION HISTORY:
JAN-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu)