Welcome to the L3 Harris Geospatial documentation center. Here you will find reference guides and help documents.
﻿

LINFITEX

LINFITEX

## Author

Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
craigm@lheamail.gsfc.nasa.gov
UPDATED VERSIONs can be found on my WEB PAGE:
http://cow.physics.wisc.edu/~craigm/idl/idl.html

## Purpose

Model function for fitting line with errors in X and Y

## Major Topics

Curve and Surface Fitting

## Calling Sequence

parms = MPFIT('LINFITEX', start_parms, \$
FUNCTARGS={X: X, Y: Y, SIGMA_X: SIGMA_X, SIGMA_Y: SIGMA_Y}, \$
...)

## Description

LINFITEX is a model function to be used with MPFIT in order to
fit a line to data with errors in both "X" and "Y" directions.
LINFITEX follows the methodology of Numerical Recipes, in the
section entitled, "Straight-Line Data with Errors in Both
Coordinates."
The user is not meant to call LINFITEX directly. Rather, the
should pass LINFITEX as a user function to MPFIT, and MPFIT will in
turn call LINFITEX.
Each data point will have an X and Y position, as well as an error
in X and Y, denoted SIGMA_X and SIGMA_Y. The user should pass
these values using the FUNCTARGS convention, as shown above. I.e.
the FUNCTARGS keyword should be set to a single structure
containing the fields "X", "Y", "SIGMA_X" and "SIGMA_Y". Each
field should have a vector of the same length.
Upon return from MPFIT, the best fit parameters will be,
P - Y-intercept of line on the X=0 axis.
P - slope of the line
NOTE that LINFITEX requires that AUTODERIVATIVE=1, i.e. MPFIT
should compute the derivatives associated with each parameter
numerically.

## Inputs

P - parameters of the linear model, as described above.

## Keyword Inputs

(as described above, these quantities should be placed in
a FUNCTARGS structure)
X - vector, X position of each data point
Y - vector, Y position of each data point
SIGMA_X - vector, X uncertainty of each data point
SIGMA_Y - vector, Y uncertainty of each data point

## Returns

Returns a vector of residuals, of the same size as X.

## Example

; X and Y values
XS = [2.9359964E-01,1.0125043E+00,2.5900450E+00,2.6647639E+00,3.7756164E+00,4.0297413E+00,4.9227958E+00,6.4959011E+00]
YS = [6.0932738E-01,1.3339731E+00,1.3525699E+00,1.4060204E+00,2.8321848E+00,2.7798350E+00,2.0494456E+00,3.3113062E+00]

; X and Y errors
XE = [1.8218818E-01,3.3440986E-01,3.7536234E-01,4.5585755E-01,7.3387712E-01,8.0054945E-01,6.2370265E-01,6.7048335E-01]
YE = [8.9751285E-01,6.4095122E-01,1.1858428E+00,1.4673588E+00,1.0045623E+00,7.8527629E-01,1.2574003E+00,1.0080348E+00]
; Best fit line
p = mpfit('LINFITEX', [1d, 1d], \$
FUNCTARGS={X: XS, Y: YS, SIGMA_X: XE, SIGMA_Y: YE}, \$
perror=dp, bestnorm=chi2)
yfit = p + p*XS

## References

Press, W. H. 1992, *Numerical Recipes in C*, 2nd Ed., Cambridge
University Press

## Modification History

Written, Feb 2009
Documented, 14 Apr 2009, CM

© 2020 Harris Geospatial Solutions, Inc. |  Legal