: help lsq2 Macro: variable number of arguments (3 <= narg <= 6) # do a least squares fit to a set of vectors, errors in x and y # syntax: lsq2 x y lambda [ x2 y2 [rms] ] # Fit line y2=$a*x2+$b to x y, assuming that the errors # in x and y are uncorrelated and sigma_y^2/sigma_x^2 = lambda. # Optionally, calculate rms residual as $rms # See lsq for the case where all the errors are in x or y, # rxy to find product moment correlation coeff, # and spear for Spearman's corr. coeff. and significance SET _n = DIMEN($1) # number of points SET _mx = SUM($1)/_n # x bar SET _my = SUM($2)/_n # y bar SET $0$1 = $1 - _mx # relative to mean SET $0$2 = $2 - _my SET _sxx = SUM($0$1*$0$1) # sigma xx SET _sxy = SUM($0$1*$0$2) # sigma xy SET _syy = SUM($0$2*$0$2) # sigma yy DEFINE a ( (_syy - $3*_sxx + \ sqrt((_syy - $3*_sxx)**2 + 4*$3*_sxy**2))/(2*_sxy) ) DEFINE b ( _my - $a*_mx ) IF($?4 && $?5) { SET $5=$a*$4+$b IF($?6) { DEFINE $6 ( sqrt(sum(($a*$1 + $b - $2)**2)/dimen($2)) ) } } FOREACH v ( _n _mx _my _sxx _sxy _syy ) { DELETE $v }