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_stat_pdf_normal_vector (g01kq)

## Purpose

nag_stat_pdf_normal_vector (g01kq) returns a number of values of the probability density function (PDF), or its logarithm, for the Normal (Gaussian) distributions.

## Syntax

[pdf, ivalid, ifail] = g01kq(ilog, x, xmu, xstd, 'lx', lx, 'lxmu', lxmu, 'lxstd', lxstd)
[pdf, ivalid, ifail] = nag_stat_pdf_normal_vector(ilog, x, xmu, xstd, 'lx', lx, 'lxmu', lxmu, 'lxstd', lxstd)

## Description

The Normal distribution with mean μi${\mu }_{i}$, variance σi2${{\sigma }_{i}}^{2}$; has probability density function (PDF)
 f (xi,μi,σi) = 1/( σi×sqrt(2π) ) e − (xi − μi)2 / 2σi2 ,  σi > 0 . $f (xi,μi,σi) = 1 σi⁢2π e -(xi-μi)2/2σi2 , σi>0 .$
The input arrays to this function are designed to allow maximum flexibility in the supply of vector parameters by re-using elements of any arrays that are shorter than the total number of evaluations required. See Section [Vectorized s] in the G01 Chapter Introduction for further information.

None.

## Parameters

### Compulsory Input Parameters

1:     ilog – int64int32nag_int scalar
The value of ilog determines whether the logarithmic value is returned in PDF.
ilog = 0${\mathbf{ilog}}=0$
f(xi,μi,σi)$f\left({x}_{i},{\mu }_{i},{\sigma }_{i}\right)$, the probability density function is returned.
ilog = 1${\mathbf{ilog}}=1$
log(f(xi,μi,σi))$\mathrm{log}\left(f\left({x}_{i},{\mu }_{i},{\sigma }_{i}\right)\right)$, the logarithm of the probability density function is returned.
Constraint: ilog = 0${\mathbf{ilog}}=0$ or 1$1$.
2:     x(lx) – double array
lx, the dimension of the array, must satisfy the constraint lx > 0${\mathbf{lx}}>0$.
xi${x}_{i}$, the values at which the PDF is to be evaluated with xi = x(j)${x}_{i}={\mathbf{x}}\left(j\right)$, j = ((i1)  mod  lx) + 1, for i = 1,2,,max (lx,lxstd,lxmu)$i=1,2,\dots ,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{lx}},{\mathbf{lxstd}},{\mathbf{lxmu}}\right)$.
3:     xmu(lxmu) – double array
lxmu, the dimension of the array, must satisfy the constraint lxmu > 0${\mathbf{lxmu}}>0$.
μi${\mu }_{i}$, the means with μi = xmu(j)${\mu }_{i}={\mathbf{xmu}}\left(j\right)$, j = ((i1)  mod  lxmu) + 1.
4:     xstd(lxstd) – double array
lxstd, the dimension of the array, must satisfy the constraint lxstd > 0${\mathbf{lxstd}}>0$.
σi${\sigma }_{i}$, the standard deviations with σi = xstd(j)${\sigma }_{i}={\mathbf{xstd}}\left(j\right)$, j = ((i1)  mod  lxstd) + 1.
Constraint: xstd(j)0.0${\mathbf{xstd}}\left(\mathit{j}\right)\ge 0.0$, for j = 1,2,,lxstd$\mathit{j}=1,2,\dots ,{\mathbf{lxstd}}$.

### Optional Input Parameters

1:     lx – int64int32nag_int scalar
Default: The dimension of the array x.
The length of the array x.
Constraint: lx > 0${\mathbf{lx}}>0$.
2:     lxmu – int64int32nag_int scalar
Default: The dimension of the array xmu.
The length of the array xmu.
Constraint: lxmu > 0${\mathbf{lxmu}}>0$.
3:     lxstd – int64int32nag_int scalar
Default: The dimension of the array xstd.
The length of the array xstd.
Constraint: lxstd > 0${\mathbf{lxstd}}>0$.

None.

### Output Parameters

