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(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.
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.