NAG FL Interface
f04amf (real_gen_lsqsol)
1
Purpose
f04amf calculates the accurate least squares solution of a set of linear equations in unknowns, and rank , with multiple right-hand sides, , using a factorization and iterative refinement.
2
Specification
Fortran Interface
Subroutine f04amf ( |
a, lda, x, ldx, b, ldb, m, n, ir, eps, qr, ldqr, alpha, e, y, z, r, ipiv, ifail) |
Integer, Intent (In) |
:: |
lda, ldx, ldb, m, n, ir, ldqr |
Integer, Intent (Inout) |
:: |
ifail |
Integer, Intent (Out) |
:: |
ipiv(n) |
Real (Kind=nag_wp), Intent (In) |
:: |
a(lda,n), b(ldb,ir), eps |
Real (Kind=nag_wp), Intent (Inout) |
:: |
x(ldx,ir), qr(ldqr,n) |
Real (Kind=nag_wp), Intent (Out) |
:: |
alpha(n), e(n), y(n), z(n), r(m) |
|
C Header Interface
#include <nag.h>
void |
f04amf_ (const double a[], const Integer *lda, double x[], const Integer *ldx, const double b[], const Integer *ldb, const Integer *m, const Integer *n, const Integer *ir, const double *eps, double qr[], const Integer *ldqr, double alpha[], double e[], double y[], double z[], double r[], Integer ipiv[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
f04amf_ (const double a[], const Integer &lda, double x[], const Integer &ldx, const double b[], const Integer &ldb, const Integer &m, const Integer &n, const Integer &ir, const double &eps, double qr[], const Integer &ldqr, double alpha[], double e[], double y[], double z[], double r[], Integer ipiv[], Integer &ifail) |
}
|
The routine may be called by the names f04amf or nagf_linsys_real_gen_lsqsol.
3
Description
To compute the least squares solution to a set of linear equations in unknowns , f04amf first computes a factorization of with column pivoting, , where is upper triangular, is an by orthogonal matrix, and is a permutation matrix. is applied to the by right-hand side matrix to give , and the by solution matrix is calculated, to a first approximation, by back-substitution in . The residual matrix is calculated using additional precision, and a correction to is computed as the least squares solution to . is replaced by and this iterative refinement of the solution is repeated until full machine accuracy has been obtained.
4
References
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag
5
Arguments
-
1:
– Real (Kind=nag_wp) array
Input
-
On entry: the by matrix .
-
2:
– Integer
Input
-
On entry: the first dimension of the array
a as declared in the (sub)program from which
f04amf is called.
Constraint:
.
-
3:
– Real (Kind=nag_wp) array
Output
-
On exit: the by solution matrix .
-
4:
– Integer
Input
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
f04amf is called.
Constraint:
.
-
5:
– Real (Kind=nag_wp) array
Input
-
On entry: the by right-hand side matrix .
-
6:
– Integer
Input
-
On entry: the first dimension of the array
b as declared in the (sub)program from which
f04amf is called.
Constraint:
.
-
7:
– Integer
Input
-
On entry: , the number of rows of the matrix , i.e., the number of equations.
Constraint:
.
-
8:
– Integer
Input
-
On entry: , the number of columns of the matrix , i.e., the number of unknowns.
Constraint:
.
-
9:
– Integer
Input
-
On entry: , the number of right-hand sides.
-
10:
– Real (Kind=nag_wp)
Input
-
On entry: must be set to the value of the machine precision.
-
11:
– Real (Kind=nag_wp) array
Output
-
On exit: details of the factorization.
-
12:
– Integer
Input
-
On entry: the first dimension of the array
qr as declared in the (sub)program from which
f04amf is called.
Constraint:
.
-
13:
– Real (Kind=nag_wp) array
Output
-
On exit: the diagonal elements of the upper triangular matrix .
-
14:
– Real (Kind=nag_wp) array
Workspace
-
-
15:
– Real (Kind=nag_wp) array
Workspace
-
-
16:
– Real (Kind=nag_wp) array
Workspace
-
-
17:
– Real (Kind=nag_wp) array
Workspace
-
-
18:
– Integer array
Output
-
On exit: details of the column interchanges.
-
19:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
The rank of
a is less than
n. The problem does not have a unique solution.
-
The iterative refinement fails to converge. The matrix is too ill-conditioned.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
Although the correction process is continued until the solution has converged to full machine accuracy, all the figures in the final solution may not be correct since the correction
to
is itself the solution to a linear least squares problem. For a detailed error analysis see page 116 of
Wilkinson and Reinsch (1971).
8
Parallelism and Performance
f04amf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The time taken by f04amf is approximately proportional to , provided is small compared with .
10
Example
This example calculates the accurate least squares solution of the equations
10.1
Program Text
10.2
Program Data
10.3
Program Results