Next: , Previous: Continuous Multivariate Distributions, Up: Continuous Multivariate Distributions


DRANDMULTINORMAL / SRANDMULTINORMAL

Generates an array of random variates from a Multivariate Normal distribution with probability density function, f(X), where: f(X) = sqrt([det(C^(-1))] / [(2 * Pi)^M]) * exp(-(X - u)^T * C^(-1) * (X - u)), where u is the vector of means, XMU.

(Note that SRANDMULTINORMAL is the single precision version of DRANDMULTINORMAL. The argument lists of both routines are identical except that any double precision arguments of DRANDMULTINORMAL are replaced in SRANDMULTINORMAL by single precision arguments - type REAL in FORTRAN or type float in C).

— SUBROUTINE: DRANDMULTINORMAL (N,M,XMU,C,LDC,STATE,X,LDX,INFO)
— Input: INTEGER N

On input: number of variates required.
Constraint: N>=0.

— Input: INTEGER M

On input: number of dimensions for the distribution.
Constraint: M>=1.

— Input: DOUBLE PRECISION XMU(M)

On input: vector of means for the distribution.

— Input: DOUBLE PRECISION C(LDC,M)

On input: variance / covariance matrix for the distribution.

— Input: INTEGER LDC

On input: leading dimension of C in the calling routine.
Constraint: LDC>=N.

— Input/Output: INTEGER STATE(*)

The STATE vector holds information on the state of the base generator being used and as such its minimum length varies. Prior to calling DRANDMULTINORMAL STATE must have been initialized. See Initialization of the Base Generators for information on initialization of the STATE variable.
On input: the current state of the base generator.
On output: the updated state of the base generator.

— Output: DOUBLE PRECISION X(LDX,M)

On output: matrix of variates from the specified distribution.

— Input: INTEGER LDX

On input: leading dimension of X in the calling routine.
Constraint: LDX>=M.

— Output: INTEGER INFO

On output: INFO is an error indicator. On successful exit, INFO contains 0. If INFO = -i on exit, the i-th argument had an illegal value.

     Example:
     

     Generate 100 values from the
          C      Multivariate Normal distribution
                 INTEGER LSTATE,N, MM
                 PARAMETER (LSTATE=16,N=100,MM=10)
                 INTEGER I,J,INFO,SEED(1),STATE(LSTATE)
                 INTEGER LDC,LDX,M
                 DOUBLE PRECISION X(N,MM),XMU(MM),C(MM,MM)
          C      Set array sizes
                 LDC = MM
                 LDX = N
          
          C      Set the seed
                 SEED(1) = 1234
          
          C      Read in the distributional parameters
                 READ(5,*) M
                 READ(5,*) (XMU(I),I=1,M)
                 DO 20 I = 1,M
                   READ(5,*) (C(I,J),J=1,M)
          20     CONTINUE
          
          C      Initialize the STATE vector
                 CALL DRANDINITIALIZE(1,1,SEED,1,STATE,LSTATE,INFO)
          C      Generate N variates from the
          C      Multivariate Normal distribution
                 CALL DRANDMULTINORMAL(N,M,XMU,C,LDC,STATE,X,LDX,INFO)
          
          C      Print the results
                 DO 40 I = 1,N
                   WRITE(6,*) (X(I,J),J=1,M)
          40     CONTINUE