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_tsa_inhom_iema_all (g13mf)

## Purpose

nag_tsa_inhom_iema_all (g13mf) calculates the iterated exponential moving average for an inhomogeneous time series, returning the intermediate results.

## Syntax

[iema, p, pn, rcomm, ifail] = g13mf(z, t, tau, m1, m2, sinit, inter, ftype, p, x, 'sorder', sorder, 'nb', nb, 'pn', pn, 'rcomm', rcomm)
[iema, p, pn, rcomm, ifail] = nag_tsa_inhom_iema_all(z, t, tau, m1, m2, sinit, inter, ftype, p, x, 'sorder', sorder, 'nb', nb, 'pn', pn, 'rcomm', rcomm)

## Description

nag_tsa_inhom_iema_all (g13mf) calculates the iterated exponential moving average for an inhomogeneous time series. The time series is represented by two vectors of length n$n$: a vector of times, t$t$; and a vector of values, z$z$. Each element of the time series is therefore composed of the pair of scalar values (ti,zi)$\left({t}_{\mathit{i}},{z}_{\mathit{i}}\right)$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$. Time can be measured in any arbitrary units, as long as all elements of t$t$ use the same units.
The exponential moving average (EMA), with parameter τ$\tau$, is an average operator, with the exponentially decaying kernel given by
 (e − ti / τ)/τ . $e -ti/τ τ .$
The exponential form of this kernel gives rise to the following iterative formula (Zumbach and Müller (2001)) for the EMA operator:
 EMA [τ ; y] (ti) = μ EMA [τ ; y] (ti − 1) + (ν − μ) yi − 1 + (1 − ν) yi $EMA [ τ ; y ] (ti) = μ ⁢ EMA [τ;y] ( ti-1 ) + (ν-μ) ⁢ yi-1 + (1-ν) ⁢ yi$
where
 μ = e − α   and   α = ( ti − ti − 1 )/τ . $μ = e-α and α = ti - ti-1 τ .$
The value of ν$\nu$ depends on the method of interpolation chosen and the relationship between y$y$ and the input series z$z$ depends on the transformation function chosen. nag_tsa_inhom_iema_all (g13mf) gives the option of three interpolation methods:
 1 Previous point: ν = 1$\nu =1$; 2 Linear: ν = (1 − μ) / α $\nu =\left(1-\mu \right)/\alpha$; 3 Next point: ν = μ$\nu =\mu$.
and three transformation functions:
 1 Identity: yi = zi[p] ${y}_{i}={{z}_{i}}^{\left[p\right]}$; 2 Absolute value: yi = |zi|p ${y}_{i}={|{z}_{i}|}^{p}$; 3 Absolute difference: yi = |zi − xi|p ${y}_{i}={|{z}_{i}-{x}_{i}|}^{p}$;
where the notation [p]$\left[p\right]$ is used to denote the integer nearest to p$p$. In the case of the absolute difference x$x$ is a user-supplied vector of length n$n$ and therefore each element of the time series is composed of the triplet of scalar values, (ti,zi,xi)$\left({t}_{i},{z}_{i},{x}_{i}\right)$.
The m$m$-iterated exponential moving average, EMA[τ,m ; y](ti)$\text{EMA}\left[\tau ,m;y\right]\left({t}_{i}\right)$, is defined using the recursive formula:
 EMA [τ,m ; y] (ti) = EMA [τ ; EMA[τ,m − 1 ; y](ti)] (ti) $EMA [ τ,m ; y ] (ti) = EMA [ τ ; EMA [ τ,m-1 ; y ] (ti) ] (ti)$
with
 EMA [τ,1 ; y] (ti) = EMA [τ ; y] (ti) . $EMA [ τ,1;y ] (ti) = EMA [τ;y] (ti) .$
For large datasets or where all the data is not available at the same time, z,t$z,t$ and, where required, x$x$ can be split into arbitrary sized blocks and nag_tsa_inhom_iema_all (g13mf) called multiple times.

## References

Dacorogna M M, Gencay R, Müller U, Olsen R B and Pictet O V (2001) An Introduction to High-frequency Finance Academic Press
Zumbach G O and Müller U A (2001) Operators on inhomogeneous time series International Journal of Theoretical and Applied Finance 4(1) 147–178

