generateTestBand

Generates test matrices of class and E(n, c). Returns in band or band symmetric format.

Synopsis

generateTestBand (n, c)

Required Arguments

int n (Input)
Number of rows in the matrix.
int c (Input)
Parameter used to alter structure, also the number of upper/lower codiagonals.

Return Value

A vector of type float. If no test was generated, then None is returned.

Optional Arguments

symmetricStorage,
Return matrix stored in band symmetric format.

Description

The same nomenclature as Østerby and Zlatev (1982) is used. Test matrices of class E(n, c), to which we will generally refer to as E-matrices, are symmetric, positive definite matrices of order n with 4 in the diagonal and -1 in the superdiagonal and subdiagonal. In addition there are two bands with -1 at a distance c from the diagonal. More precisely:

\(a_{i,i}=4\) 0 ≤ i < n
\(a_i,_{i+1}=-1\) 0 ≤ i < n -1
\(a_{i+1,}i=-1\) 0 ≤ i < n - 1
\(a_{i,i+c}=-1\) 0≤ i <n - c
\(a_{i+c,i}=-1\) 0 ≤ i < n - c

for any \(n\geq 3\) and \(2\leq c\leq n-1\).

E-matrices are similar to those obtained from the five-point formula in the discretization of elliptic partial differential equations.

By default, generateTestBand returns an E-matrix in band storage mode. Option symmetricStorage returns a matrix in band symmetric storage mode.

Example

This example generates the matrix

\[\begin{split}E(5,3) = \begin{bmatrix} 4 & -1 & 0 & -1 & 0 \\ -1 & 4 & -1 & 0 & -1 \\ 0 & -1 & 4 & -1 & 0 \\ -1 & 0 & -1 & 4 & -1 \\ 0 & -1 & 0 & -1 & 4 \\ \end{bmatrix}\end{split}\]

and prints the result.

from pyimsl.math.generateTestBand import generateTestBand
from pyimsl.math.writeMatrix import writeMatrix

a = generateTestBand(5, 3)

writeMatrix("E(5, 3) in band storage: ", a)

Output

 
                     E(5, 3) in band storage: 
             1            2            3            4            5
1            0            0            0           -1           -1
2            0            0            0            0            0
3            0           -1           -1           -1           -1
4            4            4            4            4            4
5           -1           -1           -1           -1            0
6            0            0            0            0            0
7           -1           -1            0            0            0