@@ -4,41 +4,56 @@ program example_normal_pdf
4
4
norm = > rvs_normal
5
5
6
6
implicit none
7
- real :: x(3 , 4 , 5 ), a(3 , 4 , 5 ), b(3 , 4 , 5 )
7
+ real , dimension (3 , 4 , 5 ) :: x, mu, sigma
8
+ real :: xsum
8
9
complex :: loc, scale
9
- integer :: seed_put, seed_get
10
+ integer :: seed_put, seed_get, i
10
11
11
12
seed_put = 1234567
12
13
call random_seed (seed_put, seed_get)
13
14
14
- print * , norm_pdf( 1.0 , 0 ., 1 .) ! a probability density at 1.0 in standard normal
15
-
16
- ! 0.241970733
15
+ ! probability density at x= 1.0 in standard normal
16
+ print * , norm_pdf( 1.0 , 0 ., 1 .)
17
+ ! 0.241970733
17
18
19
+ ! probability density at x=2.0 with mu=-1.0 and sigma=2.0
18
20
print * , norm_pdf(2.0 , - 1.0 , 2.0 )
19
- ! a probability density at 2.0 with mu=-1.0 sigma=2.0
21
+ ! 6.47588000E-02
20
22
21
- ! 6.47588000E-02
23
+ ! probability density at x=1.0 with mu=1.0 and sigma=-1.0 (out of range)
24
+ print * , norm_pdf(1.0 , 1.0 , - 1.0 )
25
+ ! NaN
22
26
27
+ ! standard normal random variates array
23
28
x = reshape (norm(0.0 , 1.0 , 60 ), [3 , 4 , 5 ])
24
- ! standard normal random variates array
25
-
26
- a(:, :, :) = 0.0
27
- b(:, :, :) = 1.0
28
- print * , norm_pdf(x, a, b) ! standard normal probability density array
29
-
30
- ! 0.340346158 0.285823315 0.398714304 0.391778737 0.389345556
31
- ! 0.364551932 0.386712372 0.274370432 0.215250477 0.378006011
32
- ! 0.215760440 0.177990928 0.278640658 0.223813817 0.356875211
33
- ! 0.285167664 0.378533930 0.390739858 0.271684974 0.138273031
34
- ! 0.135456234 0.331718773 0.398283750 0.383706540
35
-
29
+
30
+ ! standard normal probability density array
31
+ mu(:, :, :) = 0.0
32
+ sigma(:, :, :) = 1.0
33
+ print * , norm_pdf(x, mu, sigma)
34
+ ! 0.340346158 0.285823315 0.398714304 0.391778737 0.389345556
35
+ ! 0.364551932 0.386712372 0.274370432 0.215250477 0.378006011
36
+ ! 0.215760440 0.177990928 0.278640658 0.223813817 0.356875211
37
+ ! 0.285167664 0.378533930 0.390739858 0.271684974 0.138273031
38
+ ! 0.135456234 0.331718773 0.398283750 0.383706540
39
+
40
+ ! probability density array where sigma<=0.0 for certain elements
41
+ print * , norm_pdf([1.0 , 1.0 , 1.0 ], [1.0 , 1.0 , 1.0 ], [1.0 , 0.0 , - 1.0 ])
42
+ ! 0.398942292 NaN NaN
43
+
44
+ ! `pdf_normal` is pure and, thus, can be called concurrently
45
+ xsum = 0.0
46
+ do concurrent (i= 1 :size (x,3 ))
47
+ xsum = xsum + sum (norm_pdf(x(:,:,i), mu(:,:,i), sigma(:,:,i)))
48
+ end do
49
+ print * , xsum
50
+ ! 18.0754433
51
+
52
+ ! complex normal probability density function at x=(1.5,1.0) with real part
53
+ ! of mu=1.0, sigma=1.0 and imaginary part of mu=-0.5, sigma=2.0
36
54
loc = (1.0 , - 0.5 )
37
55
scale = (1.0 , 2 .)
38
56
print * , norm_pdf((1.5 , 1.0 ), loc, scale)
39
- ! a complex normal probability density function at (1.5,1.0) with real part
40
- ! of mu=1.0, sigma=1.0 and imaginary part of mu=-0.5, sigma=2.0
41
-
42
- ! 5.30100204E-02
57
+ ! 5.30100204E-02
43
58
44
59
end program example_normal_pdf
0 commit comments