cauran(3f) - [M_datapac:RANDOM] generate Cauchy random numbers
SUBROUTINE CAURAN(N,Iseed,X)
INTEGER,intent(in) :: N
INTEGER,intent(inout) :: Iseed
REAL(kind=wp),intent(out) :: X(:)
CAURAN(3f) generates a random sample of size N from the Cauchy
distribution with median = 0 and 75% point = 1.
This distribution is defined for all X and has the probability
density function
f(X) = (1/pi)*(1/(1+X*X))
N The desired integer number of random numbers to be generated.
ISEED An integer seed value. Should be set to a non-negative value to start a new sequence of values. Will be set to -1 on return to indicate the next call should continue the current random sequence walk.
X A vector (of dimension at least N) into which the generated
random sample of size N function value for the Cauchy
distribution will be placed.
Sample program:
program demo_cauran
use m_datapac, only : cauran, plott, label, plotxt, sort
implicit none
integer,parameter :: n=100
real :: x(n)
integer :: iseed
call label('cauran')
iseed=12345
call cauran(n,iseed,x)
write(*,*)x
call plotxt(x,n)
call sort(x,n,x) ! sort to show distribution
call plotxt(x,n)
end program demo_cauran
Results:
THE FOLLOWING IS A PLOT OF X(I) (VERTICALLY) VERSUS I (HORIZONTALLY
I-----------I-----------I-----------I-----------I
0.8386762E+02 - X
0.7943768E+02 I
0.7500773E+02 I
0.7057778E+02 I
0.6614783E+02 I
0.6171789E+02 I
0.5728794E+02 -
0.5285799E+02 I
0.4842804E+02 I
0.4399810E+02 I
0.3956815E+02 I
0.3513820E+02 I
0.3070825E+02 -
0.2627831E+02 I
0.2184836E+02 I
0.1741841E+02 I
0.1298846E+02 I X X
0.8558517E+01 I X X X
0.4128571E+01 - X X X X X X XX XX
-0.3013763E+00 I XXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX
-0.4731323E+01 I XX X X X X XX X X
-0.9161270E+01 I
-0.1359122E+02 I X
-0.1802116E+02 I
-0.2245111E+02 - X X X
I-----------I-----------I-----------I-----------I
0.1000E+01 0.2575E+02 0.5050E+02 0.7525E+02 0.1000E+03
THE FOLLOWING IS A PLOT OF X(I) (VERTICALLY) VERSUS I (HORIZONTALLY
I-----------I-----------I-----------I-----------I
0.8386762E+02 - X
0.7943768E+02 I
0.7500773E+02 I
0.7057778E+02 I
0.6614783E+02 I
0.6171789E+02 I
0.5728794E+02 -
0.5285799E+02 I
0.4842804E+02 I
0.4399810E+02 I
0.3956815E+02 I
0.3513820E+02 I
0.3070825E+02 -
0.2627831E+02 I
0.2184836E+02 I
0.1741841E+02 I
0.1298846E+02 I XX
0.8558517E+01 I XX
0.4128571E+01 - XXXXX
-0.3013763E+00 I XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-0.4731323E+01 I XXXXXX
-0.9161270E+01 I
-0.1359122E+02 I X
-0.1802116E+02 I
-0.2245111E+02 - XX
I-----------I-----------I-----------I-----------I
0.1000E+01 0.2575E+02 0.5050E+02 0.7525E+02 0.1000E+03
The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.
John Urban, 2022.05.31
CC0-1.0
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | N | |||
integer, | intent(inout) | :: | Iseed | |||
real(kind=wp), | intent(out) | :: | X(:) |
SUBROUTINE CAURAN(N,Iseed,X) INTEGER,intent(in) :: N INTEGER,intent(inout) :: Iseed REAL(kind=wp),intent(out) :: X(:) REAL(kind=wp) :: arg , pi INTEGER :: i DATA pi/3.14159265359_wp/ ! ! CHECK THE INPUT ARGUMENTS FOR ERRORS ! IF ( N<1 ) THEN WRITE (G_IO,99001) 99001 FORMAT (' ***** FATAL ERROR--The first input argument to CAURAN(3f) is non-positive *****') WRITE (G_IO,99002) N 99002 FORMAT (' ***** The value of the argument is ',I0,' *****') RETURN ELSE ! ! GENERATE N UNIFORM (0,1) RANDOM NUMBERS; ! CALL UNIRAN(N,Iseed,X) ! ! GENERATE N CAUCHY RANDOM NUMBERS ! USING THE PERCENT POINT FUNCTION TRANSFORMATION METHOD. ! DO i = 1 , N arg = pi*X(i) X(i) = -COS(arg)/SIN(arg) ENDDO ENDIF END SUBROUTINE CAURAN