PROGRAM BT4_16 PARAMETER (NMAX=100) REAL X(NMAX),NFR(NMAX),FR(NMAX),XC(NMAX),F(NMAX) INTEGER N,INTERVAL,M,I REAL XMIN,STEP,MUY,XICMA, A,B, PLT(NMAX) REAL ETA,ALFA,ETALFA CHARACTER*15 H0,H1,ANSWER1 DATA H0,H1 /'CHAP NHAN H0','BAC BO H0'/ DATA ALFA /0.05/ OPEN(1,FILE='C:\MASTER\G_TR\BAITAP~1\NEW\BANG12.TXT') READ(1,*) READ(1,*) READ(1,*)N READ(1,*)(X(I), I=1,N) ! TINH TRUNG BINH VA DO LECH CHUAN MUY=AMMGOC(X,N,1) XICMA=SQRT(AMMTAM(X,N,2)) ! TINH TAN SO THUC NGHIEM (NFR) INTERVAL=0 CALL FREQ(X,N,XC,FR,F,NFR,M,XMIN,STEP,INTERVAL) ! TINH TAN SO LY THUYET TU PHAN BO CHUAN STEP=STEP/2.0 DO I=1,M A=XC(I)-STEP B=XC(I)+STEP PLT(I)=ANORMD(MUY,XICMA,A,B) PLT(I)=PLT(I)*REAL(N) ENDDO ! TINH ETA ETA=0.0 DO I=1,M ETA=ETA+(NFR(I)-PLT(I))**2/PLT(I) ENDDO ! TINH ETA-ALFA ETALFA=CHINV(ALFA,REAL(M-2-1)) IF (ABS(ETA).LT.ETALFA) THEN ANSWER1=H0 ELSE ANSWER1=H1 ENDIF WRITE(*,*)' KET QUA KIEM NGHIEM KHI-BINH PHUONG ', & ' H0: PHAN BO THUC NGHIEM PHU HOP VOI PHAN BO CHUAN' WRITE(*,'(" N = ",I10)') N WRITE(*,'(" SO NHOM = ",I10)') M WRITE(*,'(" ETA = ",F10.3)') ETA WRITE(*,'(" ETA-ALFA = ",F10.3)') ETALFA WRITE(*,'(" KET LUAN: ",A15)') ANSWER1 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.0*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 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 FUNCTION CHINV(P,N) ! HAM NAY TINH GIA TRI X0 CUA BIEN NGAU NHIEN X PHAN BO ! "KHI BINH PHUONG" 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: 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 PRINT*,P,A,B,C 10 P0=CHIDIST(B,N) SS=ABS((P0-AP)/AP) SS1=ABS((B-C)/B) PRINT*,'P0=',P0,' SS=',SS,' B=',B,' C=',C 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 ANORMD(AMUY,XICMA,A,B) ! HAM NAY TINH XAC SUAT DE BIEN NGAU NHIEN PHAN BO CHUAN ! NHAN GIA TRI TRONG KHOANG (A,B): P(A