nag_matop_real_addsub (f01ct) performs one of the operations
- ,
- ,
- or
- ,
where
,
and
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.
and
are either
by
or
by
matrices, depending on whether they are to be transposed before addition.
is an
by
matrix.
None.
None.
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.
The following program reads in a pair of matrices
and
, along with values for
transa,
transb,
alpha and
beta, and adds them together, printing the result matrix
. The process is continued until the end of the input stream is reached.
function f01ct_example
fprintf('f01ct example results\n\n');
a = [ 1.0 2.5 3.0;
-2.0 2.0 -1.5;
3.5 2.0 -2.5;
1.5 -2.0 1.0];
b = [ 2.0 -2.5 -2.0;
1.0 1.0 1.0;
-1.5 2.5 -2.5;
2.0 -2.0 1.0];
[m,n] = size(a);
m = int64(m);
n = int64(n);
transa = 'N';
transb = 'N';
alpha = 1;
beta = 1;
[c1, ifail] = f01ct( ...
transa, transb, m, n, alpha, a, beta, b);
disp('Example 1: C = A + B');
disp(c1);
a = [ 1.0 2.5 3.0 1.5 2.5;
-2.0 2.0 -1.5 -2.0 -1.0;
3.5 2.0 -2.5 -1.5 2.5];
b = [ 2.0 -2.5 -2.0;
1.0 1.0 1.0;
-1.5 2.5 -2.5;
2.0 -2.0 1.0;
1.0 1.0 2.5];
[m,n] = size(a);
m = int64(m);
n = int64(n);
transa = 'N';
transb = 'T';
alpha = 1;
beta = -1;
[c2, ifail] = f01ct( ...
transa, transb, m, n, alpha, a, beta, b);
disp('Example 2: C = A - B''');
disp(c2);