|
LeastSqX
LeastSqX
provides powerful linear and non-linear least squares algorithms with an
easy one-minute learning curve interface. Write your own function for fitting
and pass the function name to the control, or simply rely on the default
general polynomial function.
To use LeastSqX, simply make
a single call to the FitData method defined by the control. This call includes
passing the number of data points, degrees of freedom to fit, array of
independent variables (e.g., time), array of dependent variables (e.g.,
measurements), array of uncertainties of these measurements (may be all
set to 0 for non-weighted fitting), function name (or 0 for a general polynomial
fit), and initial guess of the coefficients if supplied user fitting function
is non-linear. Upon return, the coefficients are replaced by the fit values.
Also returned are the one sigma uncertainties of the fit, along with the
Chisq value.
Example implementations included
with the control demonstrate linear and non-linear fitting, plus a simple
demonstration of how to use LeastSqX to perform multidimensional fitting
(e.g., z as a function of both x and y).
LeasySqX1.FitData (
numpoints As Long, numco As Long, xd As Double, yd As Double, sigd As Double,
userfunc As Long, co As Double, stddev As Double, ChiSquare As Double) As Long
|
A
simple least squares example:
Private Sub Perform_Fit()
Static xd(100) As Double, yd(100) As Double, sigd(100)
As Double
Static co(4) As Double, std(4) As Double
Dim ma As Long, npt As Long
Dim chisq as double
npt = 20 ' number of data points
ma = 3 ' degrees of freedom
‘ make up some example data
For i = 0 To npt - 1
xd (i) = i
yd (i) = 3.2 + 2.1
* xd (i) - 1.7 * xd (i) ^ 2 + 200# * Rnd
Next i
'Least Squares Call.
' Upon return the fitted coeffs are returned in co(0),
co(1), and co(2),
' and their uncertainties are returned in std(0),
std(1), and std(2).
call LeastSqX1.FitData(npt, ma, xd(0), yd(0),
sigd(0), 0, co(0), std(0), chisq)
End sub |
 |
|