generateTestCoordinate

Generates test matrices of class D(n, c) and E(n, c). Returns in either coordinate format.

Synopsis

generateTestCoordinate (n, c)

Required Arguments

int n (Input)
Number of rows in the matrix.
int c (Input)
Parameter used to alter structure.

Return Value

A vector of length nz of type sparse_elem. If no test was generated, then None is returned.

Optional Arguments

matrix

Return a matrix of class D(n, c).

Default: Return a matrix of class E(n, c).

symmetricStorage,
For coordinate representation, return only values for the diagonal and lower triangle. This option is not allowed if matrix is specified.

Description

We use the same nomenclature as Østerby and Zlatev (1982).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 < nc
\(a_{i+c,i}=-1\) 0 ≤ i < nc

for any n ≥ 3 and 2 ≤ cn − 1.

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

Test matrices of class D(n, c) are square matrices of order n with a full diagonal, three bands at a distance c above the diagonal and reappearing cyclically under the diagonal, and a 10 ×10 triangle of elements in the upper right corner. More precisely:

\(a_{i,i}=1\) 0 ≤ i < n
\(a_{i,i+c}=i+2\) 0 ≤ i < nc
\(a_{i,i-n+c}=i+2\) nci < n
\(a_{i,i+c+1}=-(i+1)\) 0 ≤ i < nc − 1
\(a_{i,i-n+c+1}=-(i+1)\) nc −1 ≤ i < n
\(a_{i,i+c+2}=16\) 0 ≤ i < nc − 2
\(a_{i,i-n+c+2}=16\) nc − 2 ≤ i < n
\(a_{i,n-11+i+j}=100j\) \(1\leq i<11-j,0\leq j<10\)

for any n ≥14 and 1 ≤ cn -13.

We now show the sparsity pattern of D(20, 5)

\[\begin{split}\begin{matrix} & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times & \times & \times & \times & \times & \times & \times & \times \\ & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times & \times & \times & \times & \times & \times & \times \\ & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times & \times & \times & \times & \times & \times \\ & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times & \times & \times & \times & \times \\ & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times & \times & \times & \times \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times & \times & \times \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times & \times \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times & \times \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times & \times \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \times \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot \\ & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times & \times \\ & \times & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times & \times \\ & \times & \times & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot & \times \\ & \times & \times & \times & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot & \cdot \\ & \cdot & \times & \times & \times & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot & \cdot \\ & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot & \cdot \\ & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times & \cdot \\ & \cdot & \cdot & \cdot & \cdot & \times & \times & \times & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \times \\ \end{matrix}\end{split}\]

By default generateTestCoordinate returns an E-matrix in coordinate representation. By specifying the symmetricStorage option, only the diagonal and lower triangle are returned. The scalar nz will contain the number of nonzeros in this representation.

The option matrix will return a matrix of class D(n, c). Since D-matrices are not symmetric, the symmetricStorage option is not allowed.

Examples

Example 1

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 __future__ import print_function
from pyimsl.math.generateTestCoordinate import generateTestCoordinate

a = generateTestCoordinate(5, 3)

print("   row   col  val")
for i in range(0, len(a)):
    print("%5d %5d %5.1f" % (a[i][0], a[i][1], a[i][2]))

Output

   row   col  val
    0     0   4.0
    1     1   4.0
    2     2   4.0
    3     3   4.0
    4     4   4.0
    1     0  -1.0
    2     1  -1.0
    3     2  -1.0
    4     3  -1.0
    0     1  -1.0
    1     2  -1.0
    2     3  -1.0
    3     4  -1.0
    3     0  -1.0
    4     1  -1.0
    0     3  -1.0
    1     4  -1.0

Example 2

In this example, the matrix E(5, 3) is returned in symmetric storage and printed.

from __future__ import print_function
from pyimsl.math.generateTestCoordinate import generateTestCoordinate

a = generateTestCoordinate(5, 3, symmetricStorage=True)

print("   row   col  val")
for i in range(0, len(a)):
    print("%5d %5d %5.1f" % (a[i][0], a[i][1], a[i][2]))

Output

   row   col  val
    0     0   4.0
    1     1   4.0
    2     2   4.0
    3     3   4.0
    4     4   4.0
    1     0  -1.0
    2     1  -1.0
    3     2  -1.0
    4     3  -1.0
    3     0  -1.0
    4     1  -1.0