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 (g01ka)

## Purpose

nag_stat_pdf_normal (g01ka) returns the value of the probability density function (PDF) for the Normal (Gaussian) distribution with mean $\mu$ and variance ${\sigma }^{2}$ at a point $x$.

## Syntax

[result, ifail] = g01ka(x, xmean, xstd)
[result, ifail] = nag_stat_pdf_normal(x, xmean, xstd)

## Description

The Normal distribution has probability density function (PDF)
 $fx = 1 σ ⁢ 2π e -x-μ2/2σ2 , σ>0 .$

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}$ – double scalar
$x$, the value at which the PDF is to be evaluated.
2:     $\mathrm{xmean}$ – double scalar
$\mu$, the mean of the Normal distribution.
3:     $\mathrm{xstd}$ – double scalar
$\sigma$, the standard deviation of the Normal distribution.
Constraint: $z<{\mathbf{xstd}}\sqrt{2\pi }<1.0/z$, where $z={\mathbf{x02am}}\left(\right)$, the safe range parameter.

None.

### Output Parameters

1:     $\mathrm{result}$ – double scalar
The result of the function.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
If ${\mathbf{ifail}}\ne {\mathbf{0}}$, then nag_stat_pdf_normal (g01ka) returns $0.0$.
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{xstd}}×\sqrt{2.0\pi }>U$, where $U$ is the safe range parameter as defined by nag_machine_real_safe (x02am).
${\mathbf{ifail}}=2$
Computation abandoned owing to underflow of $\frac{1}{\left(\sigma ×\sqrt{2\pi }\right)}$.
${\mathbf{ifail}}=3$
Computation abandoned owing to an internal calculation overflowing.
This rarely occurs, and is the result of extreme values of the arguments x, xmean or xstd.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Not applicable.

None.

## Example

This example prints the value of the Normal distribution PDF at four different points x with differing xmean and xstd.
function g01ka_example

fprintf('g01ka example results\n\n');

x      = [1, 4, 0.1,   1];
xmean  = [0, 2, 0,     0];
xstd   = [1, 1, 0.01, 10];
result = x;
fprintf('  x             mean          standard      pdf\n');
fprintf('                              deviation\n');

for i=1:numel(x)
[result(i), ifail] = g01ka( ...
x(i), xmean(i), xstd(i));
end

fprintf('%13.5e %13.5e %13.5e %13.5e\n', [x; xmean; xstd; result]);

g01ka_plot;

function g01ka_plot

fig1 = figure;
hold on;
xmean  = [0, 0,   1];
xstd   = [1, 0.3, 0.6];
x{1} = [-3:0.05:3];
x{2} = [-1.2:0.025:1.2];
x{3} = [-1:0.05:3];
mu = '\mu';
sigma = '\sigma';
for i=1:3
for j=1:numel(x{i})
[y{i}(j), ifail] = g01ka( ...
x{i}(j), xmean(i), xstd(i));
end
plot(x{i},y{i});
l{i} = sprintf('%s = %3.1f, %s = %3.1f', mu, xmean(i), sigma, xstd(i));
end
legend(l);
xlabel('x');
title('Gaussian Functions (or Normal Distributions)');
hold off;

g01ka example results

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