PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_matop_real_gen_tridiag_lu (f01le)
Purpose
nag_matop_real_gen_tridiag_lu (f01le) computes an factorization of a real tridiagonal matrix, using Gaussian elimination with partial pivoting.
Syntax
[
a,
b,
c,
d,
ipiv,
ifail] = f01le(
a,
lambda,
b,
c,
tol, 'n',
n)
[
a,
b,
c,
d,
ipiv,
ifail] = nag_matop_real_gen_tridiag_lu(
a,
lambda,
b,
c,
tol, 'n',
n)
Description
The matrix
, where
is a real
by
tridiagonal matrix, is factorized as
where
is a permutation matrix,
is a unit lower triangular matrix with at most one nonzero subdiagonal element per column, and
is an upper triangular matrix with at most two nonzero superdiagonal elements per column.
The factorization is obtained by Gaussian elimination with partial pivoting and implicit row scaling.
An indication of whether or not the matrix
is nearly singular is returned in the
th element of the array
ipiv. If it is important that
is nonsingular, as is usually the case when solving a system of tridiagonal equations, then it is strongly recommended that
is inspected on return from
nag_matop_real_gen_tridiag_lu (f01le). (See the argument
ipiv and
Further Comments for further details.)
The argument
is included in the function so that
nag_matop_real_gen_tridiag_lu (f01le) may be used, in conjunction with
nag_linsys_real_tridiag_fac_solve (f04le), to obtain eigenvectors of
by inverse iteration.
References
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The diagonal elements of .
- 2:
– double scalar
-
The scalar . nag_matop_real_gen_tridiag_lu (f01le) factorizes .
- 3:
– double array
-
The superdiagonal elements of , stored in to ; is not used.
- 4:
– double array
-
The subdiagonal elements of , stored in to ; is not used.
- 5:
– double scalar
-
A relative tolerance used to indicate whether or not the matrix (
) is nearly singular.
tol should normally be chosen as approximately the largest relative error in the elements of
. For example, if the elements of
are correct to about
significant figures, then
tol should be set to about
. See
Further Comments for further details on how
tol is used. If
tol is supplied as less than
, where
is the
machine precision, then the value
is used in place of
tol.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
a,
b,
c. (An error is raised if these dimensions are not equal.)
, the order of the matrix .
Constraint:
.
Output Parameters
- 1:
– double array
-
The diagonal elements of the upper triangular matrix .
- 2:
– double array
-
The elements of the first superdiagonal of , stored in to .
- 3:
– double array
-
The subdiagonal elements of , stored in to .
- 4:
– double array
-
The elements of the second superdiagonal of , stored in to ; and are not used.
- 5:
– int64int32nag_int array
-
Details of the permutation matrix
. If an interchange occurred at the
th step of the elimination, then
, otherwise
. If a diagonal element of
is small, indicating that
is nearly singular, then the element
is returned as positive. Otherwise
is returned as
. See
Further Comments for further details. If the application is such that it is important that
is not nearly singular, then it is strongly recommended that
is inspected on return.
- 6:
– 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:
-
-
-
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
The computed factorization will satisfy the equation
where
where
is the
machine precision.
Further Comments
The time taken by nag_matop_real_gen_tridiag_lu (f01le) is approximately proportional to .
The factorization of a tridiagonal matrix proceeds in steps, each step eliminating one subdiagonal element of the tridiagonal matrix. In order to avoid small pivot elements and to prevent growth in the size of the elements of , rows and () will, if necessary, be interchanged at the th step prior to the elimination.
The element
returns the smallest integer,
, for which
where
denotes the sum of the absolute values of the
th row of the matrix (
). If no such
exists, then
is returned as zero. If such a
exists, then
is small and hence (
) is singular or nearly singular.
This function may be followed by
nag_linsys_real_tridiag_fac_solve (f04le) to solve systems of tridiagonal equations. If you wish to solve single systems of tridiagonal equations you should be aware of
nag_lapack_dgtsv (f07ca), which solves tridiagonal systems with a single call.
nag_lapack_dgtsv (f07ca) requires less storage and will generally be faster than the combination of
nag_matop_real_gen_tridiag_lu (f01le) and
nag_linsys_real_tridiag_fac_solve (f04le), but no test for near singularity is included in
nag_lapack_dgtsv (f07ca) and so it should only be used when the equations are known to be nonsingular.
Example
This example factorizes the tridiagonal matrix
where
and then to solve the equations
, where
by a call to
nag_linsys_real_tridiag_fac_solve (f04le). The example program sets
and, of course, sets
.
Open in the MATLAB editor:
f01le_example
function f01le_example
fprintf('f01le example results\n\n');
b = [0 2.1 -1 1.9 8];
a = [3 2.3 -5 -0.9 7.1];
c = [0 3.4 3.6 7 -6];
lambda = 0;
tol = 5e-05;
[D, U1, L, U2, ipiv, ifail] = f01le( ...
a, lambda, b, c, tol);
fprintf('Details of factorization\n\n');
disp(' Main diagonal of U');
disp(D);
disp(' First super-diagonal of U');
disp(U1(2:end));
disp(' Second super-diagonal of U');
disp(U2(3:end)');
disp(' Multipliers');
disp(L(2:end));
disp(' Vector of interchanges');
disp(double(ipiv(1:end-1))');
y = [2.7 -0.5 2.6 0.6 2.7 ];
job = int64(1);
[x, ~, ifail] = f04le( ...
job, D, U1, L, U2, ipiv, y, tol);
disp('Solution vector:');
disp(x);
f01le example results
Details of factorization
Main diagonal of U
3.0000 3.6000 7.0000 -6.0000 1.1508
First super-diagonal of U
2.1000 -5.0000 -0.9000 7.1000
Second super-diagonal of U
0 1.9000 8.0000
Multipliers
1.1333 -0.0222 -0.1587 0.0168
Vector of interchanges
0 1 1 1
Solution vector:
-4.0000 7.0000 3.0000 -4.0000 -3.0000
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015