## Parameters

### Compulsory Input Parameters

1:     z(nb) – double array
nb, the dimension of the array, must satisfy the constraint nb0${\mathbf{nb}}\ge 0$.
zi${z}_{\mathit{i}}$, the current block of observations, for i = k + 1,,k + b$\mathit{i}=k+1,\dots ,k+b$, where k$k$ is the number of observations processed so far, i.e., the value supplied in pn on entry.
Constraint: if ftype = 1${\mathbf{ftype}}=1$ or 2$2$ and p < 0.0${\mathbf{p}}<0.0$, z(i)0${\mathbf{z}}\left(\mathit{i}\right)\ne 0$, for i = 1,2,,nb$\mathit{i}=1,2,\dots ,{\mathbf{nb}}$.
2:     t(nb) – double array
nb, the dimension of the array, must satisfy the constraint nb0${\mathbf{nb}}\ge 0$.
ti${t}_{\mathit{i}}$, the times for the current block of observations, for i = k + 1,,k + b$\mathit{i}=k+1,\dots ,k+b$, where k$k$ is the number of observations processed so far, i.e., the value supplied in pn on entry.
If titi1${t}_{i}\le {t}_{i-1}$, ${\mathbf{ifail}}={\mathbf{61}}$ will be returned, but nag_tsa_inhom_iema_all (g13mf) will continue as if t$t$ was strictly increasing by using the absolute value.
3:     tau – double scalar
τ$\tau$, the parameter controlling the rate of decay. τ$\tau$ must be sufficiently large that eα${e}^{-\alpha }$, α = (titi1) / τ$\alpha =\left({t}_{i}-{t}_{i-1}\right)/\tau$ can be calculated without overflowing, for all i$i$.
Constraint: tau > 0.0${\mathbf{tau}}>0.0$.
4:     m1 – int64int32nag_int scalar
The minimum number of times the EMA operator is to be iterated.
Constraint: m11${\mathbf{m1}}\ge 1$.
5:     m2 – int64int32nag_int scalar
The maximum number of times the EMA operator is to be iterated. Therefore nag_tsa_inhom_iema_all (g13mf) returns EMA [τ,m ; y] $\text{EMA}\left[\tau ,m;y\right]$, for m = m1,m1 + 1,,m2$m={\mathbf{m1}},{\mathbf{m1}}+1,\dots ,{\mathbf{m2}}$.
Constraint: m2m1${\mathbf{m2}}\ge {\mathbf{m1}}$.
6:     sinit(m2 + 2${\mathbf{m2}}+2$) – double array
If pn = 0${\mathbf{pn}}=0$, the values used to start the iterative process, with
• sinit(1) = t0${\mathbf{sinit}}\left(1\right)={t}_{0}$,
• sinit(2) = y0${\mathbf{sinit}}\left(2\right)={y}_{0}$,
• sinit(j + 2) = EMA [τ,j ; y] (t0) ${\mathbf{sinit}}\left(j+2\right)=\text{EMA}\left[\tau ,j;y\right]\left({t}_{0}\right)$, j = 1,2,,m2$j=1,2,\dots ,{\mathbf{m2}}$.
If pn0${\mathbf{pn}}\ne 0$ then sinit is not referenced.
Constraint: if ftype1${\mathbf{ftype}}\ne 1$, sinit(j)0${\mathbf{sinit}}\left(\mathit{j}\right)\ge 0$, for j = 2,3,,m2 + 2$\mathit{j}=2,3,\dots ,{\mathbf{m2}}+2$.
7:     inter(2$2$) – int64int32nag_int array
The type of interpolation used with inter(1)${\mathbf{inter}}\left(1\right)$ indicating the interpolation method to use when calculating EMA[τ,1 ; z]$\text{EMA}\left[\tau ,1;z\right]$ and inter(2)${\mathbf{inter}}\left(2\right)$ the interpolation method to use when calculating EMA[τ,j ; z]$\text{EMA}\left[\tau ,j;z\right]$, j > 1$j>1$.
Three types of interpolation are possible:
inter(i) = 1${\mathbf{inter}}\left(i\right)=1$
Previous point, with ν = 1$\nu =1$.
inter(i) = 2${\mathbf{inter}}\left(i\right)=2$
Linear, with ν = (1μ) / α$\nu =\left(1-\mu \right)/\alpha$.
inter(i) = 3${\mathbf{inter}}\left(i\right)=3$
Next point, ν = μ$\nu =\mu$.
Zumbach and Müller (2001) recommend that linear interpolation is used in second and subsequent iterations, i.e., inter(2) = 2${\mathbf{inter}}\left(2\right)=2$, irrespective of the interpolation method used at the first iteration, i.e., the value of inter(1)${\mathbf{inter}}\left(1\right)$.
Constraint: inter(i) = 1${\mathbf{inter}}\left(\mathit{i}\right)=1$, 2$2$ or 3$3$, for i = 1,2$\mathit{i}=1,2$.
8:     ftype – int64int32nag_int scalar
The function type used to define the relationship between y$y$ and z$z$ when calculating EMA[τ,1 ; y]$\text{EMA}\left[\tau ,1;y\right]$. Three functions are provided:
ftype = 1${\mathbf{ftype}}=1$
The identity function, with yi = zi[p] ${y}_{i}={{z}_{i}}^{\left[p\right]}$.
ftype = 2${\mathbf{ftype}}=2$
The absolute value, with yi = |zi|p ${y}_{i}={|{z}_{i}|}^{p}$.
ftype = 3${\mathbf{ftype}}=3$
The absolute difference, with yi = |zixi|p ${y}_{i}={|{z}_{i}-{x}_{i}|}^{p}$, where the vector x$x$ is supplied in x.
Constraint: ftype = 1${\mathbf{ftype}}=1$, 2$2$ or 3$3$.
9:     p – double scalar
p$p$, the power used in the transformation function.
Constraint: p0${\mathbf{p}}\ne 0$.
10:   x( : $:$) – double array
Note: the dimension of the array x must be at least nb${\mathbf{nb}}$ if ftype = 3${\mathbf{ftype}}=3$.
If ftype = 3${\mathbf{ftype}}=3$, xi${x}_{i}$, the vector used to shift the current block of observations, for i = k + 1,,k + b$\mathit{i}=k+1,\dots ,k+b$, where k$k$ is the number of observations processed so far, i.e., the value supplied in pn on entry.
If ftype3${\mathbf{ftype}}\ne 3$ then x is not referenced.
Constraint: if ftype = 3${\mathbf{ftype}}=3$ and p < 0${\mathbf{p}}<0$, x(i)z(i)${\mathbf{x}}\left(\mathit{i}\right)\ne {\mathbf{z}}\left(\mathit{i}\right)$, for i = 1,2,,nb$\mathit{i}=1,2,\dots ,{\mathbf{nb}}$.

