PROGRAM BT5_11 DIMENSION X(100),Y(100) OPEN(1,FILE='C:\MASTER\G_TR\BaiTap~1\New\BANG15.TXT') READ(1,*) READ(1,*) N READ(1,*) ((X(I),Y(I)),I=1,N) R=HSTQ(X,Y,N) ETA=TYSOTQ(X,Y,N) WRITE(*,*)' TY SO TUONG QUAN = ',ETA WRITE(*,*)' HE SO TUONG QUAN = ',R END FUNCTION HSTQ(X,Y,N) ! HAM NAY TINH HE SO TUONG QUAN GIUA HAI BIEN X VA Y ! INPUT: + X MANG MOT CHIEU KICH THUOC N CHUA SO LIEU CUA X ! + Y MANG MOT CHIEU KICH THUOC N CHUA SO LIEU CUA Y ! + N DUNG LUONG MAU ! OUTPUT: HE SO TUONG QUAN R GIUA X VA Y ! DIMENSION X(N),Y(N) TBX=0.0 TBY=0.0 SX=0.0 SY=0.0 RXY=0.0 DO I=1,N TBX=TBX+X(I) TBY=TBY+Y(I) SX=SX+X(I)*X(I) SY=SY+Y(I)*Y(I) RXY=RXY+X(I)*Y(I) ENDDO TBX=TBX/REAL(N) TBY=TBY/REAL(N) SX=SQRT(SX/REAL(N)) SY=SQRT(SY/REAL(N)) RXY=RXY/REAL(N)-TBX*TBY HSTQ=RXY/SX/SY RETURN END FUNCTION TYSOTQ(X,Y,N) ! CHUONG TRINH NAY TINH TY SO TUONG QUAN GIUA HAI BIEN X VA Y ! INPUT: + X MANG MOT CHIEU KICH THUOC N CHUA SO LIEU CUA X ! + Y MANG MOT CHIEU KICH THUOC N CHUA SO LIEU CUA Y ! + N DUNG LUONG MAU ! OUTPUT: TY SO TUONG QUAN ETA GIUA X VA Y ! DIMENSION X(N),Y(N),TSO(N/2,N/2) DIMENSION XC(N/2),YC(N/2),TSX(N/2),TSY(N/2),A(N/2) LOGICAL LX,LY XMIN=X(1) XMAX=X(1) YMIN=Y(1) YMAX=Y(1) DO I=2,N IF (X(I).LT.XMIN) XMIN=X(I) IF (X(I).GT.XMAX) XMAX=X(I) IF (Y(I).LT.YMIN) YMIN=Y(I) IF (Y(I).GT.YMAX) YMAX=Y(I) ENDDO XMIN=1.0*INT(XMIN) YMIN=1.0*INT(YMIN) XMAX=1.0*INT(XMAX)+1.0 YMAX=1.0*INT(YMAX)+1.0 NSTEP=INT(5.0*LOG10(REAL(N)))+1 STEPX=(XMAX-XMIN)/REAL(NSTEP) STEPY=(YMAX-YMIN)/REAL(NSTEP) ! TINH BANG PHAN BO TAN SO HAI CHIEU (TSO) DO KX=1,NSTEP AX=XMIN+REAL(KX-1)*STEPX BX=AX+STEPX DO KY=1,NSTEP AY=YMIN+REAL(KY-1)*STEPY BY=AY+STEPY TSO(KX,KY)=0.0 DO I=1,N LX=(X(I).GE.AX).AND.(X(I).LT.BX) LY=(Y(I).GE.AY).AND.(Y(I).LT.BY) IF (LX.AND.LY) THEN TSO(KX,KY)=TSO(KX,KY)+1.0 ENDIF ENDDO ENDDO ENDDO XMIN=XMIN-STEPX/2.0 YMIN=YMIN-STEPY/2.0 ! TINH CAC TRI SO GIUA CUA X (XC) VA Y (YC) DO KX=1,NSTEP XC(KX)=XMIN+REAL(KX)*STEPX TSX(KX)=0.0 DO KY=1,NSTEP TSX(KX)=TSX(KX)+TSO(KX,KY) ENDDO ENDDO DO KY=1,NSTEP YC(KY)=YMIN+REAL(KY)*STEPY TSY(KY)=0.0 DO KX=1,NSTEP TSY(KY)=TSY(KY)+TSO(KX,KY) ENDDO ENDDO ! WRITE(*,*)HSTQ(XC,YC,NSTEP) ! WRITE(*,'(" ",12F5.1)')(XC(I),I=1,NSTEP) ! DO I=1,NSTEP ! WRITE(*,'(F7.2,12F5.0)')YC(I),(TSO(I,J),J=1,NSTEP) ! ENDDO ! TINH CAC A(I) DO KX=1,NSTEP A(KX)=0.0 DO KY=1,NSTEP A(KX)=A(KX)+TSO(KX,KY)*YC(KY) ENDDO ENDDO ! TINH D,B,C D=0.0 B=0.0 C=0.0 DO KX=1,NSTEP D=D+(A(KX)**2)/TSX(KX) ENDDO DO KY=1,NSTEP B=B+TSY(KY)*YC(KY) C=C+TSY(KY)*YC(KY)**2 ENDDO ! TINH TY SO TUONG QUAN B=B**2/REAL(N) ETA=(D-B)/(C-B) TYSOTQ=ETA RETURN END