CNLMath : Utilities : mat_mul_rect_band (complex)
mat_mul_rect_band (complex)
Computes the transpose of a matrix, a matrix-vector product, or a matrix-matrix product for all matrices of complex type and stored in band form.
Synopsis
#include <imsl.h>
f_complex *imsl_c_mat_mul_rect_band (char *string, ..., 0)
The equivalent d_complex function is imsl_z_mat_mul_rect_band.
Required Arguments
char *string (Input)
String indicating matrix multiplication to be performed.
Return Value
The result of the multiplication is returned. To release this space, use imsl_free.
Synopsis with Optional Arguments
#include <imsl.h>
void *imsl_c_mat_mul_rect_band (char *string,
IMSL_A_MATRIX, int nrowa, int ncola, int nlca, int nuca, f_complex *a,
IMSL_B_MATRIX, int nrowb, int ncolb, int nlcb, int nucb, f_complex *b,
IMSL_X_VECTOR, int nx, f_complex *x,
IMSL_RETURN_MATRIX_CODIAGONALS, int *nlc_result, int *nuc_result,
IMSL_RETURN_USER_VECTOR, f_complex vector_user[],
0)
Optional Arguments
IMSL_A_MATRIX, int nrowa, int ncola, int nlca, int nuca, f_complex *a (Input)
The sparse matrix
IMSL_B_MATRIX, int nrowb, int ncolb, int nlcb, int nucb, f_complex *b (Input)
The sparse matrix
IMSL_X_VECTOR, int nx, f_complex *x, (Input)
The vector x of length nx.
IMSL_RETURN_MATRIX_CODIAGONALS, int *nlc_result, int *nuc_result, (Output)
If the function imsl_c_mat_mul_rect_band returns data for a band matrix, use this option to retrieve the number of lower and upper codiagonals of the return matrix.
IMSL_RETURN_USER_VECTOR, f_complex vector_user[], (Output)
If the result of the computation in a vector, return the answer in the user supplied sparse vector_user.
Description
The function imsl_c_mat_mul_rect_band computes a matrix-matrix product or a matrix‑vector product, where the matrices are specified in band format. 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, indicating transpose. 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.
The matrices and/or vector referred to in string must be given as optional arguments. Therefore, if string is “A*x”, then IMSL_A_MATRIX and IMSL_X_VECTOR must be given.
Examples
Example 1
Let
and
This example computes the product Ax.
 
#include <imsl.h>
 
int main()
{
int n = 4;
int nlca = 1;
int nuca = 1;
f_complex *b;
f_complex *z;
int nlca_z;
int nuca_z;
 
/* Note that a is in band storage mode */
f_complex a[] =
{{0.0, 0.0}, {4.0, 0.0}, {-2.0, 2.0}, {-4.0, -1.0},
{-2.0, -3.0}, {-0.5, 3.0}, {3.0, -3.0}, {1.0, -1.0},
{6.0, 1.0}, {1.0, 1.0}, {0.0, 2.0}, {0.0, 0.0}};
f_complex x[] =
{{3.0, 0.0}, {-1.0, 1.0}, {3.0, 0.0}, {-1.0, 1.0}};
 
/* Set b = A*x */
b = imsl_c_mat_mul_rect_band ("A*x",
IMSL_A_MATRIX, n, n, nlca, nuca, a,
IMSL_X_VECTOR, n, x,
0);
imsl_c_write_matrix ("Ax", 1, n, b,
0);
}
Output
 
Product, Ax
1 2 3
( -10.0, -5.0) ( 9.5, 5.5) ( 12.0, -12.0)
 
4
( 0.0, 8.0)
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>
 
int main()
{
int n = 4;
int nlca = 1;
int nuca = 1;
f_complex *b;
f_complex *z;
int nlca_z;
int nuca_z;
 
/* Note that a is in band storage mode */
f_complex a[] =
{{0.0, 0.0}, {4.0, 0.0}, {-2.0, 2.0}, {-4.0, -1.0},
{-2.0, -3.0}, {-0.5, 3.0}, {3.0, -3.0}, {1.0, -1.0},
{6.0, 1.0}, {1.0, 1.0}, {0.0, 2.0}, {0.0, 0.0}};
f_complex x[] =
{{3.0, 0.0}, {-1.0, 1.0}, {3.0, 0.0}, {-1.0, 1.0}};
 
/* Set b = A*x */
b = imsl_c_mat_mul_rect_band ("A*x",
IMSL_A_MATRIX, n, n, nlca, nuca, 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_band ("trans(A)*x",
IMSL_A_MATRIX, n, n, nlca, nuca, 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_band ("ctrans(A)*x",
IMSL_A_MATRIX, n, n, nlca, nuca, 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_band ("A*ctrans(A)",
IMSL_A_MATRIX, n, n, nlca, nuca, a,
IMSL_X_VECTOR, n, x,
IMSL_RETURN_MATRIX_CODIAGONALS, &nlca_z, &nuca_z,
0);
imsl_c_write_matrix("A*ctrans(A)", nlca_z+nuca_z+1, n, z,
0);
}
Output
 
Ax
1 2 3
( -10.0, -5.0) ( 9.5, 5.5) ( 12.0, -12.0)
 
4
( 0.0, 8.0)
 
 
trans(A)x
1 2 3
( -13.0, -4.0) ( 12.5, -0.5) ( 7.0, -15.0)
 
4
( -12.0, -1.0)
 
 
ctrans(A)x
1 2 3
( -11.0, 16.0) ( 18.5, -0.5) ( 15.0, 11.0)
 
4
( -14.0, 3.0)
 
A*ctrans(A)
1 2 3
1 ( 0.00, 0.00) ( 0.00, 0.00) ( 4.00, -4.00)
2 ( 0.00, 0.00) ( -17.00, -28.00) ( -9.50, 3.50)
3 ( 29.00, 0.00) ( 54.25, 0.00) ( 37.00, 0.00)
4 ( -17.00, 28.00) ( -9.50, -3.50) ( -9.00, 11.00)
5 ( 4.00, 4.00) ( 4.00, -4.00) ( 0.00, 0.00)
 
4
1 ( 4.00, 4.00)
2 ( -9.00, -11.00)
3 ( 6.00, 0.00)
4 ( 0.00, 0.00)
5 ( 0.00, 0.00)