### Optional Input Parameters

1:     sorder – int64int32nag_int scalar
Determines the storage order of output returned in iema.
Default: 1$1$
Constraint: sorder = 1${\mathbf{sorder}}=1$ or 2$2$.
2:     nb – int64int32nag_int scalar
Default: The dimension of the arrays z, t, x. (An error is raised if these dimensions are not equal.)
b$b$, the number of observations in the current block of data. At each call the size of the block of data supplied in z, t and x can vary; therefore nb can change between calls to nag_tsa_inhom_iema_all (g13mf).
Constraint: nb0${\mathbf{nb}}\ge 0$.
3:     pn – int64int32nag_int scalar
k$k$, the number of observations processed so far. On the first call to nag_tsa_inhom_iema_all (g13mf), or when starting to summarise a new dataset, pn must be set to 0$0$. On subsequent calls it must be the same value as returned by the last call to nag_tsa_inhom_iema_all (g13mf).
Default: 0$0$
Constraint: pn0${\mathbf{pn}}\ge 0$.
4:     rcomm(m2 + 20${\mathbf{m2}}+20$) – double array
Communication array, used to store information between calls to nag_tsa_inhom_iema_all (g13mf). On the first call to nag_tsa_inhom_iema_all (g13mf), or if all the data is provided in one go, rcomm need not be provided.

ldiema lrcomm

