PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_matop_real_gen_matrix_fun_usd (f01em)
Purpose
nag_matop_real_gen_matrix_fun_usd (f01em) computes the matrix function, , of a real by matrix , using analytical derivatives of you have supplied.
Syntax
Description
is computed using the Schur–Parlett algorithm described in
Higham (2008) and
Davies and Higham (2003).
The scalar function
, and the derivatives of
, are returned by the function
f which, given an integer
, should evaluate
at a number of (generally complex) points
, for
. For any
on the real line,
must also be real.
nag_matop_real_gen_matrix_fun_usd (f01em) is therefore appropriate for functions that can be evaluated on the complex plane and whose derivatives, of arbitrary order, can also be evaluated on the complex plane.
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
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
-
Given an integer
, the function
f evaluates
at a number of points
.
[iflag, fz, user] = f(m, iflag, nz, z, user)
Input Parameters
- 1:
– int64int32nag_int scalar
-
The order,
, of the derivative required.
If , should be returned. For , should be returned.
- 2:
– int64int32nag_int scalar
-
- 3:
– int64int32nag_int scalar
-
, the number of function or derivative values required.
- 4:
– complex array
-
The points at which the function is to be evaluated.
- 5:
– Any MATLAB object
f is called from
nag_matop_real_gen_matrix_fun_usd (f01em) with the object supplied to
nag_matop_real_gen_matrix_fun_usd (f01em).
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 for a particular
. If
iflag is returned as nonzero then
nag_matop_real_gen_matrix_fun_usd (f01em) will terminate the computation, with
.
- 2:
– complex array
-
The function or derivative 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_usd (f01em), 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_usd (f01em) 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 function has given a reliable answer.
If has real eigenvalues, nag_matop_real_gen_matrix_fun_usd (f01em) 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.
-
-
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 routine 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. This should give a very accurate result. In general, however, no error bounds are available for the algorithm. See Section 9.4 of
Higham (2008) for further discussion of the Schur–Parlett algorithm.
Further Comments
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 evaluating
and its derivatives.
If the derivatives of
are not known analytically, then
nag_matop_real_gen_matrix_fun_num (f01el) can be used to evaluate
using numerical differentiation.
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_usd (f01em).
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_usd (f01jc) should be used.
nag_matop_complex_gen_matrix_fun_usd (f01fm) can be used to find the matrix function
for a complex matrix
.
Example
This example finds the
where
Open in the MATLAB editor:
f01em_example
function f01em_example
fprintf('f01em example results\n\n');
a = [1, 0, -2, 1;
-1, 2, 0, 1;
2, 0, 1, 0;
1, 0, -1, 2];
[exp2a, user, iflag, imnorm, ifail] = ...
f01em(a, @f);
disp('f(A) = exp(2A)');
disp(exp2a);
fprintf('Imnorm = %6.2f\n',imnorm);
function [iflag, fz, user] = f(m, iflag, nz, z, user)
fz = double(2^m)*exp(2*z);
f01em example results
f(A) = exp(2A)
-12.1880 0 -3.4747 8.3697
-13.7274 54.5982 -23.9801 82.8593
-9.7900 0 -25.4527 26.5294
-18.1597 0 -34.8991 49.2404
Imnorm = 0.00
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015