PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_linsys_real_gen_lsqsol (f04am)
Purpose
nag_linsys_real_gen_lsqsol (f04am) 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.
Syntax
[
x,
qr,
alpha,
ipiv,
ifail] = f04am(
a,
b,
eps, 'm',
m, 'n',
n, 'ir',
ir)
[
x,
qr,
alpha,
ipiv,
ifail] = nag_linsys_real_gen_lsqsol(
a,
b,
eps, 'm',
m, 'n',
n, 'ir',
ir)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: |
m was made optional |
Description
To compute the least squares solution to a set of linear equations in unknowns , nag_linsys_real_gen_lsqsol (f04am) 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.
References
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag
Parameters
Compulsory Input Parameters
- 1:
– double array
-
lda, the first dimension of the array, must satisfy the constraint
.
The by matrix .
- 2:
– double array
-
ldb, the first dimension of the array, must satisfy the constraint
.
The by right-hand side matrix .
- 3:
– double scalar
-
Must be set to the value of the
machine precision.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the arrays
a,
b. (An error is raised if these dimensions are not equal.)
, the number of rows of the matrix , i.e., the number of equations.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
a.
, the number of columns of the matrix , i.e., the number of unknowns.
Constraint:
.
- 3:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
b.
, the number of right-hand sides.
Output Parameters
- 1:
– double array
-
The by solution matrix .
- 2:
– double array
-
Details of the factorization.
- 3:
– double array
-
The diagonal elements of the upper triangular matrix .
- 4:
– int64int32nag_int array
-
Details of the column interchanges.
- 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:
-
-
The rank of is less than ; the problem does not have a unique solution.
-
-
The iterative refinement fails to converge, i.e., the matrix is too ill-conditioned.
-
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
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).
Further Comments
The time taken by nag_linsys_real_gen_lsqsol (f04am) is approximately proportional to , provided is small compared with .
Example
This example calculates the accurate least squares solution of the equations
Open in the MATLAB editor:
f04am_example
function f04am_example
fprintf('f04am example results\n\n');
a = [1.1, 0.9;
1.2, 1;
1, 1];
b = [2.2;
2.3;
2.1];
epsilon = x02aj;
[x, qr, alpha, ipiv, ifail] = f04am( ...
a, b, epsilon);
disp('Solution');
disp(x);
f04am example results
Solution
1.3010
0.7935
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015