### Output Parameters

1:     iema(ldiema,sdiema$\mathit{sdiema}$) – double array
Note: the second dimension of the array iema must be at least m2m1 + 1${\mathbf{m2}}-{\mathbf{m1}}+1$ if sorder = 1${\mathbf{sorder}}=1$, otherwise at least nb.
The iterated exponential moving average.
If sorder = 1${\mathbf{sorder}}=1$, iema(i,j) = EMA [τ,j + m11 ; y] (ti + k) ${\mathbf{iema}}\left(i,j\right)=\text{EMA}\left[\tau ,j+{\mathbf{m1}}-1;y\right]\left({t}_{i+k}\right)$.
If sorder = 2${\mathbf{sorder}}=2$, iema(j,i) = EMA [τ,j + m11 ; y] (ti + k) ${\mathbf{iema}}\left(j,i\right)=\text{EMA}\left[\tau ,j+{\mathbf{m1}}-1;y\right]\left({t}_{i+k}\right)$.
For i = 1,2,,nb$i=1,2,\dots ,{\mathbf{nb}}$, j = 1,2,,m2m1 + 1$j=1,2,\dots ,{\mathbf{m2}}-{\mathbf{m1}}+1$ and k$k$ is the number of observations processed so far, i.e., the value supplied in pn on entry.
2:     p – double scalar
If ftype = 1${\mathbf{ftype}}=1$, then [p]$\left[p\right]$, the actual power used in the transformation function is returned, otherwise p is unchanged.
3:     pn – int64int32nag_int scalar
Default: 0$0$
k + b$k+b$, the updated number of observations processed so far.
4:     rcomm(m2 + 20${\mathbf{m2}}+20$) – double array
Communication array, used to store information between calls to nag_tsa_inhom_iema_all (g13mf).
5:     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:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 11${\mathbf{ifail}}=11$
On entry, sorder = _${\mathbf{sorder}}=_$.
Constraint: sorder = 1${\mathbf{sorder}}=1$ or 2$2$.
ifail = 21${\mathbf{ifail}}=21$
Constraint: nb0${\mathbf{nb}}\ge 0$.
ifail = 51${\mathbf{ifail}}=51$
Constraint: ldiemam2m1 + 1$\mathit{ldiema}\ge {\mathbf{m2}}-{\mathbf{m1}}+1$.
Constraint: ldiemanb$\mathit{ldiema}\ge {\mathbf{nb}}$.
W ifail = 61${\mathbf{ifail}}=61$
Constraint: t should be strictly increasing.
ifail = 62${\mathbf{ifail}}=62$
Constraint: t(i)t(i1)${\mathbf{t}}\left(i\right)\ne {\mathbf{t}}\left(i-1\right)$ if linear interpolation is being used.
ifail = 71${\mathbf{ifail}}=71$
Constraint: tau > 0.0${\mathbf{tau}}>0.0$.
ifail = 72${\mathbf{ifail}}=72$
Constraint: if pn > 0${\mathbf{pn}}>0$ then tau must be unchanged since previous call.
ifail = 81${\mathbf{ifail}}=81$
Constraint: m11${\mathbf{m1}}\ge 1$.
ifail = 82${\mathbf{ifail}}=82$
Constraint: if pn > 0${\mathbf{pn}}>0$ then m1 must be unchanged since previous call.
ifail = 91${\mathbf{ifail}}=91$
Constraint: m2m1${\mathbf{m2}}\ge {\mathbf{m1}}$.
ifail = 92${\mathbf{ifail}}=92$
Constraint: if pn > 0${\mathbf{pn}}>0$ then m2 must be unchanged since previous call.
ifail = 101${\mathbf{ifail}}=101$
Constraint: if ftype1${\mathbf{ftype}}\ne 1$, sinit(j)0.0${\mathbf{sinit}}\left(\mathit{j}\right)\ge 0.0$, for j = 2,3,,m2 + 2$\mathit{j}=2,3,\dots ,{\mathbf{m2}}+2$.
ifail = 111${\mathbf{ifail}}=111$
On entry, inter(1) = _${\mathbf{inter}}\left(1\right)=_$.
Constraint: inter(1) = 1${\mathbf{inter}}\left(1\right)=1$, 2$2$ or 3$3$.
ifail = 112${\mathbf{ifail}}=112$
On entry, inter(2) = _${\mathbf{inter}}\left(2\right)=_$.
Constraint: inter(2) = 1${\mathbf{inter}}\left(2\right)=1$, 2$2$ or 3$3$.
ifail = 113${\mathbf{ifail}}=113$
Constraint: if pn0${\mathbf{pn}}\ne 0$, inter must be unchanged since the last call.
ifail = 121${\mathbf{ifail}}=121$
On entry, ftype = _${\mathbf{ftype}}=_$.
Constraint: ftype = 1${\mathbf{ftype}}=1$, 2$2$ or 3$3$.
ifail = 122${\mathbf{ifail}}=122$
Constraint: if pn0${\mathbf{pn}}\ne 0$, ftype must be unchanged since the previous call.
ifail = 131${\mathbf{ifail}}=131$
Constraint: absolute value of p must be representable as an integer.
ifail = 132${\mathbf{ifail}}=132$
Constraint: if ftype1${\mathbf{ftype}}\ne 1$, p0.0${\mathbf{p}}\ne 0.0$. If ftype = 1${\mathbf{ftype}}=1$, the nearest integer to p${\mathbf{p}}$ must not be 0$0$.
ifail = 133${\mathbf{ifail}}=133$
Constraint: if ftype = 1${\mathbf{ftype}}=1$ or 2$2$ and z(i) = 0${\mathbf{z}}\left(i\right)=0$ for any i$i$ then p > 0.0${\mathbf{p}}>0.0$.
ifail = 134${\mathbf{ifail}}=134$
Constraint: if ftype = 3${\mathbf{ftype}}=3$ and z(i) = x(i)${\mathbf{z}}\left(i\right)={\mathbf{x}}\left(i\right)$ for any i$i$ then p > 0.0${\mathbf{p}}>0.0$.
ifail = 135${\mathbf{ifail}}=135$
Constraint: if pn > 0${\mathbf{pn}}>0$ then p must be unchanged since previous call.
ifail = 151${\mathbf{ifail}}=151$
Constraint: pn0${\mathbf{pn}}\ge 0$.
ifail = 152${\mathbf{ifail}}=152$
Constraint: if pn > 0${\mathbf{pn}}>0$ then pn must be unchanged since previous call.
ifail = 161${\mathbf{ifail}}=161$
rcomm has been corrupted between calls.
ifail = 171${\mathbf{ifail}}=171$
Constraint: if pn = 0${\mathbf{pn}}=0$, lrcomm = 0$\mathit{lrcomm}=0$ or lrcommm2 + 20$\mathit{lrcomm}\ge {\mathbf{m2}}+20$.
ifail = 172${\mathbf{ifail}}=172$
Constraint: if pn0${\mathbf{pn}}\ne 0$ then lrcommm2 + 20$\mathit{lrcomm}\ge {\mathbf{m2}}+20$.
W ifail = 301${\mathbf{ifail}}=301$
Truncation occurred to avoid overflow, check for extreme values in t, z, x or for tau. Results are returned using the truncated values.
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

