SUB mathlinfit (n%, x!(), y!(), m!, b!) '**************************************************************************** 'This subroutine does a least squares linear fit to the (x,y) data points. 'It returns the slope and intercept of the line. ' 'Input: ' n%, the number of (x,y) points ' x!(1 to n%), the x values ' y!(1 to n%), the y values ' 'Output: ' m!, the fitted line's slope ' b!, the fitted line's intercept ' 'Zachary Wolf '5/12/94 '**************************************************************************** 'Compute various sums Sxy! = 0! Sxx! = 0! Sx! = 0! Sy! = 0! FOR i% = 1 TO n% Sxy! = Sxy! + x!(i%) * y!(i%) Sxx! = Sxx! + x!(i%) * x!(i%) Sx! = Sx! + x!(i%) Sy! = Sy! + y!(i%) NEXT i% 'Compute the determinant D! = n% * Sxx! - Sx! * Sx! 'Compute the slope and intercept m! = (Sxy! * n% - Sx! * Sy!) / D! b! = (Sxx! * Sy! - Sxy! * Sx!) / D! END SUB