Matrix Arguments
Optimization Toolbox™ solvers accept vectors for many arguments, such as the initial point
x0, lower bounds lb, and upper bounds
ub. They also accept matrices for these arguments, where matrix
means an array of any size. When your solver arguments are naturally arrays, not
vectors, feel free to provide the arguments as arrays.
Here is how solvers handle matrix arguments.
Internally, solvers convert matrix arguments into vectors before processing. For example,
x0becomesx0(:). For an explanation of this syntax, see theA(:)entry incolon, or the "Indexing with a Single Index" section of Array Indexing.For output, solvers reshape the solution
xto the same size as the inputx0.When
x0is a matrix, solvers passxas a matrix of the same size asx0to both the objective function and to any nonlinear constraint function.Linear Constraints, though, take
xin vector form,x(:). In other words, a linear constraint of the formA*x ≤ borAeq*x = beqtakes
xas a vector, not a matrix. Ensure that your matrixAorAeqhas the same number of columns asx0has elements, or the solver will error.