CNLMath : Utilities : mat_mul_rect_coordinate (complex)
mat_mul_rect_coordinate (complex)
Computes the transpose of a matrix, a matrix-vector product, or a matrix-matrix product for all matrices stored in sparse coordinate form.
Synopsis
#include <imsl.h>
void *imsl_c_mat_mul_rect_coordinate (char *string, ..., 0)
The equivalent double function is imsl_d_mat_mul_rect_coordinate.
Required Arguments
char *string (Input)
String indicating matrix multiplication to be performed.
Return Value
The result of the multiplication. If the result is a vector, the return type is pointer to f_complex. If the result of the multiplication is a sparse matrix, the return type is pointer to Imsl_c_sparse_elem.
Synopsis with Optional Arguments
#include <imsl.h>
void *imsl_c_mat_mul_rect_coordinate (char *string,
IMSL_A_MATRIX, int nrowa, int ncola, int nza, Imsl_c_sparse_elem *a,
IMSL_B_MATRIX, int nrowb, int ncolb, int nzb, Imsl_c_sparse_elem *b,
IMSL_X_VECTOR, int nx, f_complex *x,
IMSL_RETURN_MATRIX_SIZE, int *size,
IMSL_RETURN_USER_VECTOR, f_complex vector_user[],
0)
Optional Arguments
IMSL_A_MATRIX, int nrowa, int ncola, int nza, Imsl_c_sparse_elem *a (Input)
The sparse matrix
with nza nonzero elements.
IMSL_B_MATRIX, int nrowb, int ncolb, int nzb, Imsl_c_sparse_elem *b (Input)
The sparse matrix
with nzb nonzero elements.
IMSL_X_VECTOR, int nx, f_complex *x, (Input)
The vector x of length nx.
IMSL_RETURN_MATRIX_SIZE, int *size, (Output)
If the function imsl_c_mat_mul_rect_coordinate returns a vector of type Imsl_c_sparse_elem, use this option to retrieve the length of the return vector, i.e. the number of nonzero elements in the sparse matrix generated by the requested computations.
IMSL_RETURN_USER_VECTOR, f_complex vector_user[], (Output)
If the result of the computation is a vector, return the answer in the user supplied space vector_user. It’s size depends on the computation.
Description
The function imsl_c_mat_mul_rect_coordinate computes a matrix-matrix product or a matrix-vector product, where the matrices are specified in coordinate representation. The operation performed is specified by string. For example, if “A*x” is given, Ax is computed. In string, the matrices A and B and the vector x can be used. Any of these names can be used with trans or ctrans, indicating transpose and conjugate transpose, respectively. The vector x is treated as a dense n × 1 matrix.
If string contains only one item, such as “x” or “trans(A)”, then a copy of the array, or its transpose is returned. Some multiplications, such as “A*ctrans(A)” or “trans(x)*B”, will produce a sparse matrix in coordinate format as a result. Other products such as “B*x” will produce a pointer to a complex type, containing the resulting vector.
The matrix and/or vector referred to in string must be given as optional arguments. Therefore, if string is “A*x”, IMSL_A_MATRIX and IMSL_X_VECTOR must be given.
To release this space, use imsl_free.
Examples
Example 1
Let
and
xT = (1 + i, 2 +2i, 3 + 3i, 4 + 4i, 5 +5i, 6 + 6i)
This example computes the product Ax.
 
#include <imsl.h>
 
int main()
{
Imsl_c_sparse_elem a[] = {0, 0, {10.0, 7.0},
1, 1, {3.0, 2.0},
1, 2, {-3.0, 0.0},
1, 3, {-1.0, 2.0},
2, 2, {4.0, 2.0},
3, 0, {-2.0, -4.0},
3, 3, {1.0, 6.0},
3, 4, {-1.0, 3.0},
4, 0, {-5.0, 4.0},
4, 3, {-5.0, 0.0},
4, 4, {12.0, 2.0},
4, 5, {-7.0, 7.0},
5, 0, {-1.0, 12.0},
5, 1, {-2.0, 8.0},
5, 5, {3.0, 7.0}};
f_complex b[] = {{1.0, 1.0}, {2.0, 2.0}, {3.0, 3.0},
{4.0, 4.0}, {5.0, 5.0}, {6.0, 6.0}};
 
int n = 6;
int nz = 15;
f_complex *x;
 
/* Set x = A*b */
 
x = imsl_c_mat_mul_rect_coordinate ("A*x",
IMSL_A_MATRIX, n, n, nz, a,
IMSL_X_VECTOR, n, b,
0);
 
imsl_c_write_matrix ("Product Ab", 1, n, x, 0);
}
Output
 
Product Ab
1 2 3
( 3, 17) ( -19, 5) ( 6, 18)
 
