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_real_addsub (f01ct)

Purpose

nag_matop_real_addsub (f01ct) adds two double matrices, each one optionally transposed and multiplied by a scalar.

Syntax

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

Description

nag_matop_real_addsub (f01ct) performs one of the operations where AA, BB and CC are matrices, and αα and ββ are scalars. 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. AA and BB are either mm by nn or nn by mm matrices, depending on whether they are to be transposed before addition. CC is an mm by nn 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 AA and the matrix BB, respectively, are to be transposed before addition.
transa or transb = 'N'transb='N'
The matrix will not be transposed.
transa or transb = 'T'transb='T' or 'C''C'
The matrix will be transposed.
Constraint: transa​ or ​transb = 'N'transa​ or ​transb='N', 'T''T' or 'C''C'.
3:     m – int64int32nag_int scalar
mm, the number of rows of the matrices AA and BB or their transposes. Also the number of rows of the matrix CC.
Constraint: m0m0.
4:     n – int64int32nag_int scalar
nn, the number of columns of the matrices AA and BB or their transposes. Also the number of columns of the matrix CC.
Constraint: n0n0.
5:     alpha – double scalar
The scalar αα, by which matrix AA is multiplied before addition.
6:     a(lda, : :) – double array
The first dimension, lda, of the array a must satisfy
  • if transa = 'N'transa='N', ldamax (1,m)ldamax(1,m);
  • otherwise ldamax (1,n)ldamax(1,n).
The second dimension of the array must be at least max (1,n)max(1,n) if transa = 'N'transa='N', and at least max (1,m)max(1,m) otherwise
If α = 0.0α=0.0, the elements of array a need not be assigned. If α0.0α0.0, then if transa = 'N'transa='N', the leading mm by nn part of a must contain the matrix AA, otherwise the leading nn by mm part of a must contain the matrix AA.
7:     beta – double scalar
The scalar ββ, by which matrix BB is multiplied before addition.
8:     b(ldb, : :) – double array
The first dimension, ldb, of the array b must satisfy
  • if transb = 'N'transb='N', ldbmax (1,m)ldbmax(1,m);
  • otherwise ldbmax (1,n)ldbmax(1,n).
The second dimension of the array must be at least max (1,n)max(1,n) if transb = 'N'transb='N', and at least max (1,m)max(1,m) otherwise
If β = 0.0β=0.0, the elements of array b need not be assigned. If β0.0β0.0, then if transa = 'N'transa='N', the leading mm by nn part of b must contain the matrix BB, otherwise the leading nn by mm part of b must contain the matrix BB.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

lda ldb ldc

Output Parameters

1:     c(ldc, : :) – double array
The first dimension of the array c will be max (1,m)max(1,m)
The second dimension of the array will be max (1,n)max(1,n)
ldcmax (1,m)ldcmax(1,m).
The elements of the mm by nn matrix CC.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,one or both of transa or transb is not equal to 'N', 'T' or 'C'.
  ifail = 2ifail=2
On entry,one or both of m or n is less than 00.
  ifail = 3ifail=3
On entry,lda < max (1,P)lda<max(1,P), where P = mP=m if transa = 'N'transa='N', and P = nP=n otherwise.
  ifail = 4ifail=4
On entry,ldb < max (1,P)ldb<max(1,P), where P = mP=m if transb = 'N'transb='N', and P = nP=n otherwise.
  ifail = 5ifail=5
On entry,ldc < max (1,m)ldc<max(1,m).

Accuracy

The results returned by nag_matop_real_addsub (f01ct) are accurate to machine precision.

Further Comments

The time taken for a call of nag_matop_real_addsub (f01ct) 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

function nag_matop_real_addsub_example
transa = 'N';
transb = 'N';
m = int64(4);
n = int64(3);
alpha = 1;
a = [1, 2.5, 3;
     -2, 2, -1.5;
     3.5, 2, -2.5;
     1.5, -2, 1];
beta = 1;
b = [2, -2.5, -2;
     1, 1, 1;
     -1.5, 2.5, -2.5;
     2, -2, 1];
[c, ifail] = nag_matop_real_addsub(transa, transb, m, n, alpha, a, beta, b)
 

c =

    3.0000         0    1.0000
   -1.0000    3.0000   -0.5000
    2.0000    4.5000   -5.0000
    3.5000   -4.0000    2.0000


ifail =

                    0


function f01ct_example
transa = 'N';
transb = 'N';
m = int64(4);
n = int64(3);
alpha = 1;
a = [1, 2.5, 3;
     -2, 2, -1.5;
     3.5, 2, -2.5;
     1.5, -2, 1];
beta = 1;
b = [2, -2.5, -2;
     1, 1, 1;
     -1.5, 2.5, -2.5;
     2, -2, 1];
[c, ifail] = f01ct(transa, transb, m, n, alpha, a, beta, b)
 

c =

    3.0000         0    1.0000
   -1.0000    3.0000   -0.5000
    2.0000    4.5000   -5.0000
    3.5000   -4.0000    2.0000


ifail =

                    0



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–2013