linSolPosdefCoordinate

Solves a sparse real symmetric positive definite system of linear equations \(A = b\). Using optional arguments, any of several related computations can be performed. These extra tasks include returning the symbolic factorization of A, returning the numeric factorization of A, and computing the solution of \(Ax = b\) given either the symbolic or numeric factorizations.

Synopsis

linSolPosdefCoordinate (a, b)

Required Arguments

a[[]] (Input)
Vector of length nz containing the location and value of each nonzero entry in the lower triangle of the matrix.
float b (Input)
Vector of length n containing the right-hand side.

Return Value

The solution x of the sparse symmetric positive definite linear system \(Ax = b\). If no solution was computed, then None is returned.

Optional Arguments

returnSymbolicFactor, (Output)
A structure containing, on return, the symbolic factorization of the input matrix.
supplySymbolicFactor, structure (Input)
A structure. This structure contains the symbolic factorization of the input matrix computed by linSolPosdefCoordinate with the returnSymbolicFactor option.
symbolicFactorOnly,
Compute the symbolic factorization of the input matrix and return. The argument b is ignored.
returnNumericFactor (Output)
A structure containing, on return, the numeric factorization of the input matrix.
supplyNumericFactor, structure (Input)
A structure. This structure contains the numeric factorization of the input matrix computed by linSolPosdefCoordinate with the returnNumericFactor option.
numericFactorOnly,
Compute the numeric factorization of the input matrix and return. The argument b is ignored.
solveOnly,
Solve \(Ax = b\) given the numeric or symbolic factorization of A. This option requires the use of either supplyNumericFactor or supplySymbolicFactor.
multifrontalFactorization,
Perform the numeric factorization using a multifrontal technique. By default, a standard factorization is computed based on a sparse compressed storage scheme.
smallestDiagonalElement (Output)
A scalar containing the smallest diagonal element that occurred during the numeric factorization. This option is valid only if the numeric factorization is computed during this call to linSolPosdefCoordinate.
largestDiagonalElement (Output)
A scalar containing the largest diagonal element that occurred during the numeric factorization. This option is valid only if the numeric factorization is computed during this call to linSolPosdefCoordinate.
numNonzerosInFactor (Output)
A scalar containing the total number of nonzeros in the factor.
cscFormat, int colPtr, int rowInd, float values (Input)
Accept the coefficient matrix in Compressed Sparse Column (CSC) Format. See the “Matrix Storage Modes” section of the “Introduction” at the beginning of this manual for a discussion of this storage scheme.

Description

The function linSolPosdefCoordinate solves a system of linear algebraic equations having a sparse symmetric positive definite coefficient matrix A. In this function’s default usage, a symbolic factorization of a permutation of the coefficient matrix is computed first. Then a numerical factorization is performed. The solution of the linear system is then found using the numeric factor.

The symbolic factorization step of the computation consists of determining a minimum degree ordering and then setting up a sparse data structure for the Cholesky factor, L. This step only requires the “pattern” of the sparse coefficient matrix, i.e., the locations of the nonzeros elements but not any of the elements themselves. Thus, the value field in the sparse element array is ignored. If an application generates different sparse symmetric positive definite coefficient matrices that all have the same sparsity pattern, then by using returnSymbolicFactor and supplySymbolicFactor, the symbolic factorization need only be computed once.

Given the sparse data structure for the Cholesky factor L, as supplied by the symbolic factor, the numeric factorization produces the entries in L so that

\[PAP^T = LL^T\]

Here P is the permutation matrix determined by the minimum degree ordering.

The numerical factorization can be carried out in one of two ways. By default, the standard factorization is performed based on a sparse compressed storage scheme. This is fully described in George and Liu (1981). Optionally, a multifrontal technique can be used. The multifrontal method requires more storage but will be faster in certain cases. The multifrontal factorization is based on the routines in Liu (1987). For a detailed description of this method, see Liu (1990), also Duff and Reid (1983, 1984), Ashcraft (1987), Ashcraft et al. (1987), and Liu (1986, 1989).

If an application requires that several linear systems be solved where the coefficient matrix is the same but the right-hand sides change, the options returnNumericFactor and supplyNumericFactor can be used to precompute the Cholesky factor. Then the solveOnly option can be used to efficiently solve all subsequent systems.

