gesv(A, B[, ipiv=None])
Solves
where A and B are real or complex matrices, with A square and nonsingular. On exit, B is replaced by the solution. The arguments A and B must have the same type (’d’ or ’z’). The optional argument ipiv is an integer matrix of length at least n. If ipiv is provided, then gesv() solves the system, replaces A with its triangular factors, and returns the permutation matrix in ipiv. If ipiv is not specified, then gesv() solves the system but does not return the LU factorization and does not modify A. For example,
>>> gesv(A, B)
|
solves the system without modifying A and returns the solution in B.
>>> gesv(A, B, ipiv)
|
returns the solution in B and also returns the details of the LU factorization in A and ipiv.
Raises an ArithmeticError if the matrix is singular.
getrf(A, ipiv)
LU factorization of a general, possibly rectangular, real or complex matrix,
where A is m by n. The argument ipiv is an integer matrix of length at least min{m,n}. On exit, the lower triangular part of A is replaced by L, the upper triangular part by U, and the permutation matrix is returned in ipiv. Raises an ArithmeticError if the matrix is not full rank.
getrs(A, ipiv, B[, trans=’N’])
Solves a general set of linear equations
given the LU factorization computed by gesv() or getrf(). On entry, A and ipiv must contain the factorization as computed by gesv() or getrf(). On exit, B is overwritten with the solution. B must have the same type as A.
getri(A, ipiv)
Computes the inverse of a matrix. On entry, A and ipiv must contain the factorization as computed by gesv() or getrf(). On exit, A contains the inverse.
In the following example we compute
for randomly generated problem data, factoring the coefficient matrix once.
>>> from cvxopt.base import matrix, normal
>>> from cvxopt.lapack import gesv, getrs >>> n = 10 >>> A = normal(n,n) >>> b = normal(n) >>> ipiv = matrix(0, (n,1)) >>> x = +b >>> gesv(A, x, ipiv) # x = A^{-1}*b >>> x2 = +b >>> getrs(A, ipiv, x2, trans=’T’) # x2 = A^{-T}*b >>> x += x2 |
Separate functions are provided for equations with band matrices.
gbsv(A, kl, B[, ipiv=None])
Solves
where A and B are real or complex matrices, with A n by n and banded with kl subdiagonals. The arguments A and B must have the same type (’d’ or ’z’).
The optional argument ipiv is an integer matrix of length at least n. If ipiv is provided, then A must have 2kl + ku + 1 rows. On entry the diagonals of A are stored in rows kl + 1 to 2kl + ku + 1 of the A, using the BLAS format for general band matrices (see section 3.1). On exit, the factorization is returned in A and ipiv.
If ipiv is not provided, then A must have kl + ku + 1 rows. On entry the diagonals of A are stored in the rows of A, following the standard format for general band matrices. In this case, gbsv() does not modify A on exit and does not return the factorization.
On exit, B is replaced by the solution X. Raises an ArithmeticError if the matrix is singular.
gbtrf(A, m, kl, ipiv)
LU factorization of a general m by n real or complex band matrix with kl subdiagonals. The matrix is stored using the BLAS format for general band matrices (see section 3.1), by providing the diagonals (stored as rows of a ku + kl + 1 by n matrix), the number of rows m, and the number of subdiagonals kl. The argument ipiv is an integer matrix of length at least min{m,n}. On exit, A and ipiv contain the details of the factorization. Raises an ArithmeticError if the matrix is not full rank.
gbtrs(A, kl, ipiv, B[, trans=’N’])
Solves a set of linear equations
with A a general band matrix with kl subdiagonals, given the LU factorization computed by gbsv() or gbtrf(). On entry, A and ipiv must contain the factorization as computed by gbsv() or gbtrf(). On exit, B is overwritten with the solution. B must have the same type as A.
As an example, we solve a linear equation with
>>> from cvxopt.base import matrix
>>> from cvxopt.lapack import gbsv, gbtrf, gbtrs >>> n, kl, ku = 4, 2, 1 >>> A = matrix([[0., 1., 3., 6.], [2., 4., 7., 10.], [5., 8., 11., 0.], [9., 12., 0., 0.]]) >>> x = matrix(1.0, (4,1)) >>> gbsv(A, kl, x) >>> print x [ 7.14e-02] [ 4.64e-01] [-2.14e-01] [-1.07e-01] |
The code below illustrates how one can reuse the factorization returned by gbsv().
>>> Ac = matrix(0.0, (2*kl+ku+1,n))
>>> Ac[kl:,:] = A >>> ipiv = matrix(0, (n,1)) >>> x = matrix(1.0, (4,1)) >>> gbsv(Ac, kl, x, ipiv) # solves A*x = 1 >>> print x [ 7.14e-02] [ 4.64e-01] [-2.14e-01] [-1.07e-01] >>> x = matrix(1.0, (4,1)) >>> gbtrs(Ac, kl, ipiv, x, trans=’T’) # solve A^T*x = 1 >>> print x [ 7.14e-02] [ 2.38e-02] [ 1.43e-01] [-2.38e-02] |
An alternative method uses gbtrf() for the factorization.
>>> Ac[kl:,:] = A
>>> gbtrf(Ac, n, kl, ipiv) >>> x = matrix(1.0, (4,1)) >>> gbtrs(Ac, kl, ipiv, x) # solve A^T*x = 1 >>> print x [ 7.14e-02] [ 4.64e-01] [-2.14e-01] [-1.07e-01] >>> x = matrix(1.0, (4,1)) >>> gbtrs(Ac, kl, ipiv, x, trans=’T’) # solve A^T*x = 1 >>> print x [ 7.14e-02] [ 2.38e-02] [ 1.43e-01] [-2.38e-02] |
The following functions can be used for tridiagonal matrices. They use a simpler matrix format, that stores the diagonals in three separate vectors.
gtsv(dl, d, du, B))
Solves
where A is an n by n tridiagonal matrix, with subdiagonal stored as a matrix dl of length n - 1, diagonal stored as a matrix d of length n, and superdiagonal stored as a matrix du of length n - 1. The four arguments must have the same type (’d’ or ’z’). On exit dl, d, du are overwritten with the details of the LU factorization of A, and B is overwritten with the solution X. Raises an ArithmeticError if the matrix is singular.
gttrf(dl, d, du, du2, ipiv)
LU factorization of an n by n tridiagonal matrix with subdiagonal dl, diagonal d and superdiagonal du. dl, d and du must have the same type. du2 is a matrix of length n - 2, and of the same type as dl. ipiv is an ’i’ matrix of length n. On exit, the five arguments contain the details of the factorization. Raises an ArithmeticError if the matrix is singular.
pttrs(dl, d, du, du2, ipiv, B[, trans=’N’])
Solves a set of linear equations
where A is an n by n tridiagonal matrix. The arguments dl, d, du, du2 and ipiv contain the details of the LU factorization as returned by gttrf(). On exit, B is overwritten with the solution X. B must have the same type as dl.