Create empty optimization expression array
expr = optimexpr(n)
expr = optimexpr(cstr)
expr = optimexpr(cstr1,n2,...,cstrk)
expr = optimexpr([n1,n2,...,nk])
expr = optimexpr({cstr1,cstr2,...,cstrk})
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.
You can use optimexpr
to create empty expressions that you
fill programmatically, such as in a for
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.