Given the numeric factorization, the solution x is obtained by the following calculations:

\[Ly_1 = Pb\]
\[L^Ty_2 = y_1\]
\[x = P^Ty_2\]

The permutation information, P, is carried in the numeric factor structure.

Examples

Example 1

As an example consider the 5 × 5 coefficient matrix:

\[\begin{split}a = \begin{bmatrix} 10 & 0 & 1 & 0 & 2 \\ 0 & 20 & 0 & 0 & 3 \\ 1 & 0 & 30 & 4 & 0 \\ 0 & 0 & 4 & 40 & 5 \\ 2 & 3 & 0 & 5 & 50 \\ \end{bmatrix}\end{split}\]

Let \(x^T = (5, 4, 3, 2, 1)\) so that \(Ax = (55, 83, 103, 97, 82)^T\). The number of nonzeros in the lower triangle of A is nz = 10. The sparse coordinate form for the lower triangle is given by the following:

row 0 1 2 2 3 3 4 4 4 4
col 0 1 0 2 2 3 0 1 3 4
val 10 20 1 30 4 40 2 3 5 50

Since this representation is not unique, an equivalent form would be as follows:

row 3 4 4 4 0 1 2 2 3 4
col 3 0 1 3 0 1 0 2 2 4
val 40 2 3 5 10 20 1 30 4 50
from numpy import *
from pyimsl.math.ctime import ctime
from pyimsl.math.generateTestCoordinate import generateTestCoordinate
from pyimsl.math.randomSeedSet import randomSeedSet
from pyimsl.math.randomUniform import randomUniform
from pyimsl.math.linSolPosdefCoordinate import linSolPosdefCoordinate
from pyimsl.math.writeMatrix import writeMatrix
from pyimsl.math.mathStructs import Imsl_d_sparse_elem

a = [[0, 0, 10.0],
     [1, 1, 20.0],
     [2, 0, 1.0],
     [2, 2, 30.0],
     [3, 2, 4.0],
     [3, 3, 40.0],
     [4, 0, 2.0],
     [4, 1, 3.0],
     [4, 3, 5.0],
     [4, 4, 50.0]]
b = [55.0, 83.0, 103.0, 97.0, 82.0]
x = linSolPosdefCoordinate(a, b)
writeMatrix("solution", x, column=True)

Output

 
   solution
1            5
2            4
3            3
4            2
5            1

Example 2

In this example, set \(A = E(2500, 50)\). Then solve the system \(Ax = b_l\) and return the numeric factorization resulting from that call. Then solve the system \(Ax = b_2\) using the numeric factorization just computed. The ratio of execution time is printed. Be aware that timing results are highly machine dependent.

from __future__ import print_function
from numpy import *
from pyimsl.math.ctime import ctime
from pyimsl.math.generateTestCoordinate import generateTestCoordinate
from pyimsl.math.randomSeedSet import randomSeedSet
from pyimsl.math.randomUniform import randomUniform
from pyimsl.math.linSolPosdefCoordinate import linSolPosdefCoordinate

ic = 50
n = ic * ic
# Generate two right hand sides
seed = 123457
randomSeedSet(seed)
b_1 = randomUniform(n)
randomSeedSet(seed)
b_2 = randomUniform(n)

# Build coefficient matrix a
a = generateTestCoordinate(n, ic, symmetricStorage=True)

# Now solve Ax_1 = b_1 and return the numeric factorization
time_1 = ctime()
numeric_factor = []
x_1 = linSolPosdefCoordinate(a, b_1,
                             returnNumericFactor=numeric_factor)
time_1 = ctime() - time_1

# Now solve Ax_2 = b_2 given the numeric factorization
time_2 = ctime()
x_2 = linSolPosdefCoordinate(a, b_2,
                             supplyNumericFactor=numeric_factor[0],
                             solveOnly=True)
time_2 = ctime() - time_2

try:
    ratio = time_2 / time_1
except ZeroDivisionError:
    ratio = 1.0
print("time_2/time_1 = %lf\n" % ratio)

Output

time_2/time_1 = 0.594520