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_dist_vonmises (g05sr)

## Purpose

nag_rand_dist_vonmises (g05sr) generates a vector of pseudorandom numbers from a von Mises distribution with concentration parameter $\kappa$.

## Syntax

[state, x, ifail] = g05sr(n, vk, state)
[state, x, ifail] = nag_rand_dist_vonmises(n, vk, state)

## Description

The von Mises distribution is a symmetric distribution used in the analysis of circular data. The PDF (probability density function) of this distribution on the circle with mean direction ${\mu }_{0}=0$ and concentration parameter $\kappa$, can be written as:
 $fθ= eκcos⁡θ 2πI0κ ,$
where $\theta$ is reduced modulo $2\pi$ so that $-\pi \le \theta <\pi$ and $\kappa \ge 0$. For very small $\kappa$ the distribution is almost the uniform distribution, whereas for $\kappa \to \infty$ all the probability is concentrated at one point.
The $n$ variates, ${\theta }_{1},{\theta }_{2},\dots ,{\theta }_{n}$, are generated using an envelope rejection method with a wrapped Cauchy target distribution as proposed by Best and Fisher (1979) and described by Dagpunar (1988).
One of the initialization functions nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_dist_vonmises (g05sr).

## References

Best D J and Fisher N I (1979) Efficient simulation of the von Mises distribution Appl. Statist. 28 152–157
Dagpunar J (1988) Principles of Random Variate Generation Oxford University Press
Mardia K V (1972) Statistics of Directional Data Academic Press

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
$n$, the number of pseudorandom numbers to be generated.
Constraint: ${\mathbf{n}}\ge 0$.
2:     $\mathrm{vk}$ – double scalar
$\kappa$, the concentration parameter of the required von Mises distribution.
Constraint: $0.0<{\mathbf{vk}}\le \sqrt{{\mathbf{x02al}}}/2.0$.
3:     $\mathrm{state}\left(:\right)$int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.

None.

### Output Parameters

1:     $\mathrm{state}\left(:\right)$int64int32nag_int array
Contains updated information on the state of the generator.
2:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The $n$ pseudorandom numbers from the specified von Mises distribution.
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$
Constraint: ${\mathbf{n}}\ge 0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{vk}}\le 0.0$ or vk too large:
${\mathbf{ifail}}=3$
On entry, state vector has been corrupted or not initialized.
${\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.

## Accuracy

Not applicable.

For a given number of random variates the generation time increases slightly with increasing $\kappa$.

## Example

This example prints the first five pseudorandom numbers from a von Mises distribution with $\kappa =1.0$, generated by a single call to nag_rand_dist_vonmises (g05sr), after initialization by nag_rand_init_repeat (g05kf).
```function g05sr_example

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

% Initialize the base generator to a repeatable sequence
seed  = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);

% Number of variates
n = int64(5);

% Parameters
vk = 1;

% Generate variates from von Mises distribution
[state, x, ifail] = g05sr( ...
n, vk, state);

disp('Variates');
disp(x);

```
```g05sr example results

Variates
1.2947
-1.9542
-0.6464
-1.4172
1.2536

```