PROGRAM BT2_9 PARAMETER (NMAX=100,MMAX=6,KMAX=4) DIMENSION X(NMAX,MMAX),XX(NMAX) INTEGER N,I,K REAL G(MMAX,KMAX),T(MMAX,KMAX) OPEN(1,FILE='C:\MASTER\G_TR\BAITAP~1\NEW\BANG8.TXT') READ(1,*) READ(1,*) READ(1,*) N,M DO I=1,N READ(1,*) TMP, (X(I,J),J=1,M) ENDDO DO 100 J=1,M ! BAT DAU CHU TRINH TINH CHO TUNG BIEN DO I=1,N XX(I)=X(I,J) ENDDO DO K=1,KMAX G(J,K)=AMMGOC(XX,N,K) T(J,K)=AMMTAM(XX,N,K) ENDDO 100 CONTINUE WRITE(*,*)' CAC MOMEN TINH BANG PHUONG PHAP TRUC TIEP' WRITE(*,*)' MOMEN GOC ' WRITE(*,'(" BAC",6(" X",I1))')(J,J=1,M) DO K=1,KMAX WRITE(*,'(I4,6F10.1)') K, (G(J,K),J=1,M) ENDDO WRITE(*,*)' MOMEN TRUNG TAM ' WRITE(*,'(" BAC",6(" X",I1))')(J,J=1,M) DO K=2,KMAX WRITE(*,'(I4,6F10.4)') K, (T(J,K),J=1,M) ENDDO END FUNCTION AMMGOC(X,N,K) ! ! HAM NAY TINH MOMEN GOC BAC K CUA CHUOI SO LIEU ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC CUA MOMEN ! OUTPUT: MOMEN GOC BAC K ! DIMENSION X(N) INTEGER N,K,I REAL TMP TMP=0.0 DO I=1,N TMP=TMP+X(I)**K ENDDO AMMGOC=TMP/REAL(N) RETURN END FUNCTION FAC(N) ! TINH N! (N GIAI THUA) REAL TMP IF (N.LT.0) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN FAC FUNCTION' STOP ELSE IF (N.EQ.0.OR.N.EQ.1) THEN FAC=1.0 RETURN ELSE TMP=1.0 DO I=2,N TMP=TMP*REAL(I) ENDDO FAC=TMP RETURN ENDIF END FUNCTION COMBIN(N,K) ! TINH TO HOP CHAP K CUA N ! FUNCTION/SUBROUTINE DUOC GOI TOI: FAC(N) IF (N.LT.0.OR.K.LT.0.OR.N.LT.K) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN COMBIN FUNCTION' STOP ELSE COMBIN=FAC(N)/FAC(K)/FAC(N-K) RETURN ENDIF END FUNCTION AMMTAM(X,N,K) ! HAM NAY TINH MOMEN TRUNG TAM BAC K TU CHUOI SO LIEU X ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC CUA MOMEN ! OUTPUT: MOMEN TRUNG TAM BAC K ! FUNCTION/SUBROUTINE DUOC GOI TOI: AMMGOC(X,N,K), COMBIN(N,K) DIMENSION X(N) INTEGER N,K,I REAL TMP,TB TB=AMMGOC(X,N,1) TMP=0 DO I=0,K TMP=TMP+(-1)**I*COMBIN(K,I)*TB**I*AMMGOC(X,N,K-I) ENDDO AMMTAM=TMP RETURN END