1:     pdf( : $:$) – double array
Note: the dimension of the array pdf must be at least max (lx,lxstd,lxmu)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{lx}},{\mathbf{lxstd}},{\mathbf{lxmu}}\right)$.
f(xi,μi,σi)$f\left({x}_{i},{\mu }_{i},{\sigma }_{i}\right)$ or log(f(xi,μi,σi))$\mathrm{log}\left(f\left({x}_{i},{\mu }_{i},{\sigma }_{i}\right)\right)$.
2:     ivalid( : $:$) – int64int32nag_int array
Note: the dimension of the array ivalid must be at least max (lx,lxstd,lxmu)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{lx}},{\mathbf{lxstd}},{\mathbf{lxmu}}\right)$.
ivalid(i)${\mathbf{ivalid}}\left(i\right)$ indicates any errors with the input arguments, with
ivalid(i) = 0${\mathbf{ivalid}}\left(i\right)=0$
No error.
ivalid(i) = 1${\mathbf{ivalid}}\left(i\right)=1$
σi < 0${\sigma }_{i}<0$.
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:

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

W ifail = 1${\mathbf{ifail}}=1$
On entry, at least one value of xstd was invalid.
ifail = 2${\mathbf{ifail}}=2$
Constraint: ilog = 0${\mathbf{ilog}}=0$ or 1$1$.
ifail = 3${\mathbf{ifail}}=3$
Constraint: lx > 0${\mathbf{lx}}>0$.
ifail = 4${\mathbf{ifail}}=4$
Constraint: lxmu > 0${\mathbf{lxmu}}>0$.
ifail = 5${\mathbf{ifail}}=5$
Constraint: lxstd > 0${\mathbf{lxstd}}>0$.

Not applicable.

None.

## Example

```function nag_stat_pdf_normal_vector_example
x =     [1.0, 4.0, 0.1, 1.0];
xmean = [0.0, 2.0, 0.0, 0.0];
xstd =  [1.0, 1.0, 0.01, 10];
ilog = int64(0);
[pdf, ivalid, ifail] = nag_stat_pdf_normal_vector(ilog, x, xmean, xstd);

fprintf('\n  x             mean          standard      result\n');
fprintf('                              deviation\n');
lx     = numel(x);
lxmean = numel(xmean);
lxstd  = numel(xstd);
len = max ([lx, lxmean, lxstd]);
for i=0:len-1
fprintf('%13.5e %13.5e %13.5e %13.5e %3d\n', x(mod(i,lx)+1), ...
xmean(mod(i,lxmean)+1), xstd(mod(i,lxstd)+1), pdf(i+1), ivalid(i+1));
end
```
```

x             mean          standard      result
deviation
1.00000e+00   0.00000e+00   1.00000e+00   2.41971e-01   0
4.00000e+00   2.00000e+00   1.00000e+00   5.39910e-02   0
1.00000e-01   0.00000e+00   1.00000e-02   7.69460e-21   0
1.00000e+00   0.00000e+00   1.00000e+01   3.96953e-02   0

```
```function g01kq_example
x =     [1.0, 4.0, 0.1, 1.0];
xmean = [0.0, 2.0, 0.0, 0.0];
xstd =  [1.0, 1.0, 0.01, 10];
ilog = int64(0);
[pdf, ivalid, ifail] = g01kq(ilog, x, xmean, xstd);

fprintf('\n  x             mean          standard      result\n');
fprintf('                              deviation\n');
lx     = numel(x);
lxmean = numel(xmean);
lxstd  = numel(xstd);
len = max ([lx, lxmean, lxstd]);
for i=0:len-1
fprintf('%13.5e %13.5e %13.5e %13.5e %3d\n', x(mod(i,lx)+1), ...
xmean(mod(i,lxmean)+1), xstd(mod(i,lxstd)+1), pdf(i+1), ivalid(i+1));
end
```
```

x             mean          standard      result
deviation
1.00000e+00   0.00000e+00   1.00000e+00   2.41971e-01   0
4.00000e+00   2.00000e+00   1.00000e+00   5.39910e-02   0
1.00000e-01   0.00000e+00   1.00000e-02   7.69460e-21   0
1.00000e+00   0.00000e+00   1.00000e+01   3.96953e-02   0

```