generateTestCoordinateComplex¶
Generates test matrices of class D(n, c) and E(n, c). Returns in either coordinate or band storage format, where possible.
Synopsis¶
generateTestCoordinateComplex (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
. 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¶
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 (6.0, 0.0) in
the diagonal, (‑1.0, 1.0) in the superdiagonal and (‑1.0, ‑1.0) subdiagonal.
In addition there are two bands at a distance c
from the diagonal with
(‑1.0, 1.0) in the upper codiagonal and (‑1.0, ‑1.0) in the lower codiagonal.
More precisely:
\(a_{i,i}=6\) | \(0\leq i<n\) |
\(a_{i,i+1}=-1-i\) | \(0\leq i<n-1\) |
\(a_{i+1,}i=-1-i\) | \(0\leq i<n-1\) |
\(a_{i,i+c}=-1+i\) | \(0\leq i<n-c\) |
\(a_{i+c,i}=-1+i\) | \(0\leq i<n-c\) |
for any \(n\geq 3\) and \(2\leq c\leq n-1\).
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\leq i<n\) |
\(a_{i,i+c}=i+2\) | \(0\leq i<n-c\) |
\(a_{i,i-n+c}=i+2\) | \(n-c\leq i<n\) |
\(a_{i,i+c+1}=-(i+1)\) | \(0\leq i<n-c-1\) |
\(a_{i,i+c+1}=-(i+1)\) | \(n-c-1\leq i<n\) |
\(a_{i,i+c+2}=16\) | \(0\leq i<n-c-2\) |
\(a_{i,i-n+c+2}=16\) | \(n-c-2\leq i<n\) |
\(a_{i,n-11+i+j}=100j\) | \(1\leq i<11-j\), \(0\leq j<10\) |
for any \(n\geq 14\) and \(1\leq c\leq n-13\).
The sparsity pattern of \(D(20,5)\) is as follows:
By default generateTestCoordinateComplex
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 non-zeros 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
and prints the result.
from __future__ import print_function
from pyimsl.math.generateTestCoordinateComplex import generateTestCoordinateComplex
a = generateTestCoordinateComplex(5, 3)
print(" row col val")
for i in range(0, len(a)):
print("%5d %5d (%5.1f, %5.1f)" %
(a[i][0], a[i][1], a[i][2].real, a[i][2].imag))
Output¶
row col val
0 0 ( 6.0, 0.0)
1 1 ( 6.0, 0.0)
2 2 ( 6.0, 0.0)
3 3 ( 6.0, 0.0)
4 4 ( 6.0, 0.0)
1 0 ( -1.0, -1.0)
2 1 ( -1.0, -1.0)
3 2 ( -1.0, -1.0)
4 3 ( -1.0, -1.0)
0 1 ( -1.0, 1.0)
1 2 ( -1.0, 1.0)
2 3 ( -1.0, 1.0)
3 4 ( -1.0, 1.0)
3 0 ( -1.0, -1.0)
4 1 ( -1.0, -1.0)
0 3 ( -1.0, 1.0)
1 4 ( -1.0, 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.generateTestCoordinateComplex import generateTestCoordinateComplex
a = generateTestCoordinateComplex(5, 3, symmetricStorage=True)
print(" row col val")
for i in range(0, len(a)):
print("%5d %5d (%5.1f, %5.1f)" %
(a[i][0], a[i][1], a[i][2].real, a[i][2].imag))
Output¶
row col val
0 0 ( 6.0, 0.0)
1 1 ( 6.0, 0.0)
2 2 ( 6.0, 0.0)
3 3 ( 6.0, 0.0)
4 4 ( 6.0, 0.0)
1 0 ( -1.0, -1.0)
2 1 ( -1.0, -1.0)
3 2 ( -1.0, -1.0)
4 3 ( -1.0, -1.0)
3 0 ( -1.0, -1.0)
4 1 ( -1.0, -1.0)