FUNCTION MSEmatch,x,y ;+ ;p=MSEmatch(x,y) provides a vector p=[a,b] such that ;mean-squared difference between x and (ay+b) is minimized. ;- IF N_PARAMS() LT 2 THEN Message,'Incorrect number of input vectors',/Error IF N_Elements(x) NE N_Elements(y) THEN $ Message,'Vectors must be of equal length',/Error ;Compute the various mean values needed to calculate the ;parameters n=N_Elements(x) xbar=Total(x)/n ybar=Total(y)/n xybar=Total(x*y)/n y2bar=Total(y^2)/n a=(xybar-xbar*ybar)/(y2bar-ybar^2) b=xbar-a*ybar Return,[a,b] END