Inform me () when using this script or encorporating it in a library.
Source code of forcefit.pro:
;+
; NAME:
; FORCEFIT
; PURPOSE:
; Force a fit in either slope or zero-point of a line
; CALLING SEQUENCE:
; result = FORCEFIT([x, y[,a=a][,b=b]][/help])
; EXAMPLES:
; x = dindgen(100)
; y = dindgen(100)
; result = FORCEFIT(x, y, a=2)
; fits a line of slope 2 to the input values
; result = FORCEFIT(x, y)
; normal linear fit using the LINFIT
; KEYWORDS:
; x = the input x values
; y = the input y values
; a = the fixed slope
; b = the fixed zero-point
; /help = displays this help
; MODIFICATION HISTORY:
; before 27/08/04 written by Eduard Westra
; 27/08/04 added help header by Eduard Westra
; 31/10/06 added the case for b being set
;-
FUNCTION forcefit, x, y, a=a, b=b, help=help
IF (KEYWORD_SET(HELP)) THEN BEGIN & doc_library,'forcefit' & RETURN, [0.,0.] & ENDIF
IF (N_ELEMENTS(a) EQ 1 AND N_ELEMENTS(b) EQ 1) THEN BEGIN
PRINT, "You already set both parameters. What do you want me to do?!?"
RETURN, [b,a]
ENDIF
IF N_ELEMENTS(a) EQ 1 THEN BEGIN
div = a*x
div = y - div
RETURN, [TOTAL(div)/N_ELEMENTS(div),a]
ENDIF
IF N_ELEMENTS(b) EQ 1 THEN BEGIN
; implement later
a = TOTAL(y)/TOTAL(x)
;a = TOTAL(x*y)/TOTAL(x*x)
RETURN, [b, a]
ENDIF
; no a and b set
RETURN, LINFIT(x, y)
END