7.2 General Linear Equations (cvxopt.umfpack)
See also:
- UMFPACK code, documentation, copyright and license.
- T. A. Davis, Algorithm 832: UMFPACK - an unsymmetric-pattern multifrontal method with a column pre-ordering strategy, ACM Transactions on Mathematical Software, 30(2), 196-199, 2004.
linsolve(A, B[, trans='N'])
- Solves a sparse set of linear equations
where A is a sparse matrix and B is a dense matrix of the same type ('d' or 'z') as A. On exit B contains the solution. Raises an ArithmeticError exception if the coefficient matrix is singular.
>>> from cvxopt.base import spmatrix, matrixThe function umfpack.linsolve() is equivalent to the following three functions called in sequence.
>>> from cvxopt import umfpack
>>> V = [2,3, 3,-1,4, 4,-3,1,2, 2, 6,1]
>>> I = [0,1, 0, 2,4, 1, 2,3,4, 2, 1,4]
>>> J = [0,0, 1, 1,1, 2, 2,2,2, 3, 4,4]
>>> A = spmatrix(V,I,J)
>>> B = matrix(1.0, (5,1))
>>> umfpack.linsolve(A,B)
>>> print B
[ 5.79e-01]
[-5.26e-02]
[ 1.00e+00]
[ 1.97e+00]
[-7.89e-01]
symbolic(A)
- Reorders the columns of A to reduce fill-in and performs a symbolic LU factorization. A is a sparse, possibly rectangular, matrix. Returns the symbolic factorization as an opaque C object that can be passed on to umfpack.numeric().
numeric(A, F)
- Performs a numeric LU factorization of a sparse, possibly rectangular, matrix A. The argument F is the symbolic factorization computed by umfpack.symbolic() applied to the matrix A, or another sparse matrix with the same sparsity pattern, dimensions, and type. The numeric factorization is returned as an opaque C object that that can be passed on to umfpack.solve(). Raises an ArithmeticError if the matrix is singular.
solve(A, F, B[, trans='N'])
- Solves a set of linear equations
where A is a sparse matrix and B is a dense matrix of the same type as A. The argument F is a numeric factorization computed by umfpack.numeric(). On exit B is overwritten by the solution.
As an example, suppose A is the matrix (7.1) and
which differs from A in its first and last entries. The following code computes
>>> from cvxopt.base import spmatrix, matrix
>>> from cvxopt import umfpack
>>> VA = [2,3, 3,-1,4, 4,-3,1,2, 2, 6,1]
>>> VB = [4,3, 3,-1,4, 4,-3,1,2, 2, 6,2]
>>> I = [0,1, 0, 2,4, 1, 2,3,4, 2, 1,4]
>>> J = [0,0, 1, 1,1, 2, 2,2,2, 3, 4,4]
>>> A = spmatrix(VA, I, J)
>>> B = spmatrix(VB, I, J)
>>> x = matrix(1.0, (5,1))
>>> Fs = umfpack.symbolic(A)
>>> FA = umfpack.numeric(A, Fs)
>>> FB = umfpack.numeric(B, Fs)
>>> umfpack.solve(A, FA, x)
>>> umfpack.solve(B, FB, x)
>>> umfpack.solve(A, FA, x, trans='T')
>>> print x
[ 5.81e-01]
[-2.37e-01]
[ 1.63e+00]
[ 8.07e+00]
[-1.31e-01]
![\begin{displaymath}
A = \left[\begin{array}{rrrrr}
2 & 3 & 0 & 0 & 0 \\
3 & 0...
...0 & 0 & 1 & 0 & 0 \\
0 & 4 & 2 & 0 & 1
\end{array}\right].
\end{displaymath}](img84.gif)