ccccccccccccccccccccccccc     Program 2.B     ccccccccccccccccccccccccccc
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c                                                                       c
c Please Note:                                                          c
c                                                                       c
c (1) This computer program is written by Tao Pang in conjunction with  c
c     his book, "An Introduction to Computational Physics," published   c
c     by Cambridge University Press in 1997.                            c
c                                                                       c
c (2) No warranties, express or implied, are made for this program.     c
c                                                                       c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      PROGRAM MILL
C
C Program to fit the Millikan experimental data to a linear
C curve p(x) = a*x+b directly.  One can find a and b from
C partial D/partial a = 0 and partial D/partial b = 0 with
C D = sum (p(x_i)-f(x_i))**2.  The result is a = (c1*c3-
C c4*n)/(c1**2-c2*n) and b = (c1*c4-c2*c3)/(c1**2-c2*n) with
C n being the number of points, c1 = sum x_i, c2 = sum x_i**2,
C c3 = sum f(x_i), and c4 = sum x_i*f(x_i).
C Copyright (c) Tao Pang 1997.
C
      PARAMETER (N = 15)
      DIMENSION X(N),F(N)
      DATA X /4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,
     *        12.0,13.0,14.0,15.0,16.0,17.0,18.0/
      DATA F /6.558,8.206,9.880,11.50,13.14,14.81,16.40,18.04,
     *        19.68,21.32,22.96,24.60,26.24,27.88,29.52/
C
      C1 = 0.0
      C2 = 0.0
      C3 = 0.0
      C4 = 0.0
      DO    100   I = 1, N
        C1 = C1 + X(I)
        C2 = C2 + X(I)*X(I)
        C3 = C3 + F(I)
        C4 = C4 + F(I)*X(I)
  100 CONTINUE
      C = C1*C1-C2*N
      A = (C1*C3-C4*N)/C
      B = (C1*C4-C2*C3)/C
      WRITE (6,999) A,ABS(B)
      STOP
  999 FORMAT ('The fundamental charge is ' F6.4, '+-' F6.4)
      END
