Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_dggglm (f08zb)

## Purpose

nag_lapack_dggglm (f08zb) solves a real general Gauss–Markov linear (least squares) model problem.

## Syntax

[a, b, d, x, y, info] = f08zb(a, b, d, 'm', m, 'n', n, 'p', p)
[a, b, d, x, y, info] = nag_lapack_dggglm(a, b, d, 'm', m, 'n', n, 'p', p)

## Description

nag_lapack_dggglm (f08zb) solves the real general Gauss–Markov linear model (GLM) problem
 minimize ‖y‖2  subject to  d = Ax + By x
$minimize x ‖y‖2 subject to d=Ax+By$
where A$A$ is an m$m$ by n$n$ matrix, B$B$ is an m$m$ by p$p$ matrix and d$d$ is an m$m$ element vector. It is assumed that nmn + p$n\le m\le n+p$, rank(A) = n$\mathrm{rank}\left(A\right)=n$ and rank(E) = m$\mathrm{rank}\left(E\right)=m$, where E =
 ( A B )
$E=\left(\begin{array}{cc}A& B\end{array}\right)$. Under these assumptions, the problem has a unique solution x$x$ and a minimal 2$2$-norm solution y$y$, which is obtained using a generalized QR$QR$ factorization of the matrices A$A$ and B$B$.
In particular, if the matrix B$B$ is square and nonsingular, then the GLM problem is equivalent to the weighted linear least squares problem
 minimize ‖B − 1(d − Ax)‖2. x
$minimize x ‖ B-1 (d-Ax) ‖2 .$

## References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia
Anderson E, Bai Z and Dongarra J (1992) Generalized QR factorization and its applications Linear Algebra Appl. (Volume 162–164) 243–271

## Parameters

### Compulsory Input Parameters

1:     a(lda, : $:$) – double array
The first dimension of the array a must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The m$m$ by n$n$ matrix A$A$.
2:     b(ldb, : $:$) – double array
The first dimension of the array b must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array must be at least max (1,p)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{p}}\right)$
The m$m$ by p$p$ matrix B$B$.
3:     d(m) – double array
m, the dimension of the array, must satisfy the constraint m0${\mathbf{m}}\ge 0$.
The left-hand side vector d$d$ of the GLM equation.

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the array d and the first dimension of the array b. (An error is raised if these dimensions are not equal.)
m$m$, the number of rows of the matrices A$A$ and B$B$.
Constraint: m0${\mathbf{m}}\ge 0$.
2:     n – int64int32nag_int scalar
Default: The second dimension of the array a.
n$n$, the number of columns of the matrix A$A$.
Constraint: 0nm$0\le {\mathbf{n}}\le {\mathbf{m}}$.
3:     p – int64int32nag_int scalar
Default: The second dimension of the array b.
p$p$, the number of columns of the matrix B$B$.
Constraint: pmn${\mathbf{p}}\ge {\mathbf{m}}-{\mathbf{n}}$.

### Input Parameters Omitted from the MATLAB Interface

lda ldb work lwork

### Output Parameters

1:     a(lda, : $:$) – double array
The first dimension of the array a will be max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
2:     b(ldb, : $:$) – double array
The first dimension of the array b will be max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array will be max (1,p)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{p}}\right)$
3:     d(m) – double array
4:     x(n) – double array
The solution vector x$x$ of the GLM problem.
5:     y(p) – double array
The solution vector y$y$ of the GLM problem.
6:     info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: m, 2: n, 3: p, 4: a, 5: lda, 6: b, 7: ldb, 8: d, 9: x, 10: y, 11: work, 12: lwork, 13: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
INFO = 1${\mathbf{INFO}}=1$
The upper triangular factor R$R$ associated with A$A$ in the generalized RQ$RQ$ factorization of the pair (A,B)$\left(A,B\right)$ is singular, so that rank(A) < m$\mathrm{rank}\left(A\right); the least squares solution could not be computed.
INFO = 2${\mathbf{INFO}}=2$
The bottom (NM)$\left(N-M\right)$ by (NM)$\left(N-M\right)$ part of the upper trapezoidal factor T$T$ associated with B$B$ in the generalized QR$QR$ factorization of the pair (A,B)$\left(A,B\right)$ is singular, so that rank
 ( A B )
< N
$\mathrm{rank}\left(\begin{array}{cc}A& B\end{array}\right); the least squares solutions could not be computed.

## Accuracy

For an error analysis, see Anderson et al. (1992). See also Section 4.6 of Anderson et al. (1999).

When p = mn$p=m\ge n$, the total number of floating point operations is approximately (2/3)(2m3n3) + 4nm2$\frac{2}{3}\left(2{m}^{3}-{n}^{3}\right)+4n{m}^{2}$; when p = m = n$p=m=n$, the total number of floating point operations is approximately (14/3)m3$\frac{14}{3}{m}^{3}$.

## Example

```function nag_lapack_dggglm_example
a = [-0.57, -1.28, -0.39;
-1.93, 1.08, -0.31;
2.3, 0.24, -0.4;
-0.02, 1.03, -1.43];
b = [0.5, 0, 0, 0;
0, 1, 0, 0;
0, 0, 2, 0;
0, 0, 0, 5];
d = [1.32;
-4;
5.52;
3.24];
[aOut, bOut, dOut, x, y, info] = nag_lapack_dggglm(a, b, d)
```
```

aOut =

3.0562   -0.2694   -0.0232
0.5322   -1.9623    0.7189
-0.6343   -0.1120    1.3913
0.0055    0.2893    0.5605

bOut =

-1.2131    0.2669   -0.8691    0.6131
-0.5707    0.7105    1.8876    1.8248
0.1229    0.2076    2.4417    2.9277
-0.0373   -0.1437   -0.2765   -2.3759

dOut =

1.9889
-1.0058
-2.9911
-0.0094

x =

1.9889
-1.0058
-2.9911

y =

-0.0006
-0.0025
-0.0047
0.0077

info =

0

```
```function f08zb_example
a = [-0.57, -1.28, -0.39;
-1.93, 1.08, -0.31;
2.3, 0.24, -0.4;
-0.02, 1.03, -1.43];
b = [0.5, 0, 0, 0;
0, 1, 0, 0;
0, 0, 2, 0;
0, 0, 0, 5];
d = [1.32;
-4;
5.52;
3.24];
[aOut, bOut, dOut, x, y, info] = f08zb(a, b, d)
```
```

aOut =

3.0562   -0.2694   -0.0232
0.5322   -1.9623    0.7189
-0.6343   -0.1120    1.3913
0.0055    0.2893    0.5605

bOut =

-1.2131    0.2669   -0.8691    0.6131
-0.5707    0.7105    1.8876    1.8248
0.1229    0.2076    2.4417    2.9277
-0.0373   -0.1437   -0.2765   -2.3759

dOut =

1.9889
-1.0058
-2.9911
-0.0094

x =

1.9889
-1.0058
-2.9911

y =

-0.0006
-0.0025
-0.0047
0.0077

info =

0

```