Constraint syntax of a matrix variable in optimization
3 views (last 30 days)
Show older comments
Suppose that a function is has a vector input martri x. And x is of the form:
x(:,1)
x(:,2)
x(:,3)
how should the linear constraints be written?
A(1,:,1)=...
b(1,1)=...
My question extends also for the syntax of the nonlinear equations in the case of an matrix variable. Can the optimization functions receive matrices as inputs?
0 Comments
Answers (3)
Alan Weiss
on 28 Jan 2013
Perhaps a sneak peek at some yet-to-be-released documentation will make things clearer:
-----------------
Matrix Arguments
Nonlinear solvers accept matrix initial point x0. They also accept matrix bounds lb and ub. Here's how solvers handle matrix arguments.
Internally, solvers convert matrix arguments into vectors before processing. For example, x0 becomes x0(:). For an explanation of this syntax, see the A(:) entry in colon.
For output, solvers reshape the solution x to the same size as the input x0.
When x0 is a matrix, solvers pass x as a matrix of the same size as x0 to both the objective function and to any nonlinear constraint function.
Linear constraints, though, take x in vector form, x(:). In other words, a linear constraint of the form
A*x ≤ b or Aeq*x = beq
takes x as a vector, not a matrix. Ensure that your matrix A or Aeq has the same number of columns as x0 has elements, or the solver will error.
-----------------
I hope this helps.
Alan Weiss
MATLAB mathematical toolbox documentation
0 Comments
Matt J
on 26 Jan 2013
Edited: Matt J
on 26 Jan 2013
I assume you're talking about FMINCON. The documentation leads me to believe that A and Aeq are meant to operate column-wise on x
A*x(:,i)<=b(:,i)
Aeq*x(:,i)=beq(:,i)
However, that seems very strange, because then the different columns of x cannote interact in the linear constraints. I would have hoped that the linear constraints always internally unfold x into a vector, and so should be interpreted
A*x(:)<=b
Aeq*x(:)=beq
but there's nothing in the documentation to suggest that.
Since I'm sure it's one of the two, an easy way to check is just to test both cases, i.e., write a small problem in which A is M x N and see which of
N=numel(x)
or
N=numel(x(:,1))
throws an error.
2 Comments
Teja Muppirala
on 27 Jan 2013
When FMINCON receives matrices for x or the inequality constraints, it implements them in the following way:
A*x(:) <= b(:)
Aeq*x(:) = beq(:)
This implies size(A,2) = numel(x), and size(A,1) = numel(b)
If the sizes are inconsistent, it will result in an error.
Matt J
on 27 Jan 2013
Is this in the documentation somewhere? I couldn't find it. Also, is it true for all the Optimization Toolbox solvers that work with linear constraints? The documentation for QUADPROG doesn't even mention that x can be a matrix.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!