!********************************************************************** !* Program by: Dr. D. Bala Subrahamanyam; E-mail: subbu_dbs@yahoo.com * !* Last modified: October 29, 2005 * !*********************************************************************** !* Subroutine for getting the linear fit for a dataset (x,y) for n no. * !* Input to the subroutine : * !* X (i), i = 1, n * !* Y (i), i = 1, n * !* n = no. of data points * !* Output of the subroutine (Y = mX + C) : * !* m = slope of the curve (Represented as 'am' in the program * !* c = intercept of the curve in Y-axis * !************************************************************************ Subroutine linear_fit (x, y, n, am, c) Dimension x(n), y(n) sigmaxy = 0. sigmax = 0. sigmay = 0. sigmax2 = 0. sigmay2 = 0. Do i = 1, n sigmaxy = sigmaxy + (x(i)*y(i)) sigmax = sigmax + x(i) sigmay = sigmay + y(i) sigmax2 = sigmax2 + (x(i)*x(i)) sigmay2 = sigmay2 + (y(i)*y(i)) Enddo am1 = (n*sigmaxy) - (sigmax*sigmay) am2 = (n*sigmax2) - (sigmax*sigmax) am = am1/am2 c = (sigmay - (am*sigmax))/float(n) Return End