GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
gengam.f
Go to the documentation of this file.
1 REAL function gengam(a,r)
2C**********************************************************************
3C
4C REAL FUNCTION GENGAM( A, R )
5C GENerates random deviates from GAMma distribution
6C
7C
8C Function
9C
10C
11C Generates random deviates from the gamma distribution whose
12C density is
13C (A**R)/Gamma(R) * X**(R-1) * Exp(-A*X)
14C
15C
16C Arguments
17C
18C
19C JJV added the argument ranges supported
20C A --> Location parameter of Gamma distribution
21C REAL A ( A > 0 )
22C
23C R --> Shape parameter of Gamma distribution
24C REAL R ( R > 0 )
25C
26C
27C Method
28C
29C
30C Renames SGAMMA from TOMS as slightly modified by BWB to use RANF
31C instead of SUNIF.
32C
33C For details see:
34C (Case R >= 1.0)
35C Ahrens, J.H. and Dieter, U.
36C Generating Gamma Variates by a
37C Modified Rejection Technique.
38C Comm. ACM, 25,1 (Jan. 1982), 47 - 54.
39C Algorithm GD
40C
41C JJV altered the following to reflect sgamma argument ranges
42C (Case 0.0 < R < 1.0)
43C Ahrens, J.H. and Dieter, U.
44C Computer Methods for Sampling from Gamma,
45C Beta, Poisson and Binomial Distributions.
46C Computing, 12 (1974), 223-246/
47C Adapted algorithm GS.
48C
49C**********************************************************************
50C .. Scalar Arguments ..
51 REAL a,r
52C ..
53C .. External Functions ..
54 REAL sgamma
55 EXTERNAL sgamma
56C ..
57C .. Executable Statements ..
58
59C JJV added argument value checker
60 IF ( a.GT.0.0 .AND. r.GT.0.0 ) GO TO 10
61 WRITE (*,*) 'In GENGAM - Either (1) Location param A <= 0.0 or'
62 WRITE (*,*) '(2) Shape param R <= 0.0 - ABORT!'
63 WRITE (*,*) 'A value: ',a,'R value: ',r
64 CALL xstopx
65 + ('Location or shape param out of range in GENGAM - ABORT!')
66C JJV end addition
67
68 10 gengam = sgamma(r)/a
69C gengam = gengam/a
70 RETURN
71
72 END
real function gengam(a, r)
Definition gengam.f:2
real function sgamma(a)
Definition sgamma.f:2