~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/randlib/ignnbn.f

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      INTEGER FUNCTION ignnbn(n,p)
 
2
C**********************************************************************
 
3
C
 
4
C     INTEGER FUNCTION IGNNBN( N, P )
 
5
C
 
6
C                GENerate Negative BiNomial random deviate
 
7
C
 
8
C
 
9
C                              Function
 
10
C
 
11
C
 
12
C     Generates a single random deviate from a negative binomial
 
13
C     distribution.
 
14
C
 
15
C
 
16
C                              Arguments
 
17
C
 
18
C
 
19
C     N  --> Required number of events.
 
20
C                              INTEGER N
 
21
C     JJV                      (N > 0)
 
22
C
 
23
C     P  --> The probability of an event during a Bernoulli trial.
 
24
C                              DOUBLE PRECISION P
 
25
C     JJV                      (0.0 < P < 1.0)
 
26
C
 
27
C
 
28
C
 
29
C                              Method
 
30
C
 
31
C
 
32
C     Algorithm from page 480 of
 
33
C
 
34
C     Devroye, Luc
 
35
C
 
36
C     Non-Uniform Random Variate Generation.  Springer-Verlag,
 
37
C     New York, 1986.
 
38
C
 
39
C**********************************************************************
 
40
C     ..
 
41
C     .. Scalar Arguments ..
 
42
      DOUBLE PRECISION p
 
43
      INTEGER n
 
44
C     ..
 
45
C     .. Local Scalars ..
 
46
      DOUBLE PRECISION y,a,r
 
47
C     ..
 
48
C     .. External Functions ..
 
49
C     JJV changed to call SGAMMA directly
 
50
C     DOUBLE PRECISION gengam
 
51
      DOUBLE PRECISION sgamma
 
52
      INTEGER ignpoi
 
53
C      EXTERNAL gengam,ignpoi
 
54
      EXTERNAL sgamma,ignpoi
 
55
C     ..
 
56
C     .. Intrinsic Functions ..
 
57
      INTRINSIC real
 
58
C     ..
 
59
C     .. Executable Statements ..
 
60
C     Check Arguments
 
61
C     JJV changed argumnet checker to abort if N <= 0
 
62
C     See Rand,c 
 
63
C     Generate Y, a random gamma (n,(1-p)/p) variable
 
64
C     JJV Note: the above parametrization is consistent with Devroye,
 
65
C     JJV       but gamma (p/(1-p),n) is the equivalent in our code
 
66
 10   r = dble(n)
 
67
      a = p/ (1.0-p)
 
68
C      y = gengam(a,r)
 
69
      y = sgamma(r)/a
 
70
 
 
71
C     Generate a random Poisson(y) variable
 
72
      ignnbn = ignpoi(y)
 
73
      RETURN
 
74
 
 
75
      END