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_matop_real_gen_matmul (f01ck)

## Purpose

nag_matop_real_gen_matmul (f01ck) 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$.

## Syntax

[a, b, c, ifail] = f01ck(b, c, opt, 'n', n, 'p', p, 'm', m)
[a, b, c, ifail] = nag_matop_real_gen_matmul(b, c, opt, 'n', n, 'p', p, 'm', m)

## 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.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{b}\left({\mathbf{n}},{\mathbf{m}}\right)$ – double array
The $n$ by $m$ matrix $B$.
2:     $\mathrm{c}\left({\mathbf{m}},{\mathbf{p}}\right)$ – double array
The $m$ by $p$ matrix $C$.
3:     $\mathrm{opt}$int64int32nag_int scalar
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$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array b.
$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$.
2:     $\mathrm{p}$int64int32nag_int scalar
Default: the second dimension of the array c.
$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$.
3:     $\mathrm{m}$int64int32nag_int scalar
Default: the first dimension of the array c and the second dimension of the array b. (An error is raised if these dimensions are not equal.)
$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 \mathit{iz}$;
• otherwise ${\mathbf{m}}\ge 1$.

### Output Parameters

1:     $\mathrm{a}\left({\mathbf{n}},{\mathbf{p}}\right)$ – double array
If ${\mathbf{opt}}=1$, a contains the result of the matrix multiplication.
2:     $\mathrm{b}\left({\mathbf{n}},{\mathbf{m}}\right)$ – double array
If ${\mathbf{opt}}=2$, b contains the result of the multiplication.
3:     $\mathrm{c}\left({\mathbf{m}},{\mathbf{p}}\right)$ – double array
If ${\mathbf{opt}}=3$, c contains the result of the multiplication.
4:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\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 $\mathit{iz}<{\mathbf{m}}$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

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

The time taken by nag_matop_real_gen_matmul (f01ck) is approximately proportional to $mnp$.

## 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$.
```function f01ck_example

fprintf('f01ck example results\n\n');

% Matrices B and C
b = [0, 1, 2;
1, 2, 3];
c = [0, 1;
1, 2;
2, 3];

% Calculate A = BC
opt = int64(1);
[a, b, c, ifail] = f01ck(b, c, opt);

disp('Martix A');
disp(a);

```
```f01ck example results

Martix A
5     8
8    14

```