COSMOS v7.655  COSMOSv7655
(AirShowerMC)
ksmpConExp.f
Go to the documentation of this file.
1 ! implicit none
2 ! integer n, i, j
3 !
4 ! real*8 sumx, sum, xa(500)
5 !
6 ! read(*,*) n, sumx
7 !
8 ! do i = 1, 10000
9 ! call ksmpConExp(n, sumx, xa)
10 ! sum = 0
11 ! do j= 1, n
12 ! write(*,*) sngl(xa(j))
13 ! sum = sum + xa(j)
14 ! enddo
15 ! if( abs(sum-sumx) .gt. 1.d-5 ) then
16 ! write(0,*) sum, sumx
17 ! stop
18 ! endif
19 ! enddo
20 ! end
21  subroutine ksmpconexp(n, sumx, xa)
22 !
23 ! This samples x of n particles so that sum of x
24 ! becomes sumx. The pre-assumed one particle distribution of
25 ! each particle is propotional to exp(-b xi/xc) dxi
26 ! but there is a constraint of delta(sum(xi) - sumx).
27 ! sampling is can be done by using (sum-xi)^(m-2) dxi
28 ! for givne sum = sum(xi) (i=1, m)
29 ! n should be b* sumx/xc; For xc=0.1 and b=10, n=sumx*100.
30 !
31 
32  implicit none
33  integer n ! input number of particles to be generated
34  real*8 sumx ! input sum of x
35  real*8 xa(n) ! output. x of n particles generated
36 
37  real*8 x, u, xk
38  integer j
39 
40  x = sumx
41  do j = 1, n-1
42  call rndc(u)
43  xk = x*(1.0- u**(1.0/(n-j)))
44  xa(j) = xk
45  x = x - xk
46  enddo
47  xa(n) = x
48  end
49 
50 
subroutine rndc(u)
Definition: rnd.f:91
subroutine ksmpconexp(n, sumx, xa)
Definition: ksmpConExp.f:22