optimvar
2024-04-29 04:09:46
创建一个名为 的整数优化变量向量,该向量按字符串 、 和 进行索引。使用 的索引创建一个优化表达式,并使用字符数组或以不同方向创建 进行试验。
使用字符串行向向量创建 。
bnames=["brass","stainless","galvanized"]; bolts=optimvar('bolts',bnames,'Type','integer')
bolts=1x3 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'integer' IndexNames: {{} {1x3 cell}} Elementwise properties: LowerBound: [-Inf -Inf -Inf] UpperBound: [Inf Inf Inf] See variables with show. See bounds with showbounds.
使用字符串索引创建一个优化表达式。
y=bolts("brass") + 2*bolts("stainless") + 4*bolts("galvanized")
y=Linear OptimizationExpression bolts('brass') + 2*bolts('stainless') + 4*bolts('galvanized')
使用字符向量元胞数组而不是字符串来获得与之前索引相同的变量。
bnames={'brass','stainless','galvanized'}; bolts=optimvar('bolts',bnames,'Type','integer')
bolts=1x3 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'integer' IndexNames: {{} {1x3 cell}} Elementwise properties: LowerBound: [-Inf -Inf -Inf] UpperBound: [Inf Inf Inf] See variables with show. See bounds with showbounds.
使用列向 (即 3×1 而不是 1×3),请注意, 也具有该方向。
bnames=["brass";"stainless";"galvanized"]; bolts=optimvar('bolts',bnames,'Type','integer')
bolts=3x1 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'integer' IndexNames: {{1x3 cell} {}} Elementwise properties: LowerBound: [3x1 double] UpperBound: [3x1 double] See variables with show. See bounds with showbounds.