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

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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, variance σi2; has probability density function (PDF)
f xi,μi,σi = 1 σi2π e -xi-μi2/2σi2 ,  σi>0 .  
The input arrays to this function are designed to allow maximum flexibility in the supply of vector arguments by re-using elements of any arrays that are shorter than the total number of evaluations required. See Vectorized Routines in the G01 Chapter Introduction for further information.

References

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
fxi,μi,σi, the probability density function is returned.
ilog=1
logfxi,μi,σi, the logarithm of the probability density function is returned.
Constraint: ilog=0 or 1.
2:     xlx – double array
xi, the values at which the PDF is to be evaluated with xi=xj, j=i-1 mod lx+1, for i=1,2,,maxlx,lxstd,lxmu.
3:     xmulxmu – double array
μi, the means with μi=xmuj, j=i-1 mod lxmu+1.
4:     xstdlxstd – double array
σi, the standard deviations with σi=xstdj, j=i-1 mod lxstd+1.
Constraint: xstdj0.0, for j=1,2,,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.
2:     lxmu int64int32nag_int scalar
Default: the dimension of the array xmu.
The length of the array xmu.
Constraint: lxmu>0.
3:     lxstd int64int32nag_int scalar
Default: the dimension of the array xstd.
The length of the array xstd.
Constraint: lxstd>0.

Output Parameters

1:     pdf: – double array
The dimension of the array pdf will be maxlx,lxstd,lxmu
fxi,μi,σi or logfxi,μi,σi.
2:     ivalid: int64int32nag_int array
The dimension of the array ivalid will be maxlx,lxstd,lxmu
ivalidi indicates any errors with the input arguments, with
ivalidi=0
No error.
ivalidi=1
σi<0.
3:     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:

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
On entry, at least one value of xstd was invalid.
Check ivalid for more information.
   ifail=2
Constraint: ilog=0 or 1.
   ifail=3
Constraint: lx>0.
   ifail=4
Constraint: lxmu>0.
   ifail=5
Constraint: lxstd>0.
   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 xi with differing μi and σi.
function g01kq_example


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

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

g01kq_plot;



function g01kq_plot
 
  fig1 = figure;
  hold on;
  xmean  = [0, 0,   1];
  xstd   = [1, 0.3, 0.6];
  ilog = int64(0);
  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
    [y{i}, ifail] = g01kq( ...
			   ilog, x{i}, xmean(i), xstd(i));
    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;
g01kq example results


  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
g01kq_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