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_trans_inplace (f01cr)

## Purpose

nag_matop_real_gen_trans_inplace (f01cr) transposes a rectangular matrix in-situ.

## Syntax

[a, ifail] = f01cr(a, m, n, 'mn', mn)
[a, ifail] = nag_matop_real_gen_trans_inplace(a, m, n, 'mn', mn)

## Description

nag_matop_real_gen_trans_inplace (f01cr) requires that the elements of an $m$ by $n$ matrix $A$ are stored consecutively by columns in a one-dimensional array. It reorders the elements so that on exit the array holds the transpose of $A$ stored in the same way. For example, if $m=4$ and $n=3$, on entry the array must hold:
 $a11 a21 a31 a41 a12 a22 a32 a42 a13 a23 a33 a43$
and on exit it holds
 $a11 a12 a13 a21 a22 a23 a31 a32 a33 a41 a42 a43.$

## References

Cate E G and Twigg D W (1977) Algorithm 513: Analysis of in-situ transposition ACM Trans. Math. Software 3 104–110

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{a}\left({\mathbf{mn}}\right)$ – double array
The elements of the $m$ by $n$ matrix $A$, stored by columns.
2:     $\mathrm{m}$int64int32nag_int scalar
$m$, the number of rows of the matrix $A$.
3:     $\mathrm{n}$int64int32nag_int scalar
$n$, the number of columns of the matrix $A$.

### Optional Input Parameters

1:     $\mathrm{mn}$int64int32nag_int scalar
Default: the dimension of the array a.
$n$, the value $m×n$.

### Output Parameters

1:     $\mathrm{a}\left({\mathbf{mn}}\right)$ – double array
The elements of the transpose matrix, also stored by columns.
2:     $\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, ${\mathbf{mn}}\ne {\mathbf{m}}×{\mathbf{n}}$.
${\mathbf{ifail}}=2$
 On entry, $\mathit{lmove}\le 0$.
${\mathbf{ifail}}<0$
A serious error has occurred. Check all function calls and array sizes. Seek expert help.
${\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

Exact results are produced.

The time taken by nag_matop_real_gen_trans_inplace (f01cr) is approximately proportional to $mn$.

## Example

This example transposes a $7$ by $3$ matrix and prints out, for convenience, its transpose.
```function f01cr_example

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

a = [ 1    2    3    4    5    6    7;
8    9   10   11   12   13   14;
15   16   17   18   19   20   21];
[m,n] = size(a);

[atrans, ifail] = f01cr(a, int64(m), int64(n));

atrans = reshape(atrans,[n,m]);
disp('Transpose of A');
disp(atrans);

```
```f01cr example results

Transpose of A
1     8    15
2     9    16
3    10    17
4    11    18
5    12    19
6    13    20
7    14    21

```