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_lognormal (g05yk)

## Purpose

nag_rand_quasi_lognormal (g05yk) generates a quasi-random sequence from a log-normal 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] = g05yk(xmean, std, n, iref)
[quas, iref, ifail] = nag_rand_quasi_lognormal(xmean, std, n, iref)

## Description

nag_rand_quasi_lognormal (g05yk) generates a quasi-random sequence from a log-normal distribution by first generating a uniform quasi-random sequence which is then transformed into a log-normal sequence using the exponential of 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 underlying Normal distribution.
Constraint: $\left|{\mathbf{xmean}}\left(\mathit{i}\right)\right|\le \left|-\mathrm{log}\left({\mathbf{x02am}}\right)-10.0×{\mathbf{std}}\left(\mathit{i}\right)\right|$, for $\mathit{i}=1,2,\dots ,\mathit{idim}$.
2:     $\mathrm{std}\left(\mathit{idim}\right)$ – double array
Specifies, for each dimension, the standard deviation of the underlying 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$
On entry,at least one element of xmean is too large.
${\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_lognormal (g05yk) to produce a sequence of five four-dimensional quasi-random numbers variates.
```function g05yk_example

fprintf('g05yk 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 from the log-normal distribution
[quasi, iref, ifail] = g05yk( ...
xmean, std, n, iref);

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

```
```g05yk example results

Variates
4.8648    9.4382    2.4979   21.5895
17.7572    4.9813   41.8501  233.2386
2.5195   20.5384   10.8353   45.3933
1.8229    6.8823    6.9276   32.4808
7.4938   49.7034   29.0198  127.4745

```