SCULIB_FIT_FUNCTION

routine to fit a general function to data

Description:

This routine fits a general function to a data-set by searching the chi-squared plane. Chi-squared at each test fit position will be evaluated by the external routine XISQ_ROUTINE. The data to be fit are passed to the external routine through common; see SCULIB_GAUSSIAN_XISQ for an example. Each call to the routine will generate one iteration of the search. On exit the fit should have an improved chi-squared that should be checked for convergence (i.e. has chi-squared changed by less than CHICUT between 2 iterations) before the routine is called again to perform the next iteration. It is recommended that the routine be entered for the first iteration with LAMBDA set to 0.001. Thereafter, the routine will return the value of LAMBDA to be used in the next iteration.

The search method used is that due to Marquardt as described in chapter 8 of ‘Data Reduction and Error Analysis’ by Bevington and Robinson. The code is an adaptation of the Pascal routine Marquardt listed in that book.

If the routine is entered with LAMBDA = 0 then it will return the ‘error’ matrix for the given fit parameters.

Invocation

CALL SCULIB_FIT_FUNCTION (XISQ_ROUTINE, CHICUT, N, A, LAMBDA, ALPHA, BETA, IK, JK, DA, STATUS)

Arguments

XISQ_ROUTINE (XISQ, N, A, STATUS) = EXTERNAL ROUTINE (Given)
routine to calculate chi-squared of fit
CHICUT = DOUBLE PRECISION (Given)
increase in chi-squared that will make routine search with larger LAMBDA
N = INTEGER (Given)
number of fitted parameters
A (N) = DOUBLE PRECISION (Given and returned)
the fitted parameters
LAMBDA = DOUBLE PRECISION (Given and returned)
curvature factor for alpha matrix
ALPHA (N,N) = DOUBLE PRECISION (Scratch)
storage for alpha array
BETA (N) = DOUBLE PRECISION (Scratch)
storage for beta array
IK (N) = INTEGER (Scratch)
used for inverting matrix
JK (N) = INTEGER (Scratch)
used for inverting matrix
DA (N) = DOUBLE PRECISION (Scratch)
increment in A
STATUS = INTEGER (Given and returned)
global status

Copyright

Copyright ©1995,1996,1997,1998,1999 Particle Physics and Astronomy Research Council. All Rights Reserved.

Method

If status is good on entry the routine will enter a loop

End of loop