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 μ0 = 0${\mu }_{0}=0$ and concentration parameter κ$\kappa$, can be written as:
 f(θ) = (eκcosθ)/(2πI0(κ)), $f(θ)= eκcos⁡θ 2πI0(κ) ,$
where θ$\theta$ is reduced modulo 2π$2\pi$ so that πθ < π$-\pi \le \theta <\pi$ and κ0$\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$n$ variates, θ1,θ2,,θn${\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:     n – int64int32nag_int scalar
n$n$, the number of pseudorandom numbers to be generated.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     vk – double scalar
κ$\kappa$, the concentration parameter of the required von Mises distribution.
Constraint: 0.0 < vksqrt(x02al) / 2.0$0.0<{\mathbf{vk}}\le \sqrt{\mathbf{x02al}}/2.0$.
3:     state( : $:$) – 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.

None.

### Output Parameters

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

## Accuracy

Not applicable.

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

## Example

```function nag_rand_dist_vonmises_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
n = int64(5);
vk = 1;
% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);
[state, x, ifail] = nag_rand_dist_vonmises(n, vk, state)
```
```

state =

17
1234
1
0
21822
24586
30912
13308
17917
13895
19930
8
0
1234
1
1
1234

x =

1.2947
-1.9542
-0.6464
-1.4172
1.2536

ifail =

0

```
```function g05sr_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
n = int64(5);
vk = 1;
% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);
[state, x, ifail] = g05sr(n, vk, state)
```
```

state =

17
1234
1
0
21822
24586
30912
13308
17917
13895
19930
8
0
1234
1
1
1234

x =

1.2947
-1.9542
-0.6464
-1.4172
1.2536

ifail =

0

```