Approximately 4 × m2$4×{\mathbf{m2}}$ real elements are internally allocated by nag_tsa_inhom_iema_all (g13mf).
The more data you supply to nag_tsa_inhom_iema_all (g13mf) in one call, i.e., the larger nb is, the more efficient the routine will be, particularly if the function is being run using more than one thread.
Checks are made during the calculation of α$\alpha$ and yi${y}_{i}$ to avoid overflow. If a potential overflow is detected the offending value is replaced with a large positive or negative value, as appropriate, and the calculations performed based on the replacement values. In such cases ${\mathbf{ifail}}={\mathbf{301}}$ is returned. This should not occur in standard usage and will only occur if extreme values of z, t, x or tau are supplied.

## Example

```function nag_tsa_inhom_iema_all_example
m1 = int64(2);
m2 = int64(6);
ftype = int64(1);
p = 1;
inter = [int64(3); 2];
tau = 2;
sinit = zeros(8, 1);
nb = [5, 10, 15];
rcomm = zeros(20+m2, 1);
x = [];
t = cell(3, 1);
z = cell(3, 1);
t{1} = [7.5; 8.2; 18.1; 22.8; 25.8];
z{1} = [0.6; 0.6; 0.8; 0.1; 0.2];
t{2} = [26.8; 31.1; 38.4; 45.9; 48.2; 48.9; 57.9; 58.5; 63.9; 65.2];
z{2} = [0.2;  0.5;  0.7;  0.1;  0.4;  0.7;  0.8;  0.3;  0.2;  0.5];
t{3} = [66.6; 67.4; 69.3; 69.9; 73.0; 75.6; 77.0; 84.7; 86.8; 88.0; ...
88.5; 91.0; 93.0; 93.7; 94.0];
z{3} = [0.2;  0.3;  0.8;  0.6;  0.1;  0.7;  0.9;  0.6;  0.3;  0.1;  ...
0.1;  0.4;  1.0;  1.0;  0.1];

fprintf('\n                                Iteration\n');
fprintf('             Time       2         3         4         5         6\n');

% Loop over each block of data.
miema = m2-m1+1;
iema = cell(numel(nb), 1);
fmt = '%3d    %10.1f    %8.3f  %8.3f  %8.3f  %8.3f  %8.3f\n';
for i = 1:numel(nb)
if i == 1
% Initialise the iterated EMA
[iema{i}, p, pn, rcomm, ifail] = ...
nag_tsa_inhom_iema_all(z{i}, t{i}, tau, m1, m2, sinit, inter, ftype, p, x);
else
% Update the iterated EMA for this block of data
[iema{i}, p, pn, rcomm, ifail] = ...
nag_tsa_inhom_iema_all(z{i}, t{i}, tau, m1, m2, ...
sinit, inter, ftype, p, x, 'pn', pn, 'rcomm', rcomm);
end

% Display the results for this block of data
for j=1:nb(i)
fprintf(fmt, pn-nb(i)+j, t{i}(j), iema{i}(j, 1:miema));
end
fprintf('\n');
end
```
```

Iteration
Time       2         3         4         5         6
1           7.5       0.433     0.320     0.237     0.175     0.130
2           8.2       0.479     0.361     0.268     0.198     0.147
3          18.1       0.756     0.700     0.631     0.558     0.485
4          22.8       0.406     0.535     0.592     0.600     0.577
5          25.8       0.232     0.351     0.459     0.530     0.561

6          26.8       0.217     0.301     0.406     0.491     0.540
7          31.1       0.357     0.309     0.318     0.364     0.422
8          38.4       0.630     0.556     0.490     0.445     0.425
9          45.9       0.263     0.357     0.407     0.428     0.432
10          48.2       0.241     0.284     0.343     0.388     0.413
11          48.9       0.279     0.277     0.325     0.372     0.403
12          57.9       0.713     0.617     0.543     0.496     0.469
13          58.5       0.717     0.643     0.566     0.511     0.478
14          63.9       0.385     0.495     0.541     0.546     0.531
15          65.2       0.346     0.432     0.502     0.533     0.535

16          66.6       0.330     0.384     0.453     0.504     0.526
17          67.4       0.315     0.364     0.427     0.483     0.515
18          69.3       0.409     0.367     0.389     0.435     0.478
19          69.9       0.459     0.385     0.386     0.423     0.465
20          73.0       0.377     0.403     0.394     0.398     0.419
21          75.6       0.411     0.399     0.399     0.397     0.403
22          77.0       0.536     0.440     0.410     0.401     0.401
23          84.7       0.632     0.606     0.563     0.524     0.493
24          86.8       0.538     0.587     0.583     0.557     0.526
25          88.0       0.444     0.542     0.574     0.567     0.542
26          88.5       0.401     0.515     0.564     0.567     0.548
27          91.0       0.331     0.404     0.481     0.529     0.545
28          93.0       0.495     0.418     0.438     0.483     0.518
29          93.7       0.585     0.455     0.438     0.469     0.506
30          94.0       0.612     0.475     0.441     0.465     0.500

```
```function g13mf_example
m1 = int64(2);
m2 = int64(6);
ftype = int64(1);
p = 1;
inter = [int64(3); 2];
tau = 2;
sinit = zeros(8, 1);
nb = [5, 10, 15];
rcomm = zeros(20+m2, 1);
x = [];
t = cell(3, 1);
z = cell(3, 1);
t{1} = [7.5; 8.2; 18.1; 22.8; 25.8];
z{1} = [0.6; 0.6; 0.8; 0.1; 0.2];
t{2} = [26.8; 31.1; 38.4; 45.9; 48.2; 48.9; 57.9; 58.5; 63.9; 65.2];
z{2} = [0.2;  0.5;  0.7;  0.1;  0.4;  0.7;  0.8;  0.3;  0.2;  0.5];
t{3} = [66.6; 67.4; 69.3; 69.9; 73.0; 75.6; 77.0; 84.7; 86.8; 88.0; ...
88.5; 91.0; 93.0; 93.7; 94.0];
z{3} = [0.2;  0.3;  0.8;  0.6;  0.1;  0.7;  0.9;  0.6;  0.3;  0.1;  ...
0.1;  0.4;  1.0;  1.0;  0.1];

fprintf('\n                                Iteration\n');
fprintf('             Time       2         3         4         5         6\n');

% Loop over each block of data.
miema = m2-m1+1;
iema = cell(numel(nb), 1);
fmt = '%3d    %10.1f    %8.3f  %8.3f  %8.3f  %8.3f  %8.3f\n';
for i = 1:numel(nb)
if i == 1
% Initialise the iterated EMA
[iema{i}, p, pn, rcomm, ifail] = ...
g13mf(z{i}, t{i}, tau, m1, m2, sinit, inter, ftype, p, x);
else
% Update the iterated EMA for this block of data
[iema{i}, p, pn, rcomm, ifail] = ...
g13mf(z{i}, t{i}, tau, m1, m2, ...
sinit, inter, ftype, p, x, 'pn', pn, 'rcomm', rcomm);
end

% Display the results for this block of data
for j=1:nb(i)
fprintf(fmt, pn-nb(i)+j, t{i}(j), iema{i}(j, 1:miema));
end
fprintf('\n');
end
```
```

Iteration
Time       2         3         4         5         6
1           7.5       0.433     0.320     0.237     0.175     0.130
2           8.2       0.479     0.361     0.268     0.198     0.147
3          18.1       0.756     0.700     0.631     0.558     0.485
4          22.8       0.406     0.535     0.592     0.600     0.577
5          25.8       0.232     0.351     0.459     0.530     0.561

6          26.8       0.217     0.301     0.406     0.491     0.540
7          31.1       0.357     0.309     0.318     0.364     0.422
8          38.4       0.630     0.556     0.490     0.445     0.425
9          45.9       0.263     0.357     0.407     0.428     0.432
10          48.2       0.241     0.284     0.343     0.388     0.413
11          48.9       0.279     0.277     0.325     0.372     0.403
12          57.9       0.713     0.617     0.543     0.496     0.469
13          58.5       0.717     0.643     0.566     0.511     0.478
14          63.9       0.385     0.495     0.541     0.546     0.531
15          65.2       0.346     0.432     0.502     0.533     0.535

16          66.6       0.330     0.384     0.453     0.504     0.526
17          67.4       0.315     0.364     0.427     0.483     0.515
18          69.3       0.409     0.367     0.389     0.435     0.478
19          69.9       0.459     0.385     0.386     0.423     0.465
20          73.0       0.377     0.403     0.394     0.398     0.419
21          75.6       0.411     0.399     0.399     0.397     0.403
22          77.0       0.536     0.440     0.410     0.401     0.401
23          84.7       0.632     0.606     0.563     0.524     0.493
24          86.8       0.538     0.587     0.583     0.557     0.526
25          88.0       0.444     0.542     0.574     0.567     0.542
26          88.5       0.401     0.515     0.564     0.567     0.548
27          91.0       0.331     0.404     0.481     0.529     0.545
28          93.0       0.495     0.418     0.438     0.483     0.518
29          93.7       0.585     0.455     0.438     0.469     0.506
30          94.0       0.612     0.475     0.441     0.465     0.500

```