matMulRectCoordinateComplex¶
Computes the transpose of a matrix, a matrix-vector product, or a matrix-matrix product for all matrices stored in sparse coordinate form.
Synopsis¶
matMulRectCoordinateComplex (string)
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 complex. If the result of the multiplication is a sparse matrix, the return type is sparse_elem.
Optional Arguments¶
aMatrix
, int nrowa
, int ncola
, int nza
, sparse_elem a
(Input)
The sparse matrix
with nza
nonzero elements.
bMatrix
, intnrowb
, intncolb
, intnzb
, sparse_elemb
(Input)The sparse matrix
\[B \in \mathbb{C}^{\mathrm{nrowb} \times \mathrm{ncolb}}\]with
nzb
nonzero elements.xVector
, complexx
, (Input)- The vector x of length
nx
. returnMatrixSize
(Output)- If the function
matMulRectCoordinateComplex
returns a vector of type 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. sparseOutput
(Output)- If the result of the computation is a vector, return the answer in the
user supplied space
sparseOutput
. It’s size depends on the computation.
Description¶
The function matMulRectCoordinateComplex
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 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
”, aMatrix
and
xVector
must be given.
Examples¶
Example 1¶
Let
and
This example computes the product Ax.
from numpy import *
from pyimsl.math.matMulRectCoordinateComplex import matMulRectCoordinateComplex
from pyimsl.math.writeMatrixComplex import writeMatrixComplex
a = [[0, 0, (10.0 + 7.0j)],
[1, 1, (3.0 + 2.0j)],
[1, 2, (-3.0 + 0.0j)],
[1, 3, (-1.0 + 2.0j)],
[2, 2, (4.0 + 2.0j)],
[3, 0, (-2.0 + -4.0j)],
[3, 3, (1.0 + 6.0j)],
[3, 4, (-1.0 + 3.0j)],
[4, 0, (-5.0 + 4.0j)],
[4, 3, (-5.0 + 0.0j)],
[4, 4, (12.0 + 2.0j)],
[4, 5, (-7.0 + 7.0j)],
[5, 0, (-1.0 + 12.0j)],
[5, 1, (-2.0 + 8.0j)],
[5, 5, (3.0 + 7.0j)]]
n = 6
b = array([1.0 + 1.0j, 2.0 + 2.0j, 3.0 + 3.0j,
4.0 + 4.0j, 5.0 + 5.0j, 6.0 + 6.0j])
# Set x = A*b
x = matMulRectCoordinateComplex("A*x",
aMatrix={'nrowa': n, 'ncola': n, 'a': a},
xVector=b)
writeMatrixComplex("Product Ab", x)
Output¶
Product Ab
1 2
( 3, 17) ( -19, 5)
3 4
( 6, 18) ( -38, 32)
5 6
( -63, 49) ( -57, 83)
Example 2¶
Using the same matrix A and vector x given in the last example, the products Ax, \(A^Tx\), \(A^Hx\) and \(AA^H\) are computed.
from __future__ import print_function
from numpy import *
from pyimsl.math.matMulRectCoordinateComplex import matMulRectCoordinateComplex
from pyimsl.math.writeMatrixComplex import writeMatrixComplex
a = [[0, 0, (10.0 + 7.0j)],
[1, 1, (3.0 + 2.0j)],
[1, 2, (-3.0 + 0.0j)],
[1, 3, (-1.0 + 2.0j)],
[2, 2, (4.0 + 2.0j)],
[3, 0, (-2.0 + -4.0j)],
[3, 3, (1.0 + 6.0j)],
[3, 4, (-1.0 + 3.0j)],
[4, 0, (-5.0 + 4.0j)],
[4, 3, (-5.0 + 0.0j)],
[4, 4, (12.0 + 2.0j)],
[4, 5, (-7.0 + 7.0j)],
[5, 0, (-1.0 + 12.0j)],
[5, 1, (-2.0 + 8.0j)],
[5, 5, (3.0 + 7.0j)]]
n = 6
x = array([1.0 + 1.0j, 2.0 + 2.0j, 3.0 + 3.0j,
4.0 + 4.0j, 5.0 + 5.0j, 6.0 + 6.0j])
# Set x = A*b
b = matMulRectCoordinateComplex("A*x",
aMatrix={'nrowa': n, 'ncola': n, 'a': a},
xVector=x)
writeMatrixComplex("Product Ax", b)
# Set b = trans(A)*x
b = matMulRectCoordinateComplex("trans(A)*x",
aMatrix={'nrowa': n, 'ncola': n, 'a': a},
xVector=x)
writeMatrixComplex("\n\ntrans(A)x", b)
# Set b = ctrans(A)*x
b = matMulRectCoordinateComplex("ctrans(A)*x",
aMatrix={'nrowa': n, 'ncola': n, 'a': a},
xVector=x)
writeMatrixComplex("\n\nctrans(A)x", b)
# Set z = A*ctrans(A)
nz_z = []
z = matMulRectCoordinateComplex("A*ctrans(A)",
aMatrix={'nrowa': n, 'ncola': n, 'a': a},
xVector=x,
sparseOutput=True,
returnMatrixSize=nz_z)
print("\n\t\t\t z = A*ctrans(A)\n")
for i in range(0, nz_z[0]):
print("\t\t\tz(%1d,%1d) = (%6.1f, %6.1f)" %
(z[i][0], z[i][1], z[i][2].real, z[i][2].imag))
Output¶
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)
Product Ax
1 2
( 3, 17) ( -19, 5)
3 4
( 6, 18) ( -38, 32)
5 6
( -63, 49) ( -57, 83)
trans(A)x
1 2
( -112, 54) ( -58, 46)
3 4
( 0, 12) ( -51, 5)
5 6
( 34, 78) ( -94, 60)
ctrans(A)x
1 2
( 54, -112) ( 46, -58)
3 4
( 12, 0) ( 5, -51)
5 6
( 78, 34) ( 60, -94)