F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF01CKF

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

F01CKF returns with the result of the multiplication of two matrices $B$ and $C$ in the matrix $A$, with the option to overwrite $B$ or $C$.

## 2  Specification

 SUBROUTINE F01CKF ( A, B, C, N, P, M, Z, IZ, OPT, IFAIL)
 INTEGER N, P, M, IZ, OPT, IFAIL REAL (KIND=nag_wp) A(N,P), B(N,M), C(M,P), Z(IZ)

## 3  Description

The $n$ by $m$ matrix $B$ is post-multiplied by the $m$ by $p$ matrix $C$. If ${\mathbf{OPT}}=1$ the result is formed in the $n$ by $p$ matrix $A$. If ${\mathbf{OPT}}=2$, $m$ must equal $p$, and the result is written back to $B$. If ${\mathbf{OPT}}=3$, $n$ must equal $m$, and the result is written back to $C$.

None.

## 5  Parameters

1:     A(N,P) – REAL (KIND=nag_wp) arrayOutput
On exit: if ${\mathbf{OPT}}=1$, A contains the result of the matrix multiplication.
2:     B(N,M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the $n$ by $m$ matrix $B$.
On exit: if ${\mathbf{OPT}}=2$, B contains the result of the multiplication.
3:     C(M,P) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the $m$ by $p$ matrix $C$.
On exit: if ${\mathbf{OPT}}=3$, C contains the result of the multiplication.
4:     N – INTEGERInput
On entry: $n$, the number of rows of the array $A$ and of the array $B$.
Constraints:
• if ${\mathbf{OPT}}=3$, ${\mathbf{N}}={\mathbf{M}}$;
• otherwise ${\mathbf{N}}\ge 1$.
5:     P – INTEGERInput
On entry: $p$, the number of columns of the array $A$ and of the array $C$.
Constraints:
• if ${\mathbf{OPT}}=2$, ${\mathbf{P}}={\mathbf{M}}$;
• otherwise ${\mathbf{P}}\ge 1$.
6:     M – INTEGERInput
On entry: $m$, the number of columns of the array $B$ and rows of the array $C$.
Constraints:
• if ${\mathbf{OPT}}=2$, ${\mathbf{M}}={\mathbf{P}}$;
• if ${\mathbf{OPT}}=3$, ${\mathbf{M}}={\mathbf{N}}$;
• if ${\mathbf{OPT}}\ne 1$, ${\mathbf{M}}\le {\mathbf{IZ}}$;
• otherwise ${\mathbf{M}}\ge 1$.
7:     Z(IZ) – REAL (KIND=nag_wp) arrayWorkspace
8:     IZ – INTEGERInput
On entry: the dimension of the array Z as declared in the (sub)program from which F01CKF is called.
Constraints:
• if ${\mathbf{OPT}}=1$, ${\mathbf{IZ}}\ge 1$;
• if ${\mathbf{OPT}}\ne 1$, ${\mathbf{IZ}}\ge {\mathbf{M}}$.
9:     OPT – INTEGERInput
On entry: the value of OPT determines which array is to contain the final result.
${\mathbf{OPT}}=1$
A must be distinct from B and C and, on exit, contains the result. B and C need not be distinct in this case.
${\mathbf{OPT}}=2$
B must be distinct from C and on exit, contains the result. A is not used in this case and need not be distinct from B or C.
${\mathbf{OPT}}=3$
C must be distinct from B and on exit, contains the result. A is not used in this case and need not be distinct from B or C.
Constraint: $1\le {\mathbf{OPT}}\le 3$.
10:   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, M or P or ${\mathbf{N}}\le 0$.
${\mathbf{IFAIL}}=2$
${\mathbf{OPT}}=2$ and ${\mathbf{M}}\ne {\mathbf{P}}$.
${\mathbf{IFAIL}}=3$
${\mathbf{OPT}}=3$ and ${\mathbf{N}}\ne {\mathbf{M}}$.
${\mathbf{IFAIL}}=4$
${\mathbf{OPT}}\ne 1$ and ${\mathbf{IZ}}<{\mathbf{M}}$.

## 7  Accuracy

Each element of the result is effectively computed as an inner product using basic precision.

The time taken by F01CKF is approximately proportional to $mnp$.

## 9  Example

This example multiplies the $2$ by $3$ matrix $B$ and the $3$ by $2$ matrix $C$ together and places the result in the $2$ by $2$ matrix $A$.

### 9.1  Program Text

Program Text (f01ckfe.f90)

### 9.2  Program Data

Program Data (f01ckfe.d)

### 9.3  Program Results

Program Results (f01ckfe.r)