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

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_stat_pdf_normal (g01ka) returns the value of the probability density function (PDF) for the Normal (Gaussian) distribution with mean μ and variance σ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 .  

References

None.

Parameters

Compulsory Input Parameters

1:     x – double scalar
x, the value at which the PDF is to be evaluated.
2:     xmean – double scalar
μ, the mean of the Normal distribution.
3:     xstd – double scalar
σ, the standard deviation of the Normal distribution.
Constraint: z<xstd2π<1.0/z, where z=x02am, the safe range parameter.

Optional Input Parameters

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     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:
If ifail0, then nag_stat_pdf_normal (g01ka) returns 0.0.
   ifail=1
Constraint: xstd×2.0π>U, where U is the safe range parameter as defined by nag_machine_real_safe (x02am).
   ifail=2
Computation abandoned owing to underflow of 1σ×2π.
   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.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

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
g01ka_fig1.png

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