@@ -4,38 +4,61 @@ program example_exponential_cdf
44 rexp = > rvs_exp
55
66 implicit none
7- real :: x(2 , 3 , 4 ), a(2 , 3 , 4 )
7+ real , dimension (2 , 3 , 4 ) :: x, lambda
8+ real :: xsum
89 complex :: scale
9- integer :: seed_put, seed_get
10+ integer :: seed_put, seed_get, i
1011
1112 seed_put = 1234567
1213 call random_seed (seed_put, seed_get)
1314
14- print * , exp_cdf(1.0 , 1.0 ) ! a standard exponential cumulative at 1.0
15+ ! standard exponential cumulative distribution at x=1.0
16+ print * , exp_cdf(1.0 , 1.0 )
17+ ! 0.632120550
1518
16- ! 0.632120550
19+ ! cumulative distribution at x=2.0 with lambda=2
20+ print * , exp_cdf(2.0 , 2.0 )
21+ ! 0.981684387
1722
18- print * , exp_cdf( 2.0 , 2.0 ) ! a cumulative at 2.0 with lambda=2
19-
20- ! 0.981684387
23+ ! cumulative distribution at x= 2.0 with lambda=-1.0 (out of range)
24+ print * , exp_cdf( 2.0 , - 1.0 )
25+ ! NaN
2126
27+ ! standard exponential random variates array
2228 x = reshape (rexp(0.5 , 24 ), [2 , 3 , 4 ])
23- ! standard exponential random variates array
24- a(:, :, :) = 0.5
25- print * , exp_cdf(x, a) ! a rank 3 array of standard exponential cumulative
2629
27- ! 8.57694745E-02 9.70223546E-02 1.52170658E-02 2.95336246E-02
28- ! 0.107568979 0.196659625 2.97447443E-02 0.366151094 0.163051903
29- ! 3.36527228E-02 0.385267735 0.428375721 0.103964329 0.147119939
30- ! 0.192206264 0.330693483 0.179247737 2.92580128E-02 0.332765043
31- ! 0.472417951 0.500440359 8.56802464E-02 8.72612000E-03 3.55126858E-02
30+ ! a rank-3 exponential cumulative distribution
31+ lambda(:, :, :) = 0.5
32+ print * , exp_cdf(x, lambda)
33+ ! 0.301409245 0.335173965 5.94930053E-02 0.113003314
34+ ! 0.365694344 0.583515942 0.113774836 0.838585377
35+ ! 0.509324908 0.127967060 0.857194781 0.893231630
36+ ! 0.355383813 0.470882893 0.574203610 0.799321830
37+ ! 0.546216846 0.111995399 0.801794767 0.922525287
38+ ! 0.937719882 0.301136374 3.44503522E-02 0.134661376
39+
40+ ! cumulative distribution array where lambda<=0.0 for certain elements
41+ print * , exp_cdf([1.0 , 1.0 , 1.0 ], [1.0 , 0.0 , - 1.0 ])
42+ ! 0.632120550 NaN NaN
43+
44+ ! `cdf_exp` is pure and, thus, can be called concurrently
45+ xsum = 0.0
46+ do concurrent (i= 1 :size (x,3 ))
47+ xsum = xsum + sum (exp_cdf(x(:,:,i), lambda(:,:,i)))
48+ end do
49+ print * , xsum
50+ ! 11.0886612
3251
52+ ! complex exponential cumulative distribution at (0.5,0.5) with real part of
53+ ! lambda=0.5 and imaginary part of lambda=1.0
3354 scale = (0.5 , 1.0 )
3455 print * , exp_cdf((0.5 , 0.5 ), scale)
35- ! complex exponential cumulative distribution at (0.5,0.5) with real part of
36- ! lambda=0.5 and imaginary part of lambda=1.0
56+ ! 8.70351046E-02
3757
38- ! 8.70351046E-02
58+ ! As above, but with lambda%im < 0
59+ scale = (1.0 , - 2.0 )
60+ print * , exp_cdf((1.5 , 1.0 ), scale)
61+ ! NaN
3962
4063end program example_exponential_cdf
4164
0 commit comments