PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_matop_real_gen_matrix_fun_num (f01el)
Purpose
nag_matop_real_gen_matrix_fun_num (f01el) computes the matrix function, , of a real by matrix . Numerical differentiation is used to evaluate the derivatives of when they are required.
Syntax
Description
is computed using the Schur–Parlett algorithm described in
Higham (2008) and
Davies and Higham (2003). The coefficients of the Taylor series used in the algorithm are evaluated using the numerical differentiation algorithm of
Lyness and Moler (1967).
The scalar function
is supplied via function
f which evaluates
at a number of points
.
References
Davies P I and Higham N J (2003) A Schur–Parlett algorithm for computing matrix functions. SIAM J. Matrix Anal. Appl. 25(2) 464–485
Higham N J (2008) Functions of Matrices: Theory and Computation SIAM, Philadelphia, PA, USA
Lyness J N and Moler C B (1967) Numerical differentiation of analytic functions SIAM J. Numer. Anal. 4(2) 202–210
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The first dimension of the array
a must be at least
.
The second dimension of the array
a must be at least
.
The by matrix .
- 2:
– function handle or string containing name of m-file
-
The function
f evaluates
at a number of points
.
[iflag, fz, user] = f(iflag, nz, z, user)
Input Parameters
- 1:
– int64int32nag_int scalar
-
- 2:
– int64int32nag_int scalar
-
, the number of function values required.
- 3:
– complex array
-
The points at which the function is to be evaluated.
- 4:
– Any MATLAB object
f is called from
nag_matop_real_gen_matrix_fun_num (f01el) with the object supplied to
nag_matop_real_gen_matrix_fun_num (f01el).
Output Parameters
- 1:
– int64int32nag_int scalar
-
iflag should either be unchanged from its entry value of zero, or may be set nonzero to indicate that there is a problem in evaluating the function
; for instance
may not be defined. If
iflag is returned as nonzero then
nag_matop_real_gen_matrix_fun_num (f01el) will terminate the computation, with
.
- 2:
– complex array
-
The function values.
should return the value , for . If lies on the real line, then so must .
- 3:
– Any MATLAB object
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
a.
, the order of the matrix .
Constraint:
.
- 2:
– Any MATLAB object
user is not used by
nag_matop_real_gen_matrix_fun_num (f01el), but is passed to
f. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use
user.
Output Parameters
- 1:
– double array
-
The first dimension of the array
a will be
.
The second dimension of the array
a will be
.
The by matrix, .
- 2:
– Any MATLAB object
- 3:
– int64int32nag_int scalar
-
, unless
iflag has been set nonzero inside
f, in which case
iflag will be the value set and
ifail will be set to
.
- 4:
– double scalar
-
If
has complex eigenvalues,
nag_matop_real_gen_matrix_fun_num (f01el) will use complex arithmetic to compute
. The imaginary part is discarded at the end of the computation, because it will theoretically vanish.
imnorm contains the
-norm of the imaginary part, which should be used to check that the routine has given a reliable answer.
If
a has real eigenvalues,
nag_matop_real_gen_matrix_fun_num (f01el) uses real arithmetic and
.
- 5:
– 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:
-
-
A Taylor series failed to converge after terms. Further Taylor series coefficients can no longer reliably be obtained by numerical differentiation.
-
-
iflag has been set nonzero by the user.
-
-
There was an error whilst reordering the Schur form of .
Note: this failure should not occur and suggests that the function has been called incorrectly.
-
-
The function was unable to compute the Schur decomposition of .
Note: this failure should not occur and suggests that the function has been called incorrectly.
-
-
An unexpected internal error occurred. Please contact
NAG.
-
-
Input argument number is invalid.
-
-
On entry, argument lda is invalid.
Constraint: .
-
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
For a normal matrix
(for which
) the Schur decomposition is diagonal and the algorithm reduces to evaluating
at the eigenvalues of
and then constructing
using the Schur vectors. See Section 9.4 of
Higham (2008) for further discussion of the Schur–Parlett algorithm, and
Lyness and Moler (1967) for a discussion of numerical differentiation.
Further Comments
The integer allocatable memory required is . If has real eigenvalues then up to of double allocatable memory may be required. If has complex eigenvalues then up to of complex allocatable memory may be required.
The cost of the Schur–Parlett algorithm depends on the spectrum of
, but is roughly between
and
floating-point operations. There is an additional cost in numerically differentiating
, in order to obtain the Taylor series coefficients. If the derivatives of
are known analytically, then
nag_matop_real_gen_matrix_fun_usd (f01em) can be used to evaluate
more accurately. If
is real symmetric then it is recommended that
nag_matop_real_symm_matrix_fun (f01ef) be used as it is more efficient and, in general, more accurate than
nag_matop_real_gen_matrix_fun_num (f01el).
For any on the real line, must be real. must also be complex analytic on the spectrum of . These conditions ensure that is real for real .
For further information on matrix functions, see
Higham (2008).
If estimates of the condition number of the matrix function are required then
nag_matop_real_gen_matrix_cond_num (f01jb) should be used.
nag_matop_complex_gen_matrix_fun_num (f01fl) can be used to find the matrix function
for a complex matrix
.
Example
This example finds
where
Open in the MATLAB editor:
f01el_example
function f01el_example
fprintf('f01el example results\n\n');
a = [3, 0, 1, 2;
-1, 1, 3, 1;
0, 2, 2, 1;
2, 1, -1, 1];
[cos2a, user, iflag, imnorm, ifail] = ...
f01el(a, @f);
disp('f(A) = cos(2A)');
disp(cos2a);
fprintf('Imnorm = %6.2f\n',imnorm);
function [iflag, fz, user] = f(iflag, nz, z, user)
fz = complex(cos(2*z));
f01el example results
f(A) = cos(2A)
-0.1704 -1.1597 -0.1878 -0.7307
-0.3950 -0.4410 0.7606 0.0655
-0.0950 -0.0717 0.0619 -0.4351
-0.1034 0.6424 -1.3964 0.1042
Imnorm = 0.00
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015