matAddCoordinateComplex

Performs element-wise addition on two complex matrices stored in coordinate format, \(C\leftarrow\alpha A+\beta B\).

Synopsis

matAddCoordinateComplex (n, alpha, a, beta, b, nzC)

Required Arguments

int n (Input)
The order of the matrices A and B.
complex alpha (Input)
Scalar multiplier for A.
sparse_elem a[] (Input)
Vector of length nz_a containing the location and value of each nonzero entry in the matrix A.
complex beta (Input)
Scalar multiplier for B.
sparse_elem b[] (Input)
Vector of length nz_b containing the location and value of each nonzero entry in the matrix B.
Int nzC (Output)
The number of nonzeros in the sum \(\alpha A+\beta B\).

Return Value

An array of type sparse_elem containing the computed sum. In the event of an error or if the return matrix has no nonzero elements, None is returned.

Optional Arguments

aTranspose
Replace A with \(A^T\) in the expression \(\alpha A+\beta B\).
bTranspose
Replace B with \(B^T\) in the expression \(\alpha A+\beta B\).
aConjugateTranspose
Replace A with \(A^H\) in the expression \(\alpha A+\beta B\).
bConjugateTranspose
Replace B with \(B^H\) in the expression \(\alpha A+\beta B\).

Description

The function matAddCoordinateComplex forms the sum \(\alpha A+\beta B\), given the scalars αand β 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 α. 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 β 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.

Examples

Example 1

Add two complex matrices of order 4 stored in coordinate format. Matrix A has five nonzero elements. Matrix B has seven nonzero elements.

from __future__ import print_function
from pyimsl.math.matAddCoordinateComplex import matAddCoordinateComplex

a = [[0, 0, (3 + 4j)],
     [0, 3, (-1 + 2j)],
     [1, 2, (5 + -1j)],
     [2, 0, (1 + 2j)],
     [3, 1, (3 + 0j)]]
b = [[0, 1, (-2 + 1j)],
     [0, 3, (1 + -2j)],
     [1, 0, (3 + 0j)],
     [2, 2, (5 + 2j)],
     [2, 3, (1 + 4j)],
     [3, 0, (4 + 0j)],
     [3, 1, (3 + -2j)]]
nz_a = 5
nz_b = 7
nz_c = []
n = 4
alpha = 1 + 0j
beta = 1 + 0j

c = matAddCoordinateComplex(n, alpha, a, beta, b, nzC=nz_c)

print(" row  column    value")
for i in range(0, nz_c[0]):
    print("%3d %5d %8.2f %8.2f" %
          (c[i][0], c[i][1], (c[i][2]).real, (c[i][2]).imag))

Output

 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

Example 2

Compute \(2+3i*A^T+2-i*B^T\), where

\[\begin{split}A = \begin{bmatrix} 3+4i & 0 & 0 & -1+2i \\ 0 & 0 & 5-i & 0 \\ 1+2i & 0 & 0 & 0 \\ 0 & 3+0i & 0 & 0 \\ \end{bmatrix} \text{ and } B = \begin{bmatrix} 0 & -2+i & 0 & 1-2i \\ 3+0i & 0 & 0 & 0 \\ 0 & 0 & 5+2i & 1+4i \\ 4+0i & 3-2i & 0 & 0 \\ \end{bmatrix}\end{split}\]
from __future__ import print_function
from pyimsl.math.matAddCoordinateComplex import matAddCoordinateComplex

a = [[0, 0, (3 + 4j)],
     [0, 3, (-1 + 2j)],
     [1, 2, (5 + -1j)],
     [2, 0, (1 + 2j)],
     [3, 1, (3 + 0j)]]
b = [[0, 1, (-2 + 1j)],
     [0, 3, (1 + -2j)],
     [1, 0, (3 + 0j)],
     [2, 2, (5 + 2j)],
     [2, 3, (1 + 4j)],
     [3, 0, (4 + 0j)],
     [3, 1, (3 + -2j)]]
nz_a = 5
nz_b = 7
nz_c = []
n = 4
alpha = 2 + 3j
beta = 2 - 1j

c = matAddCoordinateComplex(n, alpha, a, beta, b, nzC=nz_c,
                            aTranspose=True, bTranspose=True)

print(" row  column    value")
for i in range(0, nz_c[0]):
    print("%3d %5d %8.2f %8.2f" %
          (c[i][0], c[i][1], (c[i][2]).real, (c[i][2]).imag))

Output

 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