4 5 6
( -38, 32) ( -63, 49) ( -57, 83)
Example 2
Using the same matrix A and vector x given in the last example, the products Ax, ATx, AHx and AAH are computed.
 
#include <imsl.h>
#include <stdio.h>
 
int main()
{
Imsl_c_sparse_elem *z;
Imsl_c_sparse_elem a[] =
{0, 0, {10.0, 7.0},
1, 1, {3.0, 2.0},
1, 2, {-3.0, 0.0},
1, 3, {-1.0, 2.0},
2, 2, {4.0, 2.0},
3, 0, {-2.0, -4.0},
3, 3, {1.0, 6.0},
3, 4, {-1.0, 3.0},
4, 0, {-5.0, 4.0},
4, 3, {-5.0, 0.0},
4, 4, {12.0, 2.0},
4, 5, {-7.0, 7.0},
5, 0, {-1.0, 12.0},
5, 1, {-2.0, 8.0},
5, 5, {3.0, 7.0}};
 
f_complex x[] =
{{1.0, 1.0}, {2.0, 2.0}, {3.0, 3.0},
{4.0, 4.0}, {5.0, 5.0}, {6.0, 6.0}};
 
int n = 6, nz = 15, nz_z, i;
f_complex *b;
 
/* Set b = A*x */
b = imsl_c_mat_mul_rect_coordinate ("A*x",
IMSL_A_MATRIX, n, n, nz, a,
IMSL_X_VECTOR, n, x,
0);
imsl_c_write_matrix ("Ax", 1, n, b,
0);
imsl_free(b);
 
/* Set b = trans(A)*x */
b = imsl_c_mat_mul_rect_coordinate ("trans(A)*x",
IMSL_A_MATRIX, n, n, nz, a,
IMSL_X_VECTOR, n, x,
0);
imsl_c_write_matrix ("\n\ntrans(A)x", 1, n, b,
0);
imsl_free(b);
 
/* Set b = ctrans(A)*x */
b = imsl_c_mat_mul_rect_coordinate ("ctrans(A)*x",
IMSL_A_MATRIX, n, n, nz, a,
IMSL_X_VECTOR, n, x,
0);
imsl_c_write_matrix ("\n\nctrans(A)x", 1, n, b,
0);
imsl_free(b);
 
/* Set z = A*ctrans(A) */
z = imsl_c_mat_mul_rect_coordinate ("A*ctrans(A)",
IMSL_A_MATRIX, n, n, nz, a,
IMSL_X_VECTOR, n, x,
IMSL_RETURN_MATRIX_SIZE, &nz_z,
0);
 
printf("\n\n\t\t\t z = A*ctrans(A)\n\n");
 
for (i=0; i<nz_z; i++)
printf ("\t\t\tz(%1d,%1d) = (%6.1f, %6.1f)\n",
z[i].row, z[i].col, z[i].val.re, z[i].val.im);
}
Output
 
Ax
1 2 3
( 3, 17) ( -19, 5) ( 6, 18)
 
4 5 6
( -38, 32) ( -63, 49) ( -57, 83)
 
 
 
trans(A)x
1 2 3
( -112, 54) ( -58, 46) ( 0, 12)
 
4 5 6
( -51, 5) ( 34, 78) ( -94, 60)
 
 
 
ctrans(A)x
1 2 3
( 54, -112) ( 46, -58) ( 12, 0)
 
4 5 6
( 5, -51) ( 78, 34) ( 60, -94)
 
z = A*ctrans(A)
 
z(0,0) = ( 149.0, 0.0)
z(0,3) = ( -48.0, 26.0)
z(0,4) = ( -22.0, -75.0)
z(0,5) = ( 74.0, -127.0)
z(1,1) = ( 27.0, 0.0)
z(1,2) = ( -12.0, 6.0)
z(1,3) = ( 11.0, 8.0)
z(1,4) = ( 5.0, -10.0)
z(1,5) = ( 10.0, -28.0)
z(2,1) = ( -12.0, -6.0)
z(2,2) = ( 20.0, 0.0)
z(3,0) = ( -48.0, -26.0)
z(3,1) = ( 11.0, -8.0)
z(3,3) = ( 67.0, 0.0)
z(3,4) = ( -17.0, 36.0)
z(3,5) = ( -46.0, 28.0)
z(4,0) = ( -22.0, 75.0)
z(4,1) = ( 5.0, 10.0)
z(4,3) = ( -17.0, -36.0)
z(4,4) = ( 312.0, 0.0)
z(4,5) = ( 81.0, 126.0)
z(5,0) = ( 74.0, 127.0)
z(5,1) = ( 10.0, 28.0)
z(5,3) = ( -46.0, -28.0)
z(5,4) = ( 81.0, -126.0)
z(5,5) = ( 271.0, 0.0)