Performs element-wise addition on two complex matrices stored in coordinate format, C ¬ aA + bB.
#include <imsl.h>
Imsl_c_sparse_elem *imsl_c_mat_add_coordinate (int n, int nz_a, f_complex alpha, Imsl_c_sparse_elem a[], int nz_b, f_complex beta, Imsl_c_sparse_elem b[], int *nz_c, ..., 0)
The type double function is imsl_z_mat_add_coordinate.
int n
(Input)
The order of the matrices A and B.
int nz_a
(Input)
Number of nonzeros in the matrix A.
f_complex alpha
(Input)
Scalar multiplier for A.
Imsl_c_sparse_elem a[]
(Input)
Vector of length nz_a containing the
location and value of each nonzero entry in the matrix A.
int nz_b
(Input)
Number of nonzeros in the matrix B.
f_complex beta
(Input)
Scalar multiplier for B.
Imsl_c_sparse_elem b[]
(Input)
Vector of length nz_b containing the
location and value of each nonzero entry in the matrix B.
int *nz_c
(Output)
The number of nonzeros in the sum aA + bB.
A pointer to an array of type Imsl_c_sparse_elem containing the computed sum. In the event of an error or if the return matrix has no nonzero elements, NULL is returned.
#include <imsl.h>
Imsl_c_sparse_elem
*imsl_c_mat_add_coordinate (int n, int nz_a, f_complex
alpha, Imsl_c_sparse_elem a[], int nz_b,
f_complex beta, Imsl_c_sparse_elem b[], int
*nz_c,
IMSL_A_TRANSPOSE,
IMSL_B_TRANSPOSE,
IMSL_A_CONJUGATE_TRANSPOSE,
IMSL_B_CONJUGATE_TRANSPOSE,
0)
IMSL_A_TRANSPOSE,
Replace
A with AT in the expression aA + bB.
IMSL_B_TRANSPOSE,
Replace
B with BT in the expression aA + bB.
IMSL_A_CONJUGATE_TRANSPOSE,
Replace
A with AH in the expression aA + bB.
IMSL_B_CONJUGATE_TRANSPOSE,
Replace
B with BH in the expression aA + bB.
The function imsl_c_mat_add_coordinate forms the sum aA + bB, given the scalars a and b, and the matrices A and B in coordinate format. The transpose or conjugate transpose of A and/or B may be used during the computation if optional arguments are specified. The method starts by storing A in a linked list data structure, and performs the multiply by a. Next the data in matrix B is traversed and if the coordinates of a nonzero element correspond to those of a nonzero element in A, that entry in the linked list is updated. Otherwise, a new node in the linked list is created. The multiply by b occurs at this time. Lastly, the linked list representation of C is converted to coordinate representation, omitting any elements that may have become zero through cancellation.
Add two complex matrices of order 4 stored in coordinate format. Matrix A has five nonzero elements. Matrix B has seven nonzero elements.
#include <imsl.h>
void main ()
{
Imsl_c_sparse_elem a[] = {0, 0, 3, 4,
0, 3, -1, 2,
1, 2, 5, -1,
2, 0, 1, 2,
3, 1, 3, 0};
Imsl_c_sparse_elem b[] = {0, 1, -2, 1,
0, 3, 1, -2,
1, 0, 3, 0,
2, 2, 5, 2,
2, 3, 1, 4,
3, 0, 4, 0,
3, 1, 3, -2};
int nz_a = 5, nz_b = 7, nz_c;
int n = 4, i;
f_complex alpha = {1.0, 0.0}, beta = {1.0, 0.0};
Imsl_c_sparse_elem *c;
c =
imsl_c_mat_add_coordinate(n, nz_a, alpha, a,
nz_b, beta, b, &nz_c, 0);
printf("
row column value\n");
for (i = 0; i < nz_c; i++)
printf("%3d %5d %8.2f %8.2f\n",
c[i].row, c[i].col, c[i].val.re, c[i].val.im);
free(c);
}
row column value
0 0 3.00 4.00
0 1 -2.00 1.00
1 0 3.00 0.00
1 2 5.00 -1.00
2 0 1.00 2.00
2 2 5.00 2.00
2 3 1.00 4.00
3 0 4.00 0.00
3 1 6.00 -2.00
Compute 2+3i*AT + 2-i*BT, where

#include <imsl.h>
void main ()
{
Imsl_c_sparse_elem a[] = {0, 0, 3, 4,
0, 3, -1, 2,
1, 2, 5, -1,
2, 0, 1, 2,
3, 1, 3, 0};
Imsl_c_sparse_elem b[] = {0, 1, -2, 1,
0, 3, 1, -2,
1, 0, 3, 0,
2, 2, 5, 2,
2, 3, 1, 4,
3, 0, 4, 0,
3, 1, 3, -2};
int nz_a = 5, nz_b = 7, nz_c;
int n = 4, i;
f_complex alpha = {2.0, 3.0}, beta = {2.0, -1.0};
Imsl_c_sparse_elem *c;
c =
imsl_c_mat_add_coordinate(n, nz_a, alpha, a,
nz_b, beta, b, &nz_c,
IMSL_A_TRANSPOSE,
IMSL_B_TRANSPOSE, 0);
printf("
row column value\n");
for (i = 0; i < nz_c; i++)
printf("%3d %5d %8.2f %8.2f\n",
c[i].row, c[i].col, c[i].val.re, c[i].val.im);
free(c);
}
row column value
0 0 -6.00 17.00
0 1 6.00 -3.00
0 2 -4.00 7.00
0 3 8.00 -4.00
1 0 -3.00 4.00
1 3 10.00 2.00
2 1 13.00 13.00
2 2 12.00 -1.00
3 0 -8.00 -4.00
3 2 6.00 7.00
|
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |