optimexpr
Create empty optimization expression array
Syntax
Description
Use optimexpr to initialize a set of optimization
expressions.
Tip
For the full workflow, see Problem-Based Optimization Workflow or Problem-Based Workflow for Solving Equations.
creates an empty expr = optimexpr(n)n-by-1 OptimizationExpression array. Use expr as the
initial value in a loop that creates optimization expressions.
or
expr = optimexpr(cstr1,n2,...,cstrk)or
expr = optimexpr([n1,n2,...,nk]),
for any combination of positive integers expr = optimexpr({cstr1,cstr2,...,cstrk})nj
and names cstrj, creates an empty array of
optimization expressions with dimensions equal to the integers
nj or the lengths of the entries of
cstrj.
Examples
Input Arguments
Output Arguments
Tips
You can use
optimexprto create empty expressions that you fill programmatically, such as in aforloop.x = optimvar('x',8); expr = optimexpr(4) for k = 1:4 expr(k) = 5*k*(x(2*k) - x(2*k-1)); end
It is generally more efficient to create expressions by vectorized statements rather than loops. See Create Efficient Optimization Problems.
Version History
Introduced in R2017b