# NAG Library Function Document

## 1Purpose

nag_rand_field_fracbm_generate (g05ztc) produces realizations of a fractional Brownian motion, using the circulant embedding method. The square roots of the eigenvalues of the extended covariance matrix (or embedding matrix) need to be input, and can be calculated using nag_rand_field_1d_predef_setup (g05znc).

## 2Specification

 #include #include
 void nag_rand_field_fracbm_generate (Integer ns, Integer s, Integer m, double xmax, double h, const double lam[], double rho, Integer state[], double z[], double xx[], NagError *fail)

## 3Description

The functions nag_rand_field_1d_predef_setup (g05znc) and nag_rand_field_fracbm_generate (g05ztc) are used to simulate a fractional Brownian motion process with Hurst argument $H$ over an interval $\left[0,{x}_{\mathrm{max}}\right]$, using a set of equally spaced points. Fractional Brownian motion itself cannot be simulated directly using this method, since it is not a stationary Gaussian random field; however its increments can be simulated like a stationary Gaussian random field. The circulant embedding method is described in the documentation for nag_rand_field_1d_predef_setup (g05znc).
nag_rand_field_fracbm_generate (g05ztc) takes the square roots of the eigenvalues of the embedding matrix as returned by nag_rand_field_1d_predef_setup (g05znc) when ${\mathbf{cov}}=\mathrm{Nag_VgmBrownian}$, and its size $M$, as input and outputs $S$ realizations of the fractional Brownian motion in $Z$.
One of the initialization functions nag_rand_init_repeatable (g05kfc) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeatable (g05kgc) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_field_fracbm_generate (g05ztc).
Dietrich C R and Newsam G N (1997) Fast and exact simulation of stationary Gaussian processes through circulant embedding of the covariance matrix SIAM J. Sci. Comput. 18 1088–1107
Schlather M (1999) Introduction to positive definite functions and to unconditional simulation of random fields Technical Report ST 99–10 Lancaster University
Wood A T A and Chan G (1994) Simulation of stationary Gaussian processes in ${\left[0,1\right]}^{d}$ Journal of Computational and Graphical Statistics 3(4) 409–432

## 5Arguments

1:    $\mathbf{ns}$IntegerInput
On entry: the number of steps (points) to be generated in realizations of the increments of the fractional Brownian motion. This must be the same value as supplied to nag_rand_field_1d_predef_setup (g05znc) when calculating the eigenvalues of the embedding matrix.
Note: in the context of fractional Brownian motion, ns represents the number of steps from a zero starting state. Realizations returned in z include this starting state and so ${\mathbf{ns}}+1$ values are returned for each realization.
Constraint: ${\mathbf{ns}}\ge 1$.
2:    $\mathbf{s}$IntegerInput
On entry: $S$, the number of realizations of the fractional Brownian motion to simulate.
Constraint: ${\mathbf{s}}\ge 1$.
3:    $\mathbf{m}$IntegerInput
On entry: the size, $M$, of the embedding matrix, as returned by nag_rand_field_1d_user_setup (g05zmc) or nag_rand_field_1d_predef_setup (g05znc).
Constraint: ${\mathbf{m}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2\left({\mathbf{ns}}-1\right)\right)$.
4:    $\mathbf{xmax}$doubleInput
On entry: the upper bound for the interval over which the fractional Brownian motion is to be simulated, as input to nag_rand_field_1d_user_setup (g05zmc) or nag_rand_field_1d_predef_setup (g05znc).
Constraint: ${\mathbf{xmax}}>0.0$.
5:    $\mathbf{h}$doubleInput
On entry: the Hurst parameter, $H$, for the fractional Brownian motion. This must be the same value as supplied to nag_rand_field_1d_predef_setup (g05znc) in ${\mathbf{params}}\left[0\right]$, when the eigenvalues of the embedding matrix were calculated.
Constraint: $0.0<{\mathbf{h}}<1.0$.
6:    $\mathbf{lam}\left[{\mathbf{m}}\right]$const doubleInput
On entry: contains the square roots of the eigenvalues of the embedding matrix, as returned by nag_rand_field_1d_user_setup (g05zmc) or nag_rand_field_1d_predef_setup (g05znc).
Constraint: ${\mathbf{lam}}\left[\mathit{i}-1\right]\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
7:    $\mathbf{rho}$doubleInput
On entry: indicates the scaling of the covariance matrix, as returned by nag_rand_field_1d_user_setup (g05zmc) or nag_rand_field_1d_predef_setup (g05znc).
Constraint: $0.0<{\mathbf{rho}}\le 1.0$.
8:    $\mathbf{state}\left[\mathit{dim}\right]$IntegerCommunication Array
Note: the dimension, $\mathit{dim}$, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument state in the previous call to nag_rand_init_repeatable (g05kfc) or nag_rand_init_nonrepeatable (g05kgc).
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
9:    $\mathbf{z}\left[\left({\mathbf{ns}}+1\right)×{\mathbf{s}}\right]$doubleOutput
On exit: contains the realizations of the fractional Brownian motion, $Z$. The $\mathit{j}$th realization, for the $\mathit{i}$th point ${\mathbf{xx}}\left[\mathit{i}-1\right]$, is stored in ${\mathbf{z}}\left[\left(\mathit{j}-1\right)×\left({\mathbf{ns}}+1\right)+\mathit{i}-1\right]$, for $\mathit{j}=1,2,\dots ,{\mathbf{s}}$ and $\mathit{i}=1,2,\dots ,{\mathbf{ns}}+1$.
10:  $\mathbf{xx}\left[{\mathbf{ns}}+1\right]$doubleOutput
On exit: the points at which values of the fractional Brownian motion are output. The first point is always zero, and the subsequent ns points represent the equispaced steps towards the last point, xmax. Note that in nag_rand_field_1d_user_setup (g05zmc) and nag_rand_field_1d_predef_setup (g05znc), the returned ns sample points are the mid-points of the grid returned in xx here.
11:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{ns}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ns}}\ge 1$.
On entry, ${\mathbf{s}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{s}}\ge 1$.
NE_INT_2
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$, and ${\mathbf{ns}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,2\left({\mathbf{ns}}-1\right)\right)$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_INVALID_STATE
On entry, state vector has been corrupted or not initialized.
NE_NEG_ELEMENT
On entry, at least one element of lam was negative.
Constraint: all elements of lam must be non-negative.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_REAL
On entry, ${\mathbf{h}}=〈\mathit{\text{value}}〉$.
Constraint: $0.0<{\mathbf{h}}<1.0$.
On entry, ${\mathbf{rho}}=〈\mathit{\text{value}}〉$.
Constraint: $0.0<{\mathbf{rho}}\le 1.0$.
On entry, ${\mathbf{xmax}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{xmax}}>0.0$.

Not applicable.

## 8Parallelism and Performance

nag_rand_field_fracbm_generate (g05ztc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_rand_field_fracbm_generate (g05ztc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

This example calls nag_rand_field_fracbm_generate (g05ztc) to generate $5$ realizations of a fractional Brownian motion over $10$ steps from $x=0.0$ to $x=2.0$ using eigenvalues generated by nag_rand_field_1d_predef_setup (g05znc) with ${\mathbf{cov}}=\mathrm{Nag_VgmBrownian}$.

### 10.1Program Text

Program Text (g05ztce.c)

### 10.2Program Data

Program Data (g05ztce.d)

### 10.3Program Results

Program Results (g05ztce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017