Last active
March 30, 2019 09:40
-
-
Save nilforooshan/bc7f2d5a39273a3a96a4d4b4f7267a7a to your computer and use it in GitHub Desktop.
f90: Insert a random variable (x) from a normal distribution with mean (mu) and standard deviation (std) and get the zscore and Prob(Z =< zscore) (i.e. the area under the curve). *.exe and *.out are the Windows and Linux executables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PROGRAM ztest | |
| IMPLICIT NONE | |
| ! Declarations | |
| REAL:: x, mu, std, pi=3.1416 | |
| REAL:: y, z, erf, cdf, gausserf | |
| CHARACTER(1):: exiit | |
| ! 2.Opening prints | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'This program is written by Mohammad A. Nilforooshan.' | |
| PRINT*, 'All rights reserved.' | |
| PRINT*, 'http://sites.google.com/site/mannprofile/' | |
| ! Ask for the input values | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, ' (x - mu)' | |
| PRINT*, 'z = --------' | |
| PRINT*, ' std ' | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Insert the following values.' | |
| PRINT*, 'x =' | |
| READ*, x | |
| PRINT*, 'mu =' | |
| READ*, mu | |
| PRINT*, 'std =' | |
| READ*, std | |
| ! Estimate z value | |
| z=(x-mu)/std | |
| ! Predefinitions for extreme z values | |
| IF (-3.04 > z) THEN | |
| PRINT*, | |
| PRINT*, | |
| WRITE(*,'(A,1F8.4)') 'z = ',z | |
| WRITE(*,'(A,1F8.4,A)') 'P(z =< ',z,') < 0.001' | |
| STOP | |
| ELSE IF (3.04 < z) THEN | |
| PRINT*, | |
| PRINT*, | |
| WRITE(*,'(A,1F7.4)') 'z = ',z | |
| WRITE(*,'(A,1F7.4,A)') 'P(z =< ',z,') > 0.999' | |
| STOP | |
| ELSE | |
| CONTINUE | |
| END IF | |
| ! Calculations | |
| y=z/SQRT(2.) | |
| erf=gausserf(y) | |
| cdf=0.5*(1+erf) | |
| ! Print the results on the screen | |
| PRINT*, | |
| PRINT*, | |
| WRITE(*,'(A,1F7.4)') 'z = ',z | |
| WRITE(*,'(A,1F7.4,A,1F6.4)') 'P(z =< ',z,') = ',cdf | |
| ! Finished | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Press any key to exit.' | |
| READ*, exiit | |
| IF (exiit=='a') THEN | |
| GO TO 82 | |
| END IF | |
| 82 END PROGRAM ztest | |
| ! Introducing Gauss error function | |
| REAL FUNCTION gausserf(a) | |
| REAL:: a, pi=3.1416 | |
| gausserf=(0.0002/SQRT(pi))*((a/0.0001)-((a**3)/0.0003)+((a**5)/0.001) & | |
| -((a**7)/0.0042)+((a**9)/0.0216)-((a**11)/0.132)+((a**13)/0.936) & | |
| -((a**15)/7.56)+((a**17)/68.544)-((a**19)/689.472)+((a**21)/7620.48) & | |
| -((a**23)/91808.64)+((a**25)/1197504.)-((a**27)/16812956.16) & | |
| +((a**29)/252817044.5)) | |
| RETURN | |
| END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment