>  Docs Center  >  Libraries  >  JBIU  >  JBLINFIT
Libraries

JBLINFIT

JBLINFIT

Name


    JBLINFIT

Purpose


    Performs least squares fitting to a straight line, but can perform it over
    one particular dimension for a multi-dimensional data set. Acts like the
    built-in function LINFIT if DIMENSION is not set.

Category


    Math

Calling Sequence


    Result = JBLINFIT(X, Y)

Inputs


    X: Array containing the independent variable values.
    Y: Array containing the dependent variable values.

Keyword Parameters


    DIMENSION: If X and Y are multi-dimensional arrays, perform the fitting
              accross this dimension.
    CHISQR: Output variable containing the chi squared values.
    COVAR: Output variable containing the covariance matrix.
    MEASURE_ERRORS: Array containing the measurement errors in Y.
    PROB: Output variable containing the probability of obtaining a fit
              with at least this chi squared value.
    SIGMA: Output variable containing uncertainties in fit parameters.
    YFIT: Output variable containing the values of the dependent variable at
              the X locations, according to the fit.

Outputs


    Returns the parameters of the linear fit. If X has dimensions [D1, D2, D3... DM],
    and DIMENSION=N, then Result has dimensions [2, D1...DN-1, DN+1...DM].
    Result[0,....] contains the constant term and Result[1,...] contains the slope.

Example


    seed = 43l
    n = 10000L
    x = 1e-3 * findgen(n)
    y1 = x + randomn(seed, n)
    y2 = 10. - 2 * x + 0.5 * randomn(seed, n)
    x = [[x],[x]]
    y = [[y1],[y2]]
   
    result = jblinfit(x, y, sigma=sigma, yfit=yfit, dimension=1)
   
    xax = [0,10]
    cgplot, psym=3, x, y1, yrange=minmax(y), color='red'
    cgplot, /overplot, psym=3, x, y2, color='blue'
    cgplot, /overplot, xax, result[0,0] + result[1,0]*xax, color='red'
    cgplot, /overplot, xax, result[0,1] + result[1,1]*xax, color='blue'
   
    cgtext, x[9000], yfit[9000,0] + 2, color='red', align=1, $
      string(result[0,0], sigma[0,0], result[1,0], sigma[1,0], $
      format='(%"y = (%0.2f +/- %0.2f) + (%0.3f +/- %0.3f) x")'), $
      charsize=1.5
    cgtext, x[9000], yfit[9000,1] - 3, color='blue', align=1, $
      string(result[0,1], sigma[0,1], result[1,1], sigma[1,1], $
      format='(%"y = (%0.2f +/- %0.2f) + (%0.3f +/- %0.3f) x")'), $
      charsize=1.5

Modification History


    Written by: Jeremy Bailin
    28 March 2011 Initial writing.



© 2024 NV5 Geospatial Solutions, Inc. |  Legal
My Account    |    Contact Us