hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_rand_dist_vonmises (g05sr)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


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


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


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 and concentration parameter κ, can be written as:
fθ= eκcosθ 2πI0κ ,  
where θ is reduced modulo 2π so that -πθ<π and κ0. For very small κ the distribution is almost the uniform distribution, whereas for κ all the probability is concentrated at one point.
The n variates, θ1,θ2,,θ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).


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


Compulsory Input Parameters

1:     n int64int32nag_int scalar
n, the number of pseudorandom numbers to be generated.
Constraint: n0.
2:     vk – double scalar
κ, the concentration parameter of the required von Mises distribution.
Constraint: 0.0<vkx02al/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.

Optional Input Parameters


Output Parameters

1:     state: int64int32nag_int array
Contains updated information on the state of the generator.
2:     xn – double array
The n pseudorandom numbers from the specified von Mises distribution.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
Constraint: n0.
On entry, vk0.0 or vk too large:
On entry, state vector has been corrupted or not initialized.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


Not applicable.

Further Comments

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


This example prints the first five pseudorandom numbers from a von Mises distribution with κ=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);


g05sr example results


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015