主要内容

OptimizationVariable

为优化变量

描述

一个OptimizationVariable对象包含用于优化表达式的变量。使用表达式来表示目标函数、约束条件或方程。变量本质上是符号的,可以是任意大小的数组。

创建

创建一个OptimizationVariable对象使用optimvar

属性

全部展开

Array-Wide属性

此属性是只读的。

变量名,指定为字符串或字符向量。

的名字给出要显示的变量标签,如in显示的名字还给出了解决方案结构中的字段名解决的回报。

提示

为了避免混淆,设置的名字就是MATLAB®变量的名字。例如,

金属= optimvar (“金属”

数据类型:字符|字符串

变量类型,指定为“连续”“整数”

  • “连续”——真正的值

  • “整数”——整数值

变量类型适用于数组中的所有变量。要有多个变量类型,请创建多个变量。

提示

要指定二进制变量,请使用“整数”类型和指定下界0UpperBound1

数据类型:字符|字符串

索引名称,指定为字符串或字符向量的单元格数组。有关使用索引名的信息,请参见为优化变量命名的索引

数据类型:细胞

Element-wise属性

的下界,指定为实标量或具有相同维数的实数组OptimizationVariable对象。标量值适用于变量的所有元素。

下界属性始终显示为数组。但是,您可以将该属性设置为应用于所有元素的标量。例如,

var.LowerBound = 0

数据类型:

的上限值,指定为实标量或具有相同维数的实数组OptimizationVariable对象。标量值适用于变量的所有元素。

UpperBound属性始终显示为数组。但是,您可以将该属性设置为应用于所有元素的标量。例如

var.UpperBound = 1

数据类型:

对象的功能

显示 显示优化对象信息
showbounds 显示变量范围
保存优化对象描述
writebounds 保存变量边界的描述

例子

全部折叠

创建标量优化变量美元

美元= optimvar (“美元”
$ = OptimizationVariable with properties: Name: 'dollars' Type: 'continuous' IndexNames: {{} {}} LowerBound: -Inf UpperBound: Inf参见variables with show。见bounds with showbounds。

创建一个名为的3乘1优化变量向量x

x = optimvar (“x”3)
x = 3x1 OptimizationVariable array with properties: array wide properties: Name: 'x' Type: 'continuous' IndexNames: {{} {}} Elementwise properties: LowerBound: [3x1 double] UpperBound: [3x1 double]参见variables with show。见bounds with showbounds。

创建一个整数优化变量向量螺栓由字符串索引“铜”“不锈钢”,“镀锌”.使用螺栓创建一个优化表达式,并进行创建实验螺栓使用字符数组或在不同的方向。

创建螺栓在行方向上使用字符串。

bnames = [“铜”“不锈钢”“镀锌”];螺栓= optimvar (螺栓的bnames,“类型”“整数”
bytes = 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]参见variables with show. properties: {{} {1x3 cell}}见bounds with showbounds。

使用字符串索引创建优化表达式。

y =螺栓(“铜”) + 2 *螺栓(“不锈钢”) + 4 *螺栓(“镀锌”
y = Linear OptimizationExpression螺栓('黄铜')+ 2*螺栓('不锈钢')+ 4*螺栓('镀锌')

使用字符向量的单元格数组而不是字符串来获得与以前相同的下标的变量。

bnames = {“铜”“不锈钢”镀锌的};螺栓= optimvar (螺栓的bnames,“类型”“整数”
bytes = 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]参见variables with show. properties: {{} {1x3 cell}}见bounds with showbounds。

使用的面向列版本bnames3 × 1而不是1 × 3,观察一下螺栓也有这样的取向。

bnames = [“铜”“不锈钢”“镀锌”];螺栓= optimvar (螺栓的bnames,“类型”“整数”
bolt = 3x1 OptimizationVariable array with properties: array wide properties: Name: 'bolts' Type: 'integer' IndexNames: {{1x3 cell} {}} Elementwise properties: LowerBound: [3x1 double] UpperBound: [3x1 double]参见variables with show。见bounds with showbounds。

创建一个3 × 4 × 2的优化变量数组xarray

xarray = optimvar (“xarray”、3、4、2)
xarray = 3x4x2 OptimizationVariable array with properties: array wide properties: Name: 'xarray' Type: 'continuous' IndexNames: {{} {}} Elementwise properties: LowerBound: [3x4x2 double] UpperBound: [3x4x2 double]参见variables with show。见bounds with showbounds。

还可以创建由名称和数字索引混合索引的多维变量。例如,创建一个3乘4的优化变量数组,其中第一个维度由字符串索引“铜”“不锈钢”,镀锌的,第2维是数字索引。

bnames = [“铜”“不锈钢”“镀锌”];螺栓= optimvar (螺栓的bnames 4)
bolt = 3x4 OptimizationVariable array with properties: array wide properties: Name: 'bolts' Type: 'continuous' IndexNames: {{1x3 cell} {}} Elementwise properties: LowerBound: [3x4 double] UpperBound: [3x4 double]参见variables with show。见bounds with showbounds。

创建一个优化变量x大小为3 × 3 × 3,表示二进制变量。

x = optimvar (“x”3, 3, 3,“类型”“整数”下界的,0,“UpperBound”, 1)
x = 3x3x3 OptimizationVariable array with properties: array wide properties: Name: 'x' Type: 'integer' IndexNames: {{} {}} Elementwise properties: LowerBound: [3x3x3 double] UpperBound: [3x3x3 double]参见variables with show。见bounds with showbounds。

更多关于

全部展开

提示

  • OptimizationVariable对象有处理复制行为。看到处理对象的行为句柄类和值类的比较.处理复制行为意味着OptimizationVariable指的是原始而不是独立存在的。例如,创建一个变量x,复制到y,则设置属性为y.请注意,x采用新的属性值。

    x = optimvar (“x”下界的1);y = x;y.LowerBound = 0;showbounds (x)
    0 < = x
介绍了R2017b