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

None.

None.

### Output Parameters

1:     quas(n,idim$\mathit{idim}$) – double array
Contains the n quasi-random numbers of dimension idim
2:     iref(liref$\mathit{liref}$) – int64int32nag_int array
Contains updated information on the state of the sequence.
3:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
On entry, incorrect initialization has been detected.
ifail = 2${\mathbf{ifail}}=2$
 On entry, n < 1${\mathbf{n}}<1$.
ifail = 3${\mathbf{ifail}}=3$
A standard deviation is negative.
ifail = 4${\mathbf{ifail}}=4$
There have been too many calls to the generator.

Not applicable.

None.

## Example

```function nag_rand_quasi_normal_example
xmean = [1; 2; 3; 4];
std = [1; 1; 1; 1];
n = int64(5);
idim = int64(4);
genid = int64(1);
% Skip the first few variates in the sequence
iskip = int64(1000);

% Initialize the Sobol generator
[iref, ifail] = nag_rand_quasi_init(genid,idim,iskip);
% Generate N values for the normal distribution
[quasi, iref, ifail] = nag_rand_quasi_normal(xmean, std, n, iref)
```
```

quasi =

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

iref =

135
4
7812
31
1005
7
11
1814036480
2086666240
1382023168
1721761792
1073741824
1073741824
1073741824
1073741824
536870912
1610612736
1610612736
1610612736
268435456
1342177280
805306368
268435456
134217728
2013265920
1207959552
671088640
67108864
1140850688
1946157056
2080374784
33554432
1711276032
771751936
973078528
16777216
1426063360
1191182336
1358954496
8388608
2139095040
1652555776
1233125376
4194304
1077936128
876609536
1816133632
2097152
1616904192
1314914304
312475648
1048576
1347420160
1999634432
753926144
524288
2021130240
717750272
1936195584
262144
1145307136
1077149696
1006895104
131072
1717960704
1615724544
1510342656
65536
1431633920
813105152
1090584576
32768
2147450880
1210744832
1635942400
16384
1073758208
1950367744
273137664
8192
1610637312
778067968
681811968
4096
1342197760
1194340352
2113212416
2048
2013296640
1657292800
988583936
1024
1140868096
875852800
1346552832
512
1711302144
1313746432
1218914816
256
1426085120
2004305664
1844694784
128
2139127680
715842176
317568640
64
1077952576
1073771584
742391872
32
1616928864
1610624608
1923088480
16
1347440720
805324592
1022361616
8
2021161080
1207984840
1533542440
4
1145324612
1946170420
1074004092
2
1717986918
771771982
1611006010
1
1431655765
1191212919
268501073

ifail =

0

```
```function g05yj_example
xmean = [1; 2; 3; 4];
std = [1; 1; 1; 1];
n = int64(5);
idim = int64(4);
genid = int64(1);
% Skip the first few variates in the sequence
iskip = int64(1000);

% Initialize the Sobol generator
[iref, ifail] = g05yl(genid,idim,iskip);
% Generate N values for the normal distribution
[quasi, iref, ifail] = g05yj(xmean, std, n, iref)
```
```

quasi =

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

iref =

135
4
7812
31
1005
7
11
1814036480
2086666240
1382023168
1721761792
1073741824
1073741824
1073741824
1073741824
536870912
1610612736
1610612736
1610612736
268435456
1342177280
805306368
268435456
134217728
2013265920
1207959552
671088640
67108864
1140850688
1946157056
2080374784
33554432
1711276032
771751936
973078528
16777216
1426063360
1191182336
1358954496
8388608
2139095040
1652555776
1233125376
4194304
1077936128
876609536
1816133632
2097152
1616904192
1314914304
312475648
1048576
1347420160
1999634432
753926144
524288
2021130240
717750272
1936195584
262144
1145307136
1077149696
1006895104
131072
1717960704
1615724544
1510342656
65536
1431633920
813105152
1090584576
32768
2147450880
1210744832
1635942400
16384
1073758208
1950367744
273137664
8192
1610637312
778067968
681811968
4096
1342197760
1194340352
2113212416
2048
2013296640
1657292800
988583936
1024
1140868096
875852800
1346552832
512
1711302144
1313746432
1218914816
256
1426085120
2004305664
1844694784
128
2139127680
715842176
317568640
64
1077952576
1073771584
742391872
32
1616928864
1610624608
1923088480
16
1347440720
805324592
1022361616
8
2021161080
1207984840
1533542440
4
1145324612
1946170420
1074004092
2
1717986918
771771982
1611006010
1
1431655765
1191212919
268501073

ifail =

0

```