Last active
March 30, 2019 09:45
-
-
Save nilforooshan/b22419e8d6c87f418f74486eaa6a8cb5 to your computer and use it in GitHub Desktop.
f90: Define the type of sampling. Give the set and sample sizes and find the number of possibilities and the probability for each possibility *.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 smpl_prob | |
| ! Declarations | |
| INTEGER:: i, k, m, n, o, p, s, po | |
| INTEGER::a, b, c=1, d, e, f=1, g, h, l=1 | |
| REAL:: pr | |
| CHARACTER(1):: exiit | |
| ! 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 the type of sampling | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Please define the type of sampling.' | |
| PRINT*, | |
| PRINT*, 'Examples:' | |
| PRINT*, 'Coin-tossing is a sampling with replacement.' | |
| PRINT*, 'In an order independent sampling "AB" and "BA" are the same.' | |
| PRINT*, | |
| PRINT*, '- with replacement and order dependent (press 1)' | |
| PRINT*, '- with replacement and order independent (press 2)' | |
| PRINT*, '- without replacement and order dependent (press 3)' | |
| PRINT*, '- without replacement and order independent (press 4)' | |
| PRINT*, 'Press any other key to exit.' | |
| READ*, s | |
| IF ((s/=1) .AND. (s/=2) .AND. (s/=3) .AND. (s/=4)) STOP | |
| ! Ask the input values | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Set size?' | |
| PRINT*, 'e.g., in coin-tossing, no matter how many times' | |
| PRINT*, 'you repeat it, the set size is equal to 2.' | |
| READ*, n | |
| 45 PRINT*, | |
| PRINT*, | |
| PRINT*, 'Sample size?' | |
| PRINT*, 'e.g., in coin-tossing, it is the number of times you toss the coin.' | |
| READ*, m | |
| PRINT*, | |
| PRINT*, | |
| o=n-m | |
| IF ((s>2) .AND. (o<0)) THEN | |
| PRINT*, 'In a sampling without replacement,' | |
| PRINT*, 'the set size should be greater than the sample size.' | |
| GO TO 45 | |
| END IF | |
| ! Estimate the factorials | |
| a=n | |
| d=o | |
| g=m | |
| IF (s>2) THEN | |
| DO i=1,n/2 | |
| b=a*(a-1) | |
| c=c*b | |
| a=a-2 | |
| END DO | |
| DO i=1,o/2 | |
| e=d*(d-1) | |
| f=f*e | |
| d=d-2 | |
| END DO | |
| END IF | |
| ! n!=c | |
| ! (n-m)!=f | |
| IF (s==4) THEN | |
| DO i=1,m/2 | |
| h=g*(g-1) | |
| l=l*h | |
| g=g-2 | |
| END DO | |
| END IF | |
| ! m!=l | |
| ! Calculate the number of possibilities and probilities | |
| IF (s==1) THEN | |
| po=n**m | |
| END IF | |
| IF (s==2) THEN | |
| k=n | |
| p=0 | |
| po=0 | |
| DO i=1,n | |
| p=i*(k**(m-2)) | |
| po=po+p | |
| k=k-1 | |
| END DO | |
| WRITE(*,*) 'Possibilities=',po | |
| PRINT*, 'Probabilities are different for different possibilities.' | |
| STOP | |
| END IF | |
| IF (s==3) THEN | |
| po=c/f | |
| END IF | |
| IF (s==4) THEN | |
| po=c/(f*l) | |
| END IF | |
| pr=1/REAL(po) | |
| ! Print the results on the screen | |
| WRITE(*,*) 'Possibilities=',po | |
| WRITE(*,*) 'Probability =',pr | |
| ! Finished | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Press any key to exit.' | |
| READ*, exiit | |
| IF (exiit=='a') THEN | |
| GO TO 138 | |
| END IF | |
| 138 END PROGRAM smpl_prob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment