hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_matop_complex_addsub (f01cw)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_matop_complex_addsub (f01cw) adds two complex matrices, each one optionally transposed and multiplied by a scalar.

Syntax

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

Description

nag_matop_complex_addsub (f01cw) performs one of the operations where A, B and C are matrices, α and β are scalars, T denotes transposition and H denotes conjugate transposition. For efficiency, the function contains special code for the cases when one or both of α, β 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.

References

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 and the matrix B, respectively, are to be transposed before addition.
transa or transb='N'
The matrix will not be transposed.
transa or transb='T'
The matrix will be transposed.
transa or transb='C'
The matrix will be transposed and conjugated.
Constraint: transa​ or ​transb='N', 'T' or 'C'.
3:     m int64int32nag_int scalar
m, the number of rows of the matrices A and B or their transposes. Also the number of rows of the matrix C.
Constraint: m0.
4:     n int64int32nag_int scalar
n, the number of columns of the matrices A and B or their transposes. Also the number of columns of the matrix C.
Constraint: n0.
5:     alpha – complex scalar
The scalar α, by which matrix A is multiplied before addition.
6:     alda: – complex array
The first dimension, lda, of the array a must satisfy
  • if transa='N', ldamax1,m;
  • otherwise ldamax1,n.
The second dimension of the array a must be at least max1,n if alpha0 and transa='N', max1,m if alpha0 and transa='T' or 'C' and at least 1 if alpha=0.
The matrix A. If α=0, the array a is not referenced.
7:     beta – complex scalar
The scalar β, by which matrix B is multiplied before addition.
8:     bldb: – complex array
The first dimension, ldb, of the array b must satisfy
  • if transb='N', ldbmax1,m;
  • otherwise ldbmax1,n.
The second dimension of the array b must be at least max1,n if beta0 and transb='N', max1,m if beta0 and transb='T' or 'C' and at least 1 if beta=0.
The matrix B. If β=0, the array b is not referenced.

Optional Input Parameters

None.

Output Parameters

1:     cldc: – complex array
The first dimension of the array c will be max1,m.
The second dimension of the array c will be max1,n.
The elements of the m by n matrix C.
2:     ifail int64int32nag_int scalar
ifail=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
On entry,one or both of transa or transb is not equal to 'N', 'T' or 'C'.
   ifail=2
On entry,one or both of m or n is less than 0.
   ifail=3
On entry,lda<max1,P, where P=m if transa='N', and P=n otherwise.
   ifail=4
On entry,ldb<max1,P, where P=m if transb='N', and P=n otherwise.
   ifail=5
On entry,ldc<max1,m.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

The results returned by nag_matop_complex_addsub (f01cw) are accurate to machine precision.

Further Comments

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

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.
function f01cw_example


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

% Example 1: C = A + B
a = [ 1.0 + 2.0i   2.5 - 1.5i   2.5 - 1.0i;
     -2.0 - 2.0i   2.0 - 1.0i  -1.5 - 1.0i;
      3.5 - 1.5i   2.0 + 1.5i   2.0 + 3.0i;
     -2.5 + 0.0i  -3.0 + 2.5i  -2.0 + 2.0i];
b = [ 2.0 + 1.0i  -2.5 + 3.0i  -0.5 + 0.0i;
      1.0 + 0.0i   1.0 - 1.5i   1.5 - 1.5i;
     -1.5 - 0.5i   2.5 - 2.0i  -0.5 + 1.0i;
      2.5 - 1.5i  -1.0 + 1.5i   2.0 + 3.0i];

[m,n] = size(a);
m = int64(m);
n = int64(n);

transa = 'N';
transb = 'N';
alpha  = complex(1);
beta   = complex(1);
[c1, ifail] = f01cw( ...
                     transa, transb, m, n, alpha, a, beta, b);

disp('Example 1: C = A + B');
disp(c1);

% Example 2: C = A - B^T
a = [ 1.0 + 1.0i   2.5 - 1.5i   3.0 + 1.5i;
     -2.0 - 0.5i   2.0 + 1.5i  -1.5 - 2.5i];
b = [ 2.0 + 1.0i  -2.5 + 2.0i;
      1.0 + 0.0i   1.0 + 1.5i;
     -1.5 - 0.5i   2.5 - 1.0i]; 
[m,n] = size(a);
m = int64(m);
n = int64(n);

transa = 'N';
transb = 'T';
alpha  = complex(1);
beta   = complex(-1);
[c2, ifail] = f01cw( ...
                     transa, transb, m, n, alpha, a, beta, b);

disp('Example 2: C = A - B^T');
disp(c2);


f01cw example results

Example 1: C = A + B
   3.0000 + 3.0000i   0.0000 + 1.5000i   2.0000 - 1.0000i
  -1.0000 - 2.0000i   3.0000 - 2.5000i   0.0000 - 2.5000i
   2.0000 - 2.0000i   4.5000 - 0.5000i   1.5000 + 4.0000i
   0.0000 - 1.5000i  -4.0000 + 4.0000i   0.0000 + 5.0000i

Example 2: C = A - B^T
  -1.0000 + 0.0000i   1.5000 - 1.5000i   4.5000 + 2.0000i
   0.5000 - 2.5000i   1.0000 + 0.0000i  -4.0000 - 1.5000i


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015