PROGRAM BT2_5 PARAMETER (NMAX=100) DIMENSION X(NMAX) INTEGER NAM(NMAX),N,I,K REAL G(4),T(4) OPEN(1,FILE='C:\MASTER\G_TR\BAITAP~1\NEW\BANG3.TXT') READ(1,*) READ(1,*) READ(1,*)N READ(1,*)((NAM(I),X(I)), I=1,N) DO K=1,4 G(K)=BMMGOC(X,N,K) T(K)=BMMTAM(X,N,K) ENDDO WRITE(*,*)' CAC MOMEN TINH BANG PHUONG PHAP PHAN NHOM' WRITE(*,*)' BAC ',' MOMEN GOC ',' MOMEN TAM ' DO K=1,4 WRITE(*,'(I5,2F20.3)') K, G(K), T(K) ENDDO END FUNCTION BMMGOC(X,N,K) ! HAM NAY TINH MOMEN GOC BANG PHUONG PHAP PHAN NHOM ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC MOMEN ! OUTPUT: MOMEN GOC BAC K ! FUNCTION/SUBROUTINE DUOC GOI TOI: ! FREQ(X,N,XC,FR,F,NFR,M,XMIN,STEP,INTERVAL) ! INTEGER N,M,I REAL X(N), XC(N), NFR(N), FR(N),F(N) REAL XMIN,STEP, TMP CALL FREQ(X,N,XC,FR,F,NFR,M,XMIN,STEP,0) TMP=0.0 DO I=1,M TMP=TMP+NFR(I)*XC(I)**K ENDDO BMMGOC=TMP/REAL(N) RETURN END FUNCTION BMMTAM(X,N,K) ! HAM NAY TINH MOMEN TRUNG TAM BANG PHUONG PHAP PHAN NHOM ! INPUT: + + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC MOMEN ! OUTPUT: MOMEN TRUNG TAM BAC K ! FUNCTION/SUBROUTINE DUOC GOI TOI: ! FREQ(X,N,XC,FR,F,NFR,M,XMIN,STEP,INTERVAL) ! REAL X(N), XC(N), NFR(N), FR(N),F(N) INTEGER N,M,I REAL XMIN,STEP, TMP,TBC CALL FREQ(X,N,XC,FR,F,NFR,M,XMIN,STEP,0) TBC=0.0 DO I=1,M TBC=TBC+NFR(I)*XC(I) ENDDO TBC=TBC/REAL(N) DO I=1,M XC(I)=XC(I)-TBC TMP=TMP+NFR(I)*XC(I)**K ENDDO BMMTAM=TMP/REAL(N) RETURN END SUBROUTINE FREQ(X,N,XC,FR,F,NFR,M,XMIN,STEP,INTERVAL) C C CHUONG TRINH NAY TINH TAN SO (NFR) VA TAN SUAT (FR) C CUA MANG X DO DAI N. C INPUT: + MANG X CHUA GIA TRI QUAN TRAC CUA BIEN NGAU NHIEN C + N LA DUNG LUONG MAU C + INTERVAL = 0 NEU LAY SO KHOANG CHIA NGAM DINH C = 1 NEU TU CHON SO KHOANG CHIA C OUTPUT: + M LA SO KHOANG CHIA, KHI INTERVAL = 0 THI C M = 5*LOG10(N) C + XC MANG DO DAI M CHUA TRI SO TRUNG GIAN CUA CAC KHOANG C + NFR MANG DO DAI M CHUA TAN SO CAC NHOM C + FR MANG DO DAI M CHUA TAN SUAT TICH LUY CAC NHOM (HAM PHAN BO) C + F MANG DO DAI M CHUA MAT DO XAC SUAT CAC NHOM C + XMIN GIOI HAN DUOI CUA NHOM THU NHAT (<=MIN{X(I)} C + STEP BUOC CHIA C REAL X(1),NFR(1),FR(1),XC(1),F(1) INTEGER N,INTERVAL,M REAL XMIN,XMAX,STEP CHARACTER ST*10 C IF (INTERVAL.EQ.0) THEN M=5*LOG10(REAL(N)) ELSE 10 WRITE(*,'(A\)') ' CHO SO KHOANG: ' READ*, ST READ(ST,*,ERR=100) M GOTO 101 100 PRINT*,' INVALID NUMERIC INPUT ! AGAIN...' GOTO 10 101 CONTINUE ENDIF C C XAC DINH MAX, MIN CUA CHUOI DE TIM GIOI HAN CAC NHOM XMIN=X(1) XMAX=X(1) DO I=2,N IF (X(I).LT.XMIN) XMIN=X(I) IF (X(I).GT.XMAX) XMAX=X(I) ENDDO C XMIN=AINT(XMIN) IF (XMIN.LT.0.0) XMIN=XMIN-1.0 XMAX=AINT(XMAX) IF (XMAX.GT.0.0) XMAX=AINT(XMAX)+1.0 C STEP=(XMAX-XMIN)/REAL(M) C NEU MUON CHON BUOC TRON SO THI THEM DONG LENH SAU C STEP=AINT(STEP)+1 C C TINH XC XC(1)=XMIN+STEP/2.0 DO J=2,M XC(J)=XC(J-1)+STEP ENDDO C TINH TAN SO CAC KHOANG VA HAM PHAN BO, HAM MAT DO STEP=STEP/2.0 DO J=1,M NFR(J)=0.0 DO I=1,N IF ((X(I).GE.XC(J)-STEP).AND.(X(I).LT.XC(J)+STEP)) THEN NFR(J)=NFR(J) + 1 ENDIF ENDDO FR(J)=NFR(J)/REAL(N) ENDDO STEP=STEP*2.0 DO J=M,1,-1 F(J)=FR(J)/STEP TEMP=0.0 DO K=1,J TEMP=TEMP+FR(K) ENDDO FR(J)=TEMP ENDDO RETURN END