File: example_uniform_pdf.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (49 lines) | stat: -rw-r--r-- 1,869 bytes parent folder | download | duplicates (2)
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
program example_uniform_pdf
  use stdlib_random, only: random_seed
  use stdlib_stats_distribution_uniform, only: uni_pdf => pdf_uniform, &
                                               uni => rvs_uniform

  implicit none
  complex :: loc, scale
  real :: a(3, 4, 5), b(3, 4, 5), x(3, 4, 5)
  integer :: seed_put, seed_get

  seed_put = 1234567
  call random_seed(seed_put, seed_get)

  print *, uni_pdf(3, 2, 10)       !probability density at 3 in range [2, 10]

! 9.09090936E-02

  print *, uni_pdf(0.5, 0.0, 1.0)    !a probability density at 0.5 in [0., 1.]

! 1.00000000

  print *, uni_pdf(0.7, -1.0, 2.0)   !a probability density at 0.7 in [-1., 1.]

! 0.500000000

  a(:, :, :) = 0.0
  b(:, :, :) = 2.0
  x = reshape(uni(0., 2., 60), [3, 4, 5])! uniform random variates array in [0., 2.]
  print *, uni_pdf(x, a, b)         ! probability density array in [0., 2.]

! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000
! 0.500000000  0.500000000  0.500000000  0.500000000  0.500000000  0.500000000

  loc = (-0.5, -0.5)
  scale = (1.0, 1.0)
  print *, uni_pdf((-0.1, 0.2), loc, scale)
! joint probability density at (-0.1,0.2) in [(-0.5, -0.5), (0.5, 0.5)]

! 1.00000000
end program example_uniform_pdf