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(cstr
1,n
2,...,cstr
k)
or
expr
= optimexpr([n
1,n
2,...,n
k])
,
for any combination of positive integers expr
= optimexpr({cstr
1,cstr
2,...,cstr
k})n
j
and names cstr
j, creates an empty array of
optimization expressions with dimensions equal to the integers
n
j or the lengths of the entries of
cstr
j.
Examples
Input Arguments
Output Arguments
Tips
You can use
optimexpr
to create empty expressions that you fill programmatically, such as in afor
loop.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