matAddBand

Adds two band matrices, both in band storage mode, \(C\leftarrow\alpha A+\beta B\).

Synopsis

matAddBand (nlca, nuca, alpha, a, nlcb, nucb, beta, b, nlcc, nucc)

Required Arguments

int nlca (Input)
Number of lower codiagonals of A.
int nuca (Input)
Number of upper codiagonals of A.
float alpha (Input)
Scalar multiplier for A.
float a[[]] (Input)
An n by n band matrix with nlca lower codiagonals and nuca upper codiagonals stored in band mode with dimension (nlca + nuca + 1) by n.
int nlcb (Input)
Number of lower codiagonals of B.
int nucb (Input)
Number of upper codiagonals of B.
float beta (Input)
Scalar multiplier for B.
float b[[]] (Input)
An n by n band matrix with nlcb lower codiagonals and nucb upper codiagonals stored in band mode with dimension (nlcb + nucb + 1) by n.
int nlcc (Output)
Number of lower codiagonals of C.
int nucc (Output)
Number of upper codiagonals of C.

Return Value

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

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\).
symmetric,
A, B and C are stored in band symmetric storage mode.

Description

The function matAddBand forms the sum \(\alpha A+\beta B\), given the scalars αand β, and, the matrices A and B in band format. The transpose of A and/or B may be used during the computation if optional arguments are specified. Symmetric storage mode may be used if the optional argument is specified.

If symmetric is specified, the return value for the number of lower codiagonals, nlcc, will be equal to 0.

If the return matrix equals None, the return value for the number of lower codiagonals, nlcc, will be equal to -1 and the number of upper codiagonals, nucc, will be equal to 0.

Examples

Example 1

Add two real matrices of order 4 stored in band mode. Matrix A has one upper codiagonal and one lower codiagonal. Matrix B has no upper codiagonals and two lower codiagonals.

from pyimsl.math.matAddBand import matAddBand
from pyimsl.math.writeMatrix import writeMatrix

a = [[0., 2., 3., -1.], [1., 1., 1., 1.], [0., 3., 4., 0.]]
b = [[3., 3., 3., 3.], [1., -2., 1., 0.], [-1., 2., 0., 0.]]
nucb = 0
nlcb = 2
nuca = 1
nlca = 1
n = 4
alpha = 1.0
beta = 1.0
nlcc = []
nucc = []

c = matAddBand(nlca, nuca, alpha, a, nlcb, nucb, beta, b, nlcc=nlcc, nucc=nucc)

writeMatrix("C = A + B", c)

Output

 
                      C = A + B
             1            2            3            4
1            0            2            3           -1
2            4            4            4            4
3            1            1            5            0
4           -1            2            0            0

Example 2

Compute 4 * A + 2 * B, where

\[\begin{split}A = \begin{bmatrix} 3 & 4 & 0 & 0 \\ 4 & 2 & 3 & 0 \\ 0 & 3 & 1 & 1 \\ 0 & 0 & 1 & 2 \\ \end{bmatrix} \text{ and } B = \begin{bmatrix} 5 & 2 & 0 & 0 \\ 2 & 1 & 3 & 0 \\ 0 & 3 & 2 & 1 \\ 0 & 0 & 1 & 2 \\ \end{bmatrix}\end{split}\]
from pyimsl.math.matAddBand import matAddBand
from pyimsl.math.writeMatrix import writeMatrix

a = [[0., 4., 3., 1.], [3., 2., 1., 2.]]
b = [[0., 2., 3., 1.], [5., 1., 2., 2.]]
nucb = 1
nlcb = 1
nuca = 1
nlca = 1
n = 4
alpha = 4.0
beta = 2.0
nlcc = []
nucc = []

c = matAddBand(nlca, nuca, alpha, a, nlcb, nucb, beta,
               b, nlcc=nlcc, nucc=nucc, symmetric=True)

writeMatrix("C = 4*A + 2*B", c)

Output

 
                    C = 4*A + 2*B
             1            2            3            4
1            0           20           18            6
2           22           10            8           12