Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_rand_quasi_normal (g05yj)

## Purpose

nag_rand_quasi_normal (g05yj) generates a quasi-random sequence from a Normal (Gaussian) distribution. It must be preceded by a call to one of the initialization functions nag_rand_quasi_init (g05yl) or nag_rand_quasi_init_scrambled (g05yn).

## Syntax

[quas, iref, ifail] = g05yj(xmean, std, n, iref)
[quas, iref, ifail] = nag_rand_quasi_normal(xmean, std, n, iref)

## Description

nag_rand_quasi_normal (g05yj) generates a quasi-random sequence from a Normal distribution by first generating a uniform quasi-random sequence which is then transformed into a Normal sequence using the inverse of the Normal CDF. The type of uniform sequence used depends on the initialization function called and can include the low-discrepancy sequences proposed by Sobol, Faure or Niederreiter. If the initialization function nag_rand_quasi_init_scrambled (g05yn) was used then the underlying uniform sequence is first scrambled prior to being transformed (see Description in nag_rand_quasi_init_scrambled (g05yn) for details).

## References

Bratley P and Fox B L (1988) Algorithm 659: implementing Sobol's quasirandom sequence generator ACM Trans. Math. Software 14(1) 88–100
Fox B L (1986) Algorithm 647: implementation and relative efficiency of quasirandom sequence generators ACM Trans. Math. Software 12(4) 362–376
Wichura (1988) Algorithm AS 241: the percentage points of the Normal distribution Appl. Statist. 37 477–484

## Parameters

Note: the following variables are used in the parameter descriptions:

### Compulsory Input Parameters

1:     $\mathrm{xmean}\left(\mathit{idim}\right)$ – double array
Specifies, for each dimension, the mean of the Normal distribution.
2:     $\mathrm{std}\left(\mathit{idim}\right)$ – double array
Specifies, for each dimension, the standard deviation of the Normal distribution.
Constraint: ${\mathbf{std}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,\mathit{idim}$.
3:     $\mathrm{n}$int64int32nag_int scalar
The number of quasi-random numbers required.
Constraint: ${\mathbf{n}}\ge 0$ and ${\mathbf{n}}+\text{previous number of generated values}\le {2}^{31}-1$.
4:     $\mathrm{iref}\left(\mathit{liref}\right)$int64int32nag_int array
Contains information on the current state of the sequence.

None.

### Output Parameters

1:     $\mathrm{quas}\left({\mathbf{n}},\mathit{idim}\right)$ – double array
Contains the n quasi-random numbers of dimension idim
2:     $\mathrm{iref}\left(\mathit{liref}\right)$int64int32nag_int array
Contains updated information on the state of the sequence.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
On entry, incorrect initialization has been detected.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{n}}<1$.
${\mathbf{ifail}}=3$
A standard deviation is negative.
${\mathbf{ifail}}=4$
There have been too many calls to the generator.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Not applicable.

None.

## Example

This example calls nag_rand_quasi_init (g05yl) to initialize the generator and then nag_rand_quasi_normal (g05yj) to generate a sequence of five four-dimensional variates.
```function g05yj_example

fprintf('g05yj example results\n\n');

% Initialize the Sobol generator, skipping some variates
iskip = int64(1000);
idim = int64(4);
genid = int64(1);
% Initialize the Sobol generator
[iref, ifail] = g05yl( ...
genid,idim,iskip);

% Number of variates
n = int64(5);

% Parameters
xmean = [1; 2; 3; 4];
std   = [1; 1; 1; 1];

% Generate N values for the normal distribution
[quasi, iref, ifail] = g05yj( ...
xmean, std, n, iref);

disp('Variates');
disp(quasi);

```
```g05yj example results

Variates
1.5820    2.2448    0.9154    3.0722
2.8768    1.6057    3.7341    5.4521
0.9240    3.0223    2.3828    3.8154
0.6004    1.9290    1.9355    3.4806
2.0141    3.9061    3.3680    4.8479

```