Documentation for jbiu/

Generated by IDLdoc

single page | use frames     summary     class     fields     routine details     file attributes

math/

jblinfit.pro


top source jblinfit

Math

result = jblinfit(x, y, dimension=dimension, chisqr=chisqr, covar=covar, measure_errors=measure_errors, prob=prob, sigma=sigma, yfit=yfit)

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.

Return value

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.

Parameters

x in

Array containing the independent variable values.

y in

Array containing the dependent variable values.

Keywords

dimension in

If X and Y are multi-dimensional arrays, perform the fitting accross this dimension.

chisqr in

Output variable containing the chi squared values.

covar in

Output variable containing the covariance matrix.

measure_errors in

Array containing the measurement errors in Y.

prob in

Output variable containing the probability of obtaining a fit with at least this chi squared value.

sigma in

Output variable containing uncertainties in fit parameters.

yfit in

Output variable containing the values of the dependent variable at the X locations, according to the fit.

Examples

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

Author information

History:

Written by: Jeremy Bailin 28 March 2011 Initial writing.

File attributes

Modification date: Mon Mar 28 16:39:22 2011
Lines: 136