PROGRAM BT2_1 PARAMETER (NMAX=100) DIMENSION X(NMAX),X1(NMAX),CHISO(NMAX) INTEGER NAM(NMAX), N,N1,I,J REAL Q50,Q25,Q75, TB REAL ALFA,TRIMEAN,TBHC,IQR,MAD,SHC,YULKED OPEN(1,FILE='C:\MASTER\G_TR\BAITAP~1\NEW\BANG1.TXT') READ(1,*) READ(1,*) READ(1,*)N READ(1,*)((NAM(I),X(I)), I=1,N) ! TINH TRUNG BINH SO HOC (TB) TB = AVER(X,N) ! SAP XEP CHUOI THANH CHUOI TRINH TU (X) VA CHUOI XEP HANG (X1) CALL SORT(X,N,X1,CHISO,N1) WRITE(*,*) ' CHUOI TRINH TU' WRITE(*,'(10F7.1)') (X(I),I=1,N) WRITE(*,*) ' CHUOI XEP HANG VA CHI SO PHAN TU' ! WRITE(*,'(10F6.1)') (X1(I),I=1,N1) ! WRITE(*,'(10F6.1)') (CHISO(I),I=1,N1) WRITE(*,*) ' TRUNG BINH SO HOC' WRITE(*,'(" TB = ",F6.1)') TB ! TINH CAC PHAN VI CALL QUANTILES(X,N,Q50,Q25,Q75) WRITE(*,*) WRITE(*,'(" TRUNG VI = ",F7.1)') Q50 WRITE(*,'(" PHAN VI DUOI = ",F7.1)') Q25 WRITE(*,'(" PHAN VI TREN = ",F7.1)') Q75 END FUNCTION AVER(X,N) C... CHUONG TRINH NAY TINH TRUNG BINH SO HOC CUA CHUOI C... DU LIEU VAO LA MANG X DO DAI N CHUA SO LIEU QUAN TRAC C... CUA BIEN NGAU NHIEN X INTEGER N, I REAL X(N) ! MANG CHUA SO LIEU BAN DAU REAL TMP TMP = 0.0 DO I = 1,N TMP = TMP + X(I) END DO AVER = TMP/REAL(N) RETURN END SUBROUTINE SORT(X,N,X1,CHISO,N1) ! ! CHUONG TRINH NAY SAP XEP CHUOI THANH CHUOI TRINH TU ! VA CHUOI XEP HANG ! ! INPUT: + MANG X DO DAI N CHUA CHUOI SO LIEU BAN DAU ! + N DUNG LUONG MAU ! OUTPUT: + MANG X DO DAI N CHUA CHUOI TRINH TU ! + MANG X1 DO DAI N1 CHUA CHUOI XEP HANG ! + MANG CHISO DO DAI N1 CHUA CHI SO CUA CHUOI XEP HANG ! + N1 SO THANH PHAN TRONG CHUOI XEP HANG ! DIMENSION X(1),X1(1),CHISO(1) INTEGER N,N1,I,J,K REAL TMP ! SAP XEP THANH CHUOI TRINH TU TANG DAN DO I=1,N-1 DO J=I+1,N IF (X(J).LT.X(I)) THEN TMP=X(J) X(J)=X(I) X(I)=TMP ENDIF ENDDO ENDDO ! XAC DINH CAC THANH PHAN CUA CHUOI XEP HANG N1=1 I=1 X1(N1)=X(I) CHISO(N1)=REAL(I) 10 I=I+1 IF (I.GT.N) GOTO 100 IF (X(I).NE.X(I-1)) THEN N1=N1+1 X1(N1)=X(I) ENDIF GOTO 10 100 CONTINUE ! TINH CHI SO CUA CAC THANH PHAN TRONG CHUOI XEP HANG DO J=1,N1 K=0 CHISO(J)=0.0 DO I=1,N IF (X(I).EQ.X1(J)) THEN K=K+1 CHISO(J)=CHISO(J)+REAL(I) ENDIF ENDDO CHISO(J)=CHISO(J)/REAL(K) ENDDO RETURN END FUNCTION Q05(X,N) ! ! HAM NAY TINH TRUNG VI CUA CHUOI X ! INPUT: + X LA MANG SO LIEU DA SAP XEP THANH CHUOI TRINH TU ! + N LA DO DAI CUA X (DUNG LUONG MAU) ! OUTPUT: + TRUNG VI CUA CHUOI ! DIMENSION X(N) INTEGER N,I,NC NC=N/2 IF (MOD(N,2).EQ.0) THEN Q05=(X(NC)+X(NC+1))/2.0 ELSE Q05=X(NC+1) ENDIF RETURN END SUBROUTINE QUANTILES(X,N,Q50,Q25,Q75) ! ! CHUONG TRINH NAY TINH CAC PHAN VI CHINH CUA CHUOI X DO DAI N ! ! INPUT: + X MANG CHUA CHUOI SO LIEU DA SAP XEP TRINH TU ! + N DUNG LUONG MAU ! OUTPUT: + TRUNG VI Q50 ! + CAC PHAN VI DUOI VA TREN Q25, Q75 ! FUNCTION/SUBROUTINE DUOC GOI TOI: Q05(X,N) ! DIMENSION X(N), X1(N) INTEGER N,I,NC1,NC2,NT,J REAL Q50,Q25,Q75 Q50=Q05(X,N) NT=N NC1=NT/2 IF (MOD(NT,2).EQ.0) THEN NC2=NC1+1 ELSE NC1=NC1+1 NC2=NC1 ENDIF DO I=1,NC1 X1(I)=X(I) ENDDO Q25=Q05(X1,NC1) J=0 DO I=NC2,N J=J+1 X1(J)=X(I) ENDDO Q75=Q05(X1,NC1) RETURN END