1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| !
! this program gives the linear (average) equation giving the acceleration
! as a function of the voltage :
!
PROGRAM linearleast
IMPLICIT NONE
INTEGER :: i,j,nl,n
REAL :: x,y
!
! n is the number of rows in the data file
!
REAL,ALLOCATABLE,DIMENSION(n,2) :: A
!
! A is the matrix in which the datas will be stored
!
!
! interface bloc :
!
INTERFACE
SUBROUTINE coef(A,n,nl)
INTEGER,INTENT(INOUT) :: nl
REAL,INTENT(INOUT),ALLOCATABLE :: A(n,2)
END SUBROUTINE coef
END INTERFACE
OPEN (33,FILE='xydata.dat',form='formatted',status='old')
nl=0
10 READ (33,*,END=20) x,y
nl=nl+1
GO TO 10
20 REWIND (33)
! creation of the matrix A :
ALLOCATE (A(n,2))
DO i=1,nl
READ (33,*) (A(i,j),j=1,2)
END DO
CALL coef (A,n,nl)
DEALLOCATE (A)
END PROGRAM linearleast
!
SUBROUTINE coef (D,m,nl)
IMPLICIT NONE
INTEGER :: i,j,m,nl
REAL :: c,b,g,f,a,k,l
REAL,ALLOCATABLE :: D(m,2),E(nl),H(nl)
! c is the sum of the accelerations
c=0
ALLOCATE (D)
DO i=1,nl
c=c+D(i,1)
END DO
! b is the sum of the voltages
b=0
DO i=1,nl
b=b+D(i,2)
END DO
! g is the average coefficient (b/c)
g=b/c
! E contains the residuals
ALLOCATE (E)
DO i=1,nl
E(i)=D(i,2)-g*D(i,1)
END DO
! H contains the estimated voltages (the estimated Y)
ALLOCATE (H)
DO i=1,nl
H(i)=g*D(i,1)+H(i)
END DO
! k is the sum of the residuals
k=0
DO i=1,nl
k=k+E(i)
END DO
DEALLOCATE (D)
DEALLOCATE (E)
DEALLOCATE (H)
! l is the average residual
l=k/nl
PRINT 10, g,l
10 FORMAT (1X,'THE LINEAR EQUATION IS : Y(X)= ',F6.3,' X + ',F6.3)
PRINT *,'ORIGINAL ORIGINAL ESTIMATED RESIDUAL'
PRINT *,' X Y Y '
DO i=1,nl
PRINT 20, D(i,1),D(i,2),g*D(i,1)+l,E(i)
20 FORMAT (' ',F6.3,' ',F6.3,' ',F6.3,' ',F6.3)
END DO
END SUBROUTINE coef |
Partager