A, B[, trans='N']) |
'N'
. If m is greater than or equal
to n, gels() solves the least-squares problem
'T'
or 'C'
and A and B
are real. If m is greater than or equal to n,
gels() solves the least-norm problem
'C'
and A and B
are complex. If m is greater than or equal to n,
gels() solves the least-norm problem
'd'
or 'z'
).
trans = 'T'
is not allowed if A is complex.
On exit, the solution X is stored as the leading submatrix
of B.
The array A is overwritten with details of the QR or the LQ
factorization of A.
Note that gels() does not check whether
A, tau) |
A, tau, C[, side='L'[, trans='N']]) |
A, tau, C[, side='L'[, trans='N']]) |
trans = 'T'
is only allowed if the typecode is 'd'
.
In the following example, we solve a least-squares problem by a direct call to gels(), and by separate calls to geqrf(), ormqr(), and trtrs().
>>> from cvxopt import random, blas, lapack >>> from cvxopt.base import matrix >>> m, n = 10, 5 >>> A, b = random.normal(m,n), random.normal(m,1) >>> x1 = +b >>> lapack.gels(+A, x1) # x1[:n] minimizes ||A*x1[:n] - b||_2 >>> tau = matrix(0.0, (n,1)) >>> lapack.geqrf(A, tau) # A = [Q1, Q2] * [R1; 0] >>> x2 = +b >>> lapack.ormqr(A, tau, x2, trans='T') # x2 := [Q1, Q2]' * b >>> lapack.trtrs(A[:n,:], x2, uplo='U') # x2[:n] := R1^{-1}*x2[:n] >>> blas.nrm2(x1[:n] - x2[:n]) 3.0050798580569307e-16