This function provides a multivariate version of function
lsei
from the limSolve
package. It solves the following optimisation problem for
each column b of B
mlsei(A, B, ..., fulloutput = FALSE, verbose = TRUE)
||Ax-B||^2
;
if the columns of A
have a names attribute, they
will be used to label the output.TRUE
, also returns the
covariance matrix of the solution and the rank of the
equality constraints -- only used if type = 1
(see
lsei
).lsei
.If fulloutput=TRUE
, a list whose elements are the
results returned by lsei
on each column of
B
, otherwise a list with the following elements:
Xa matrix of dimension ncol(B) x ncol(A)
that contain the estimated solution of the least-square
problem. IsErrora logical that indicates if an
error occured typethe string "lsei", such that
how the solution was obtained can be traced
solutionNorma vector, whose elements are the sum
of absolute values of residuals of equalities and
violated inequalities, as computed for each column of
B
. solutionNorma vector, whose elements
are the values of the minimised quadratic function at the
solution, i.e. the value of ||Ax-b||^2, as computed for
each column of B
.
min ||Ax - b||^2subject to the equality constraints: E x = f
and/or inequality constraints: G x >= h
It applies
lsei
on each column of a right-hand side matrix, and automatically transpose the input and result matrices back and forth if needed.
# random left-hand quadratic coefficients
A <- rmatrix(20, 3)
r <- ncol(A)
# random right-hand target matrix
B <- rmatrix(20, 10)
# constrained least-squares: nonnegative and sum up to one
res <- mlsei(A,B, E=matrix(1, 1, r), F=1, G=diag(1, r), H=rep(0,r))