-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathutils_m.F90
61 lines (51 loc) · 1.48 KB
/
mathutils_m.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module math_utils_m
use, intrinsic :: iso_fortran_env, only: dp => real64, i64 => int64
implicit none
public :: r8_normal_ab
contains
function r8_normal_ab ( a, b )
!*****************************************************************************80
!
!! R8_NORMAL_AB returns a scaled pseudonormal R8.
!
! Discussion:
!
! The normal probability distribution function (PDF) is sampled,
! with mean A and standard deviation B.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 06 August 2013
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, real ( kind = rk ) A, the mean of the PDF.
!
! Input, real ( kind = rk ) B, the standard deviation of the PDF.
!
! Output, real ( kind = rk ) R8_NORMAL_AB, a sample of the normal PDF.
!
implicit none
integer, parameter :: rk = kind ( 1.0D+00 )
real ( kind = rk ) a
real ( kind = rk ) b
real ( kind = rk ) r1
real ( kind = rk ) r2
real ( kind = rk ) r8_normal_ab
real ( kind = rk ), parameter :: r8_pi = 3.141592653589793D+00
real ( kind = rk ) x
call random_number ( harvest = r1 )
call random_number ( harvest = r2 )
x = sqrt ( - 2.0D+00 * log ( r1 ) ) * cos ( 2.0D+00 * r8_pi * r2 )
r8_normal_ab = a + b * x
return
end function r8_normal_ab
end module