F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF01CTF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F01CTF adds two real matrices, each one optionally transposed and multiplied by a scalar.

## 2  Specification

 SUBROUTINE F01CTF ( TRANSA, TRANSB, M, N, ALPHA, A, LDA, BETA, B, LDB, C, LDC, IFAIL)
 INTEGER M, N, LDA, LDB, LDC, IFAIL REAL (KIND=nag_wp) ALPHA, A(LDA,*), BETA, B(LDB,*), C(LDC,*) CHARACTER(1) TRANSA, TRANSB

## 3  Description

F01CTF performs one of the operations
• $C:=\alpha A+\beta B$,
• $C:=\alpha {A}^{\mathrm{T}}+\beta B$,
• $C:=\alpha A+\beta {B}^{\mathrm{T}}$ or
• $C:=\alpha {A}^{\mathrm{T}}+\beta {B}^{\mathrm{T}}$,
where $A$, $B$ and $C$ are matrices, and $\alpha$ and $\beta$ are scalars. For efficiency, the routine 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$ and $B$ are either $m$ by $n$ or $n$ by $m$ matrices, depending on whether they are to be transposed before addition. $C$ is an $m$ by $n$ matrix.
None.

## 5  Parameters

1:     TRANSA – CHARACTER(1)Input
2:     TRANSB – CHARACTER(1)Input
On entry: TRANSA and TRANSB must specify whether or not the matrix $A$ and the matrix $B$, respectively, are to be transposed before addition.
TRANSA or ${\mathbf{TRANSB}}=\text{'N'}$
The matrix will not be transposed.
TRANSA or ${\mathbf{TRANSB}}=\text{'T'}$ or $\text{'C'}$
The matrix will be transposed.
Constraint: ${\mathbf{TRANSA}}\text{​ or ​}{\mathbf{TRANSB}}=\text{'N'}$, $\text{'T'}$ or $\text{'C'}$.
3:     M – INTEGERInput
On entry: $m$, the number of rows of the matrices $A$ and $B$ or their transposes. Also the number of rows of the matrix $C$.
Constraint: ${\mathbf{M}}\ge 0$.
4:     N – INTEGERInput
On entry: $n$, the number of columns of the matrices $A$ and $B$ or their transposes. Also the number of columns of the matrix $C$.
Constraint: ${\mathbf{N}}\ge 0$.
5:     ALPHA – REAL (KIND=nag_wp)Input
On entry: the scalar $\alpha$, by which matrix $A$ is multiplied before addition.
6:     A(LDA,$*$) – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array A must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ if ${\mathbf{TRANSA}}=\text{'N'}$, and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$ otherwise.
On entry: if $\alpha =0.0$, the elements of array A need not be assigned. If $\alpha \ne 0.0$, then if ${\mathbf{TRANSA}}=\text{'N'}$, the leading $m$ by $n$ part of A must contain the matrix $A$, otherwise the leading $n$ by $m$ part of A must contain the matrix $A$.
7:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F01CTF is called.
Constraints:
• if ${\mathbf{TRANSA}}=\text{'N'}$, ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$;
• otherwise ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
8:     BETA – REAL (KIND=nag_wp)Input
On entry: the scalar $\beta$, by which matrix $B$ is multiplied before addition.
9:     B(LDB,$*$) – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array B must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$ if ${\mathbf{TRANSB}}=\text{'N'}$, and at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$ otherwise.
On entry: if $\beta =0.0$, the elements of array B need not be assigned. If $\beta \ne 0.0$, then if ${\mathbf{TRANSA}}=\text{'N'}$, the leading $m$ by $n$ part of B must contain the matrix $B$, otherwise the leading $n$ by $m$ part of B must contain the matrix $B$.
10:   LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F01CTF is called.
Constraints:
• if ${\mathbf{TRANSB}}=\text{'N'}$, ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$;
• otherwise ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
11:   C(LDC,$*$) – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array C must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
On exit: the elements of the $m$ by $n$ matrix $C$.
12:   LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which F01CTF is called.
Constraint: ${\mathbf{LDC}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$.
13:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, one or both of TRANSA or TRANSB is not equal to 'N', 'T' or 'C'.
${\mathbf{IFAIL}}=2$
 On entry, one or both of M or N is less than $0$.
${\mathbf{IFAIL}}=3$
 On entry, ${\mathbf{LDA}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,P\right)$, where $\mathrm{P}={\mathbf{M}}$ if ${\mathbf{TRANSA}}=\text{'N'}$, and $\mathrm{P}={\mathbf{N}}$ otherwise.
${\mathbf{IFAIL}}=4$
 On entry, ${\mathbf{LDB}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,P\right)$, where $\mathrm{P}={\mathbf{M}}$ if ${\mathbf{TRANSB}}=\text{'N'}$, and $\mathrm{P}={\mathbf{N}}$ otherwise.
${\mathbf{IFAIL}}=5$
 On entry, ${\mathbf{LDC}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}\right)$.

## 7  Accuracy

The results returned by F01CTF are accurate to machine precision.

The time taken for a call of F01CTF varies with M, N and the values of $\alpha$ and $\beta$. The routine is quickest if either or both of $\alpha$ and $\beta$ are equal to zero, or plus or minus unity.

## 9  Example

The following program reads in a pair of matrices $A$ and $B$, along with values for TRANSA, TRANSB, ALPHA and BETA, and adds them together, printing the result matrix $C$. The process is continued until the end of the input stream is reached.

### 9.1  Program Text

Program Text (f01ctfe.f90)

### 9.2  Program Data

Program Data (f01ctfe.d)

### 9.3  Program Results

Program Results (f01ctfe.r)