PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_specfun_polygamma_deriv (s14ad)
Purpose
nag_specfun_polygamma_deriv (s14ad) returns a sequence of values of scaled derivatives of the psi function (also known as the digamma function).
Syntax
Description
nag_specfun_polygamma_deriv (s14ad) computes
values of the function
for
,
,
, where
is the psi function
and
denotes the
th derivative of
.
The function is derived from the function PSIFN in
Amos (1983). The basic method of evaluation of
is the asymptotic series
for large
greater than a machine-dependent value
, followed by backward recurrence using
for smaller values of
, where
when
,
when
, and
,
, are the Bernoulli numbers.
When
is large, the above procedure may be inefficient, and the expansion
which converges rapidly for large
, is used instead.
References
Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Amos D E (1983) Algorithm 610: A portable FORTRAN subroutine for derivatives of the psi function ACM Trans. Math. Software 9 494–502
Parameters
Compulsory Input Parameters
- 1:
– double scalar
-
The argument of the function.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
The index of the first member of the sequence of functions.
Constraint:
.
- 3:
– int64int32nag_int scalar
-
The number of members required in the sequence
, for .
Constraint:
.
Optional Input Parameters
None.
Output Parameters
- 1:
– double array
-
The first
elements of
ans contain the required values
, for
.
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
-
-
-
-
-
No results are returned because underflow is likely. Either
x or
is too large. If possible, reduce the value of
m and call
nag_specfun_polygamma_deriv (s14ad) again.
-
-
No results are returned because overflow is likely. Either
x is too small, or
is too large. If possible, reduce the value of
m and call
nag_specfun_polygamma_deriv (s14ad) again.
-
-
No results are returned because there is not enough internal workspace to continue computation.
may be too large. If possible, reduce the value of
m and call
nag_specfun_polygamma_deriv (s14ad) again.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
All constants in nag_specfun_polygamma_deriv (s14ad) are given to approximately digits of precision. Calling the number of digits of precision in the floating-point arithmetic being used , then clearly the maximum number of correct digits in the results obtained is limited by . Empirical tests of nag_specfun_polygamma_deriv (s14ad), taking values of in the range , and in the range , have shown that the maximum relative error is a loss of approximately two decimal places of precision. Tests with , i.e., testing the function , have shown somewhat better accuracy, except at points close to the zero of , , where only absolute accuracy can be obtained.
Further Comments
The time taken for a call of nag_specfun_polygamma_deriv (s14ad) is approximately proportional to , plus a constant. In general, it is much cheaper to call nag_specfun_polygamma_deriv (s14ad) with greater than to evaluate the function , for , rather than to make separate calls of nag_specfun_polygamma_deriv (s14ad).
Example
This example reads values of the argument from a file, evaluates the function at each value of and prints the results.
Open in the MATLAB editor:
s14ad_example
function s14ad_example
fprintf('s14ad example results\n\n');
x = [0.1 0.5 3.6 8];
n = size(x,2);
k = int64(0);
m = int64(4);
result = zeros(m,n);
for j=1:n
[result(:,j), ifail] = s14ad(x(j),k,m);
end
disp(' x psi -psi'' psi''''/2! -psi''''''/3!');
for j=1:n
fprintf('%5.1f',x(j));
fprintf('%12.4e',result(:,j));
fprintf('\n');
end
s14ad example results
x psi -psi' psi''/2! -psi'''/3!
0.1 1.0424e+01 1.0143e+02 1.0009e+03 1.0001e+04
0.5 1.9635e+00 4.9348e+00 8.4144e+00 1.6235e+01
3.6 -1.1357e+00 3.1988e-01 5.0750e-02 1.0653e-02
8.0 -2.0156e+00 1.3314e-01 8.8498e-03 7.8321e-04
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015