generate_test_coordinate (complex)
Generates test matrices of class D(n, c) and E(n, c). Returns in either coordinate or band storage format, where possible.
Synopsis
#include <imsl.h>
void *imsl_c_generate_test_coordinate (int n, int c, int *nz, ..., 0)
The function is imsl_z_generate_test_coordinate is the double precision analogue.
Required Arguments
int n (Input)
Number of rows in the matrix.
int c (Input)
Parameter used to alter structure.
int *nz (Output)
Length of the return vector.
Return Value
A pointer to a vector of length nz of type imsl_c_sparse_elem. To release this space, use imsl_free. If no test was generated, then NULL is returned.
Synopsis with Optional Arguments
#include <imsl.h>
void *imsl_c_generate_test_coordinate (int n, int c, int *nz,
IMSL_D_MATRIX,
IMSL_SYMMETRIC_STORAGE,
0)
Optional Arguments
IMSL_D_MATRIX
Return a matrix of class D(n, c).
Default: Return a matrix of class E(n, c).
IMSL_SYMMETRIC_STORAGE,
For coordinate representation, return only values for the diagonal and lower triangle. This option is not allowed if IMSL_D_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:
ai,i = 6 | 0 ≤ i < n |
ai,i+1 = ‑1 ‑ i | 0 ≤ i < n ‑1 |
ai+1,i = ‑1 ‑ i | 0 ≤ i < n ‑1 |
ai,i+c = ‑1 + i | 0 ≤ i < n ‑c |
ai+c,i = ‑1 + i | 0 ≤ i < n ‑c |
for any n ≥ 3 and 2 ≤ c ≤ 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:
ai,i = 1 | 0 ≤ i < n |
ai,i+c = i + 2 | 0 ≤ i < n - c |
ai,i-n+c = i + 2 | n ‑ c ≤ i < n |
ai,i+c+1 = ‑(i + 1) | 0 ≤ i < n ‑ c ‑ 1 |
ai,i+c+1 = ‑(i + 1) | n ‑ c ‑ 1≤ i < n |
ai,i+c+2 = 16 | 0 ≤ i < n ‑ c ‑ 2 |
ai,i-n+c+2 = 16 | n ‑ c ‑ 2≤ i < n |
ai,n-11+i+j = 100j | 1 ≤ i< 11 ‑ j, 0 ≤ j < 10 |
for any n ≥ 14 and 1 ≤ c ≤ n ‑ 13.
The sparsity pattern of D(20, 5) is as follows:
x | | | | | x | x | x | | | x | x | x | x | x | x | x | x | x | x |
| x | | | | | x | x | x | | | x | x | x | x | x | x | x | x | x |
| | x | | | | | x | x | x | | | x | x | x | x | x | x | x | x |
| | | x | | | | | x | x | x | | | x | x | x | x | x | x | x |
| | | | x | | | | | x | x | x | | | x | x | x | x | x | x |
| | | | | x | | | | | x | x | x | | | x | x | x | x | x |
| | | | | | x | | | | | x | x | x | | | x | x | x | x |
| | | | | | | x | | | | | x | x | x | | | x | x | x |
| | | | | | | | x | | | | | x | x | x | | | x | x |
| | | | | | | | | x | | | | | x | x | x | | | x |
| | | | | | | | | | x | | | | | x | x | x | | |
| | | | | | | | | | | x | | | | | x | x | x | |
| | | | | | | | | | | | x | | | | | x | x | x |
x | | | | | | | | | | | | | x | | | | | x | x |
x | x | | | | | | | | | | | | | x | | | | | x |
x | x | x | | | | | | | | | | | | | x | | | | |
| x | x | x | | | | | | | | | | | | | x | | | |
| | x | x | x | | | | | | | | | | | | | x | | |
| | | x | x | x | | | | | | | | | | | | | x | |
| | | | x | x | x | | | | | | | | | | | | | x |
By default imsl_c_generate_test_coordinate returns an E-matrix in coordinate representation. By specifying the IMSL_SYMMETRIC_STORAGE option, only the diagonal and lower triangle are returned. The scalar nz will contain the number of non-zeros in this representation.
The option IMSL_D_MATRIX will return a matrix of class D(n, c). Since D-matrices are not symmetric, the IMSL_SYMMETRIC_STORAGE option is not allowed.
Examples
Example 1
This example generates the matrix
and prints the result.
#include <imsl.h>
#include <stdio.h>
int main()
{
int i, n = 5, c = 3, nz;
Imsl_c_sparse_elem *a;
a = imsl_c_generate_test_coordinate (n, c, &nz,
0);
printf ("row col val\n");
for (i=0; i<nz; i++)
printf (" %d %d (%5.1f, %5.1f)\n",
a[i].row, a[i].col, a[i].val.re, a[i].val.im);
}
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.
#include <imsl.h>
#include <stdio.h>
int main()
{
int i, n = 5, c = 3, nz;
Imsl_c_sparse_elem *a;
a = imsl_c_generate_test_coordinate (n, c, &nz,
IMSL_SYMMETRIC_STORAGE,
0);
printf ("row col val\n");
for (i=0; i<nz; i++)
printf (" %d %d (%5.1f, %5.1f)\n",
a[i].row, a[i].col, a[i].val.re, a[i].val.im);
}
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)