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

## Purpose

nag_matop_real_addsub (f01ct) adds two double matrices, each one optionally transposed and multiplied by a scalar.

## Syntax

[c, ifail] = f01ct(transa, transb, m, n, alpha, a, beta, b)
[c, ifail] = nag_matop_real_addsub(transa, transb, m, n, alpha, a, beta, b)

## Description

nag_matop_real_addsub (f01ct) performs one of the operations
• C : = αA + βB$C:=\alpha A+\beta B$,
• C : = αAT + βB$C:=\alpha {A}^{\mathrm{T}}+\beta B$,
• C : = αA + βBT$C:=\alpha A+\beta {B}^{\mathrm{T}}$ or
• C : = αAT + βBT$C:=\alpha {A}^{\mathrm{T}}+\beta {B}^{\mathrm{T}}$,
where A$A$, B$B$ and C$C$ are matrices, and α$\alpha$ and β$\beta$ are scalars. For efficiency, the function contains special code for the cases when one or both of α$\alpha$, β$\beta$ is equal to zero, unity or minus unity. The matrices, or their transposes, must be compatible for addition. A$A$ and B$B$ are either m$m$ by n$n$ or n$n$ by m$m$ matrices, depending on whether they are to be transposed before addition. C$C$ is an m$m$ by n$n$ matrix.

None.

## Parameters

### Compulsory Input Parameters

1:     transa – string (length ≥ 1)
2:     transb – string (length ≥ 1)
transa and transb must specify whether or not the matrix A$A$ and the matrix B$B$, respectively, are to be transposed before addition.
transa or transb = 'N'${\mathbf{transb}}=\text{'N'}$
The matrix will not be transposed.
transa or transb = 'T'${\mathbf{transb}}=\text{'T'}$ or 'C'$\text{'C'}$
The matrix will be transposed.
Constraint: transa​ or ​transb = 'N'${\mathbf{transa}}\text{​ or ​}{\mathbf{transb}}=\text{'N'}$, 'T'$\text{'T'}$ or 'C'$\text{'C'}$.
3:     m – int64int32nag_int scalar
m$m$, the number of rows of the matrices A$A$ and B$B$ or their transposes. Also the number of rows of the matrix C$C$.
Constraint: m0${\mathbf{m}}\ge 0$.
4:     n – int64int32nag_int scalar
n$n$, the number of columns of the matrices A$A$ and B$B$ or their transposes. Also the number of columns of the matrix C$C$.
Constraint: n0${\mathbf{n}}\ge 0$.
5:     alpha – double scalar
The scalar α$\alpha$, by which matrix A$A$ is multiplied before addition.
6:     a(lda, : $:$) – double array
The first dimension, lda, of the array a must satisfy
• if transa = 'N'${\mathbf{transa}}=\text{'N'}$, ldamax (1,m)$\mathit{lda}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• otherwise ldamax (1,n)$\mathit{lda}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\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)$ if transa = 'N'${\mathbf{transa}}=\text{'N'}$, and at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ otherwise
If α = 0.0$\alpha =0.0$, the elements of array a need not be assigned. If α0.0$\alpha \ne 0.0$, then if transa = 'N'${\mathbf{transa}}=\text{'N'}$, the leading m$m$ by n$n$ part of a must contain the matrix A$A$, otherwise the leading n$n$ by m$m$ part of a must contain the matrix A$A$.
7:     beta – double scalar
The scalar β$\beta$, by which matrix B$B$ is multiplied before addition.
8:     b(ldb, : $:$) – double array
The first dimension, ldb, of the array b must satisfy
• if transb = 'N'${\mathbf{transb}}=\text{'N'}$, ldbmax (1,m)$\mathit{ldb}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• otherwise ldbmax (1,n)$\mathit{ldb}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\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)$ if transb = 'N'${\mathbf{transb}}=\text{'N'}$, and at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ otherwise
If β = 0.0$\beta =0.0$, the elements of array b need not be assigned. If β0.0$\beta \ne 0.0$, then if transa = 'N'${\mathbf{transa}}=\text{'N'}$, the leading m$m$ by n$n$ part of b must contain the matrix B$B$, otherwise the leading n$n$ by m$m$ part of b must contain the matrix B$B$.

None.

lda ldb ldc

### Output Parameters

1:     c(ldc, : $:$) – double array
The first dimension of the array c 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)$
ldcmax (1,m)$\mathit{ldc}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
The elements of the m$m$ by n$n$ matrix C$C$.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, one or both of transa or transb is not equal to 'N', 'T' or 'C'.
ifail = 2${\mathbf{ifail}}=2$
 On entry, one or both of m or n is less than 0$0$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, lda < max (1,P)$\mathit{lda}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,P\right)$, where P = m$\mathrm{P}={\mathbf{m}}$ if transa = 'N'${\mathbf{transa}}=\text{'N'}$, and P = n$\mathrm{P}={\mathbf{n}}$ otherwise.
ifail = 4${\mathbf{ifail}}=4$
 On entry, ldb < max (1,P)$\mathit{ldb}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,P\right)$, where P = m$\mathrm{P}={\mathbf{m}}$ if transb = 'N'${\mathbf{transb}}=\text{'N'}$, and P = n$\mathrm{P}={\mathbf{n}}$ otherwise.
ifail = 5${\mathbf{ifail}}=5$
 On entry, ldc < max (1,m)$\mathit{ldc}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.

## Accuracy

The results returned by nag_matop_real_addsub (f01ct) are accurate to machine precision.

The time taken for a call of nag_matop_real_addsub (f01ct) varies with m, n and the values of α$\alpha$ and β$\beta$. The function is quickest if either or both of α$\alpha$ and β$\beta$ are equal to zero, or plus or minus unity.

## Example

```function nag_matop_real_addsub_example
transa = 'N';
transb = 'N';
m = int64(4);
n = int64(3);
alpha = 1;
a = [1, 2.5, 3;
-2, 2, -1.5;
3.5, 2, -2.5;
1.5, -2, 1];
beta = 1;
b = [2, -2.5, -2;
1, 1, 1;
-1.5, 2.5, -2.5;
2, -2, 1];
[c, ifail] = nag_matop_real_addsub(transa, transb, m, n, alpha, a, beta, b)
```
```

c =

3.0000         0    1.0000
-1.0000    3.0000   -0.5000
2.0000    4.5000   -5.0000
3.5000   -4.0000    2.0000

ifail =

0

```
```function f01ct_example
transa = 'N';
transb = 'N';
m = int64(4);
n = int64(3);
alpha = 1;
a = [1, 2.5, 3;
-2, 2, -1.5;
3.5, 2, -2.5;
1.5, -2, 1];
beta = 1;
b = [2, -2.5, -2;
1, 1, 1;
-1.5, 2.5, -2.5;
2, -2, 1];
[c, ifail] = f01ct(transa, transb, m, n, alpha, a, beta, b)
```
```

c =

3.0000         0    1.0000
-1.0000    3.0000   -0.5000
2.0000    4.5000   -5.0000
3.5000   -4.0000    2.0000

ifail =

0

```