Create Multidimensional Optimization Expressions
Create a 3-by-4-by-2 array of optimization expressions.
expr = optimexpr(3,4,2)
expr = 3×4×2 OptimizationExpression array with properties: IndexNames: {{} {} {}} See expression formulation with showexpr.
Create a 3-by-4 array of optimization expressions where the first dimension is indexed by the strings "brass","stainless", and "galvanized", and the second dimension is numerically indexed.
bnames = ["brass","stainless","galvanized"]; expr = optimexpr(bnames,4)
expr = 3×4 OptimizationExpression array with properties: IndexNames: {{1×3 cell} {}} See expression formulation with showexpr.
Create an expression using a named index indicating that each stainless expression is 1.5 times the corresponding x(galvanized) value.
x = optimvar('x',bnames,4); expr('stainless',:) = x('galvanized',:)*1.5; showexpr(expr('stainless',:))
('stainless', 1) 1.5*x('galvanized', 1) ('stainless', 2) 1.5*x('galvanized', 2) ('stainless', 3) 1.5*x('galvanized', 3) ('stainless', 4) 1.5*x('galvanized', 4)