IMSL C Math Library
generate_test_coordinate
Generates test matrices of class D(nc) and E(nc). Returns in either coordinate format.
Synopsis
#include <imsl.h>
Imsl_f_sparse_elem *imsl_f_generate_test_coordinate (int n, int c, int *nz, ..., 0)
The function imsl_d_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_f_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_f_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(nc).
Default: Return a matrix of class E(nc).
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
We use the same nomenclature as Østerby and Zlatev (1982).Test matrices of class E(nc), 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
ai,i = 4
0 i < n
ai,i+1 =  −1
0 i < n  − 1
ai+1,i =  −1
0 i < n  − 1
ai,i+c =  −1
0 i < n  − c
ai+c,i =  −1
0 i < n  − c
for any n 3 and 2 c n  − 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:
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-n+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.
We now show the sparsity pattern of D(20, 5)
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_f_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 nonzeros 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;
int n = 5;
int c = 3;
int nz;
Imsl_f_sparse_elem *a;
 
a = imsl_f_generate_test_coordinate (n, c, &nz,
0);
 
printf ("row col val\n");
for (i=0; i<nz; i++)
printf (" %d %d %5.1f\n",
a[i].row, a[i].col, a[i].val);
}
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.
 
#include <imsl.h>
#include <stdio.h>
 
int main()
{
int i;
int n = 5;
int c = 3;
int nz;
Imsl_f_sparse_elem *a;
 
a = imsl_f_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\n",
a[i].row, a[i].col, a[i].val);
}
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