Chapter 12: Utilities

mat_mul_rect (complex)

Computes the transpose of a matrix, the conjugate-transpose of a matrix, a matrix-vector product, a matrix-matrix product, the bilinear form, or any triple product.

Synopsis

#include <imsl.h>

f_complex *imsl_c_mat_mul_rect (char *string, ¼, 0)

The type d_complex function is imsl_z_mat_mul_rect.

Required Arguments

char *string   (Input)
String indicating matrix multiplication to be performed.

Return Value

The result of the multiplication. This is always a pointer to a f_complex, even if the result is a single number. To release this space, use free. If no answer was computed, then NULL is returned.

Synopsis with Optional Arguments

#include <imsl.h>

f_complex *imsl_c_mat_mul_rect (char *string,
IMSL_A_MATRIX, int nrowa, int ncola, f_complex *a,
IMSL_A_COL_DIM, int a_col_dim,
IMSL_B_MATRIX, int nrowb, int ncolb, f_complex *b,
IMSL_B_COL_DIM, int b_col_dim,
IMSL_X_VECTOR, int nx, f_complex *x,
IMSL_Y_VECTOR, int ny, f_complex *y,
IMSL_RETURN_USER, f_complex ans[],
IMSL_RETURN_COL_DIM, int return_col_dim,
0)

Optional Arguments

IMSL_A_MATRIX, int nrowa, int ncola, f_complex *a   (Input)
The nrowa ´ ncola matrix A.

IMSL_A_COL_DIM, int a_col_dim   (Input)
The column dimension of A.
Default: a_col_dim = ncola

IMSL_B_MATRIX, int nrowb, int ncolb, f_complex *b   (Input)
The nrowb ´ ncolb matrix B.

IMSL_B_COL_DIM, int b_col_dim   (Input)
The column dimension of B.
Default: b_col_dim = ncolb

IMSL_X_VECTOR, int nx, f_complex *x   (Input)
The vector x of size nx.

IMSL_Y_VECTOR, int ny, f_complex *y   (Input)
The vector y of size ny.

IMSL_RETURN_USER, f_complex ans[]   (Output)
A user-allocated array containing the result.

IMSL_RETURN_COL_DIM, int return_col_dim   (Input)
The column dimension of the answer.
Default: return_col_dim = the number of columns in the answer

Description

This function computes a matrix-vector product, a matrix-matrix product, a bilinear form of a matrix, or a triple product according to the specification given by string. For example, if “A*x” is given, Ax is computed. In string, the matrices A and B and the vectors x and y can be used. Any of these four names can be used with trans, indicating transpose, or with ctrans, indicating conjugate (or Hermitian) transpose. The vectors x and y are treated as n ´ 1 matrices.

If string contains only one item, such as “x” or  “trans(A)”, then a copy of the array, or its transpose, is returned. If string contains one multiplication, such as “A*x” or “B*A”, then the indicated product is returned. Some other legal values for  string are  “trans(y)*A”, “A*ctrans(B)”, “x*trans(y)”, or  “ctrans(x)*y”.

The matrices and/or vectors referred to in string must be given as optional arguments. If string is “B*x”, then IMSL_B_MATRIX and IMSL_X_VECTOR must be given.

Example

Let

The arrays AH, Ax, xTAT, AB, BHAT, xTy, and xyH are computed and printed.

#include <imsl.h>

main()
{
    f_complex   A[] = {{1,4}, {2, 3}, {9,6},
                       {5,2}, {4,-3}, {7,1}};

    f_complex   B[] = {{3,-6}, {2, 4},
                       {7, 3}, {4,-5},
                       {9, 2}, {1, 3}};

    f_complex   x[] = {{7,4}, {2, 2}, {1,-5}};
    f_complex   y[] = {{3,4}, {4,-2}, {2, 3}};
    f_complex   *ans;

    ans = imsl_c_mat_mul_rect("ctrans(A)",
                              IMSL_A_MATRIX, 2, 3, A,
                              0);
    imsl_c_write_matrix("ctrans(A)", 3, 2, ans, 0);

    ans = imsl_c_mat_mul_rect("A*x",
                              IMSL_A_MATRIX, 2, 3, A,
                              IMSL_X_VECTOR, 3, x,
                              0);
    imsl_c_write_matrix("A*x", 1, 2, ans, 0);

    ans = imsl_c_mat_mul_rect("trans(x)*trans(A)",
                              IMSL_A_MATRIX, 2, 3, A,
                              IMSL_X_VECTOR, 3, x,
                              0);
    imsl_c_write_matrix("trans(x)*trans(A)", 1, 2, ans, 0);

    ans = imsl_c_mat_mul_rect("A*B",
                              IMSL_A_MATRIX, 2, 3, A,
                              IMSL_B_MATRIX, 3, 2, B,
                              0);
    imsl_c_write_matrix("A*B", 2, 2, ans, 0);

    ans = imsl_c_mat_mul_rect("ctrans(B)*trans(A)",
                              IMSL_A_MATRIX, 2, 3, A,
                              IMSL_B_MATRIX, 3, 2, B,
                              0);
    imsl_c_write_matrix("ctrans(B)*trans(A)", 2, 2, ans, 0);

    ans = imsl_c_mat_mul_rect("trans(x)*y",
                              IMSL_X_VECTOR, 3, x,
                              IMSL_Y_VECTOR, 3, y,
                              0);
    imsl_c_write_matrix("trans(x)*y", 1, 1, ans, 0);

    ans = imsl_c_mat_mul_rect("x*ctrans(y)",
                              IMSL_X_VECTOR, 3, x,
                              IMSL_Y_VECTOR, 3, y,
                              0);
    imsl_c_write_matrix("x*ctrans(y)", 3, 3, ans, 0);
}

Output

                     ctrans(A)
                         1                        2
1  (         1,        -4)  (         5,        -2)
2  (         2,        -3)  (         4,         3)
3  (         9,        -6)  (         7,        -1)
 
                       A*x
                      1                        2
(        28,         3)  (        53,         2)
 
                trans(x)*trans(A)
                      1                        2
(        28,         3)  (        53,         2)
 
                        A*B
                         1                        2
1  (       101,       105)  (         0,        47)
2  (       125,       -10)  (         7,        14)
 
                ctrans(B)*trans(A)
                         1                        2
1  (        95,        69)  (        87,        -2)
2  (        38,         5)  (        59,       -28)
 
      trans(x)*y
(        34,        37)

                                 x*ctrans(y)
                        1                        2                        3
1 (        37,       -16)  (        20,        30)  (        26,       -13)
2 (        14,        -2)  (         4,        12)  (        10,        -2)
3 (       -17,       -19)  (        14,       -18)  (       -13,       -13)


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260