FUNCTION AVER(X,N) C... HAM NAY TINH TRUNG BINH SO HOC CUA CHUOI C INPUT: + X MANG DO DAI N CHUA SO LIEU QUAN TRAC C + N DUNG LUONG MAU C OUTPUT: TRUNG BINH SO HOC CUA X C 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 c FUNCTION P_LOWER(X,N,X0) C... HAM NAY TINH UOC LUONG XAC SUAT CUA SU KIEN C... P(X= K LA NHUNG SO NGUYEN ! OUTPUT: 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 POSSION(LAMDA,K) ! HAM NAY TINH XAC SUAT SU KIEN XUAT HIEN K LAN THEO POSSION ! INPUT: + LAMDA TRUNG BINH SO LAN XUAT HIEN ! + K SO LAN XUA HIEN SU KIEN ! OUTPUT: XAC SUAT DE SU KIEN XUAT HIEN K LAN ! REAL LAMDA POSSION=EXP(-LAMDA)*LAMDA**K/FAC(K) 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 PROB1(FR,XC,M,X0) C C HAM NAY TINH UOC LUONG XAC SUAT P(XX0)=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: CHIDIST PARAMETER (EPS=1.0E-6) 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 CHINV=0.0 RETURN ELSE IF (P.EQ.1) THEN WRITE(*,*)' THE P VALUE TOO BIG IN AKBPINV FUNCTION' STOP ENDIF ! A=0.0 B=9999999.0 C=A AP=P 10 P0=CHIDIST(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 CHINV=A RETURN END FUNCTION CHIDIST(X0,N) ! HAM NAY TINH XAC SUAT P=P(X>0) VOI X LA BIEN NGAU NHIEN ! CO PHAN BO "KHI BINH PHUONG" VOI N BAC TU DO. ! INPUT: + X0 MOT GIA TRI NAO DO CUA X ! + N BAC TU DO ! OUTPUT: P=P(X>X0) ! SUBROUTINE/FUNCTION DUOC GOI TOI: GAMMQ REAL X0,N CHIDIST=GAMMQ(N/2.0,X0/2.0) RETURN END FUNCTION gammq(a,x) REAL a,gammq,x !CU USES gcf,gser REAL gammcf,gamser,gln if(x.lt.0..or.a.le.0.)pause 'bad arguments in gammq' if(x.lt.a+1.)then call gser(gamser,a,x,gln) gammq=1.-gamser else call gcf(gammcf,a,x,gln) gammq=gammcf endif return END SUBROUTINE gcf(gammcf,a,x,gln) INTEGER ITMAX REAL a,gammcf,gln,x,EPS,FPMIN PARAMETER (ITMAX=100,EPS=3.e-7,FPMIN=1.e-30) !CU USES gammln INTEGER i REAL an,b,c,d,del,h,gammln gln=gammln(a) b=x+1.-a c=1./FPMIN d=1./b h=d do 11 i=1,ITMAX an=-i*(i-a) b=b+2. d=an*d+b if(abs(d).lt.FPMIN)d=FPMIN c=b+an/c if(abs(c).lt.FPMIN)c=FPMIN d=1./d del=d*c h=h*del if(abs(del-1.).lt.EPS)goto 1 11 continue pause 'a too large, ITMAX too small in gcf' 1 gammcf=exp(-x+a*log(x)-gln)*h return END SUBROUTINE gser(gamser,a,x,gln) INTEGER ITMAX REAL a,gamser,gln,x,EPS PARAMETER (ITMAX=100,EPS=3.e-7) !CU USES gammln INTEGER n REAL ap,del,sum,gammln gln=gammln(a) if(x.le.0.)then if(x.lt.0.)pause 'x < 0 in gser' gamser=0. return endif ap=a sum=1./a del=sum do 11 n=1,ITMAX ap=ap+1. del=del*x/ap sum=sum+del if(abs(del).lt.abs(sum)*EPS)goto 1 11 continue pause 'a too large, ITMAX too small in gser' 1 gamser=sum*exp(-x+a*log(x)-gln) return END FUNCTION gammln(xx) REAL gammln,xx INTEGER j DOUBLE PRECISION ser,stp,tmp,x,y,cof(6) SAVE cof,stp DATA cof,stp/76.18009172947146d0,-86.50532032941677d0, & 24.01409824083091d0,-1.231739572450155d0,.1208650973866179d-2, & -.5395239384953d-5,2.5066282746310005d0/ x=xx y=x tmp=x+5.5d0 tmp=(x+0.5d0)*log(tmp)-tmp ser=1.000000000190015d0 do 11 j=1,6 y=y+1.d0 ser=ser+cof(j)/y 11 continue gammln=tmp+log(stp*ser/x) 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-6) 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 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|X0)=P. ! INPUT: + P XAC SUAT DE X>X0 (P(X>X0)=P) ! + N1 VA N2 LA SO BAC TU DO, PHAI LA NHUNG SO THUC ! OUTPUT: X0 ! SUBROUTINE/FUNCTION DUOC GOI TOI: FDIST PARAMETER (EPS=1.0E-6) REAL P,AP,N1,N2, A,B,C,P0,SS,SS1 IF (P.LT.0.0.OR.P.GT.1.0) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN FINV FUNCTION' STOP ENDIF IF (P.EQ.0.0) THEN WRITE(*,*)' THE P VALUE TOO SMALL IN FINV FUNCTION' STOP ELSE IF (P.EQ.1) THEN FINV=0.0 RETURN ENDIF ! A=0.0 B=9999999.0 C=A AP=P 10 P0=FDIST(B,N1,N2) 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 FINV=A RETURN END FUNCTION FDIST(X0,N1,N2) ! HAM NAY TINH XAC SUAT DE BIEN NGAU NHIEN X CO PHAN BO FISHER ! VOI N1 VA N2 BAC TU DO NHAN GIA TRI >X0: ! P=P(X>X0)=1-P(X R1 R(M*M) ! + M KICH THUOC MA TRAN TUONG QUAN, DONG THOI CUNG LA ! SO BIEN DUOC XET ! + J,K CHI SO BIEN DUOC TINH TUONG QUAN RIENG ! OUTPUT: HE SO TUONG QUAN RIENG GIUA BIEN THU J VA THU K ! DIMENSION R(M*M),RT(M*M) RT=R RJK=PPDS(RT,M,J,K) RT=R RJJ=PPDS(RT,M,J,J) RT=R RKK=PPDS(RT,M,K,K) HSTQR=-RJK/(SQRT(RJJ*RKK)) RETURN END FUNCTION HSTQB(R,M,J) ! HAM NAY TINH HE SO TUONG QUAN BOI GIUA BIEN XJ VA TAP HOP ! M-1 BIEN X1,X2,X(J-1),X(J+1),..,XM ! INPUT: + R MANG MOT CHIEU CHUA MA TRAN TUONG QUAN CHUAN HOA ! (KICH THUOC M*M ==> R(M*M) ! + M KICH THUOC MA TRAN TUONG QUAN, DONG THOI CUNG LA ! SO BIEN DUOC XET ! + J CHI SO BIEN DUOC TINH TUONG QUAN BOI VOI TAP M-1 ! BIEN CON LAI ! OUTPUT: HE SO TUONG QUAN BOI GIUA BIEN THU J VA CAC BIEN KHAC ! DIMENSION R(M*M),RT(M*M) RT=R RJJ=PPDS(RT,M,J,J) RT=R RR=DET(RT,M) HSTQB=SQRT(1-RR/RJJ) RETURN END