PROGRAM BT5_4 PARAMETER (NMAX=100,MMAX=6) DIMENSION X(NMAX*MMAX) DIMENSION R(MMAX*MMAX),RC(MMAX*MMAX) CHARACTER VARNAME(6)*2, ANSWER(2)*16,ANS*16 REAL ALFA DATA VARNAME /'X1','X2','X3','Y1','Y2','Y3'/ DATA ANSWER /'LON RO RET','KHONG LON RO RET'/ DATA ALFA /0.05/ OPEN(1,FILE='C:\MASTER\G_TR\BAITAP~1\NEW\BANG2.TXT') READ(1,*) READ(1,*) READ(1,*) N,M DO I=1,N L=(M-1)*N+I READ(1,*) TMP, (X(J),J=I,L,N) ENDDO CALL CORRE(X,N,M,R) TALFA=TINV(ALFA,REAL(N-2)) WRITE(*,*)'KET QUA KIEM NGHIEM DO RO RET CUA HE SO TUONG QUAN' WRITE(*,*) WRITE(*,'(" MUC Y NGHIA ALFA= ",F6.3)') ALFA DO J=1,M-1 DO K=(J-1)*M+J+1, J*M T=R(K)*SQRT(REAL(N-2))/SQRT(1.0-R(K)**2) IF (T.GT.TALFA) THEN ANS=ANSWER(1) ELSE ANS=ANSWER(2) ENDIF L=MOD(K,M) IF (L.EQ.0) L=6 WRITE(*,300) VARNAME(J),VARNAME(L),R(K),ANS ENDDO ENDDO 300 FORMAT(' R(',A2,'-',A2,')=',F7.4,'==>',A17) END !++++++++++++++++++++++ SUBROUTINE CORRE(X,N,M,R) ! CHUONG TRINH NAY TINH MA TRAN TUONG QUAN CHUAN HOA ! CUA TAP M BIEN TU SO LIEU BAN DAU CO DUNG LUONG N ! INPUT: + X MANG MOT CHIEU KICH THUOC N*M LUU TRU SO ! LIEU BAN DAU DANG MA TRAN N HANG M COT ! (X(1,1), X(2,1),...,X(N,1),X(1,2),...) ! + N DUNG LUONG MAU ! + M SO BIEN ! OUTPUT: + R MANG MOT CHIEU KICH THUOC M*M LUU TRU MA TRAN ! TUONG QUAN CHUAN HOA CUA M BIEN ! DIMENSION X(N*M),XX(N,M),R(M*M),TB(M),SX(M) K=0 DO J=1,M TB(J)=0.0 SX(J)=0.0 DO I=1,N K=K+1 TB(J)=TB(J)+X(K) SX(J)=SX(J)+X(K)*X(K) XX(I,J)=X(K) ENDDO TB(J)=TB(J)/REAL(N) SX(J)=SQRT(SX(J)/REAL(N)-TB(J)*TB(J)) ! PRINT*,TB(J),SX(J) ENDDO JK=0 DO J=1,M DO K=1,M JK=JK+1 R(JK)=0.0 DO I=1,N R(JK)=R(JK)+XX(I,J)*XX(I,K) ENDDO R(JK)=R(JK)/REAL(N)-TB(J)*TB(K) R(JK)=R(JK)/(SX(J)*SX(K)) ENDDO ENDDO RETURN END FUNCTION TINV(P,N) ! HAM NAY TINH GIA TRI X0 CUA BIEN NGAU NHIEN X PHAN BO ! STUDENT VOI N BAC TU DO THOA MAN DIEU KIEN ! P(|X|>X0)=P. ! INPUT: + P XAC SUAT DE |X|>X0 (P(|X|>X0)=P) ! + N SO BAC TU DO, PHAI LA MOT SO THUC ! OUTPUT: X0 ! SUBROUTINE/FUNCTION DUOC GOI TOI: TDIST PARAMETER (EPS=1.0E-5) REAL P,AP,N, A,B,C,P0 IF (P.LT.0.0.OR.P.GT.1.0) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN AKBPINV FUNCTION' STOP ENDIF IF (P.EQ.0.0) THEN WRITE(*,*)' THE P VALUE TOO SMALL IN AKBPINV FUNCTION' STOP ELSE IF (P.EQ.1) THEN WRITE(*,*)' THE P VALUE TOO BIG IN AKBPINV FUNCTION' STOP ENDIF ! A=0.0 B=99999.0 ! C=A AP=P 10 P0=TDIST(B,N) SS=ABS((P0-AP)/AP) SS1=ABS((B-C)/B) IF (SS.GE.EPS.AND.SS1.GE.EPS) THEN IF (AP.GT.P0) THEN C=B B=(A+B)/2.0 GOTO 10 ELSE IF (AP.LT.P0) THEN B=(C+B)/2.0 GOTO 10 ENDIF ENDIF A=(C+B)/2.0 TINV=A RETURN END FUNCTION TDIST(X0,N) ! HAM NAY TINH XAC SUAT DE BIEN NGAU NHIEN X CO PHAN BO STUDENT ! VOI N BAC TU DO NHAN GIA TRI NGOAI KHOANG (-X0;X0): ! P=P(|X|>X0)=1-P(|X|