Main Content

optimvar

Create optimization variables

Description

Useoptimvarto create optimization variables.

例子

X= optimvar(姓名creates a scalar optimization variable. An optimization variable is a symbolic object that enables you to create expressions for the objective function and the problem constraints in terms of the variable.

小费

为了避免混乱,请设置姓名to be the MATLAB®变量的名称。例如,

metal = optimvar('金属'

例子

X= optimvar(姓名,,,,n创建一个n-1优化变量的向量。

例子

X= optimvar(姓名,,,,CSTRcreates a vector of optimization variables that can useCSTRfor indexing. The number of elements ofXis the same as the length of theCSTR向量。方向Xis the same as the orientation ofCSTRXis a row vector whenCSTRis a row vector, andX是一个列向量时CSTR是列矢量。

例子

X= optimvar(姓名,,,,CSTR1,n2,,,,。。。,,,,CSTRk)orX= optimvar(姓名,,,,{CSTR1,CSTR2,,,,。。。,,,,CSTRK})orX= optimvar(姓名,,,,[n1,n2,,,,。。。,,,,nk]),对于积极整数的任何组合nJ和名字CSTRk,创建一系列优化变量,其尺寸等于整数nj and the lengths of the entriesCSTR1k。

例子

X= optimvar(___,,,,名称,价值,对于任何以前的语法,使用一个或多个指定的其他选项名称,价值配对参数。例如,要指定整数变量,请使用x = optimvar('x','type','integer')

Examples

collapse all

Create a scalar optimization variable named美元

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

Create a 3-by-1 optimization variable vector namedX

x = optimvar('X',,,,3)
x = 3x1优化视差带有属性:阵列整个属性:名称:'x'type:'连续'indexNames:{{} {} {}} elementwise properties:lowerbound:[3x1 double] upperbound:[3x1 double bound:[3x1 double]参见带有show的变量,请参见变量。看到与展示的边界。

创建一个命名的整数优化变量向量bolts这是由琴弦索引的“黄铜”,,,,"stainless",,,,and"galvanized"。使用指数boltsto create an optimization expression, and experiment with creatingbolts使用字符阵列或不同方向。

Createbolts在行定向中使用字符串。

bnames = [“黄铜”,,,,"stainless",,,,"galvanized"]; bolts = optimvar(“螺栓”,bnames,'类型',,,,'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.

Create an optimization expression using the string indices.

y =螺栓(“黄铜”) + 2*螺栓("stainless")+ 4*bolts("galvanized"
y= Linear OptimizationExpression bolts('brass') + 2*bolts('stainless') + 4*bolts('galvanized')

Use a cell array of character vectors instead of strings to get a variable with the same indices as before.

bnames = {'黄铜',,,,'stainless',,,,“镀锌”}; bolts = optimvar(“螺栓”,bnames,'类型',,,,'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.

使用面向列的版本的bnames,,,,3-by-1 instead of 1-by-3, and observe thatboltshas that orientation as well.

bnames = [“黄铜”;"stainless";"galvanized"]; bolts = optimvar(“螺栓”,bnames,'类型',,,,'integer'
螺栓= 3x1优化视差属性:阵列范围属性:名称:'螺栓'类型:'integer'indexNames:{{1x3 cell}}}}}}} elementwise properties:lowerbound:lowerbound:[3x1 double] touble bound Boundbound:[3x1 double]请参见变量:[3x1 double]与表演。看到与展示的边界。

Create a 3-by-4-by-2 array of optimization variables namedXarray

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] See variables with show. See bounds with showbounds.

您还可以创建由名称和数字索引的混合物索引的多维变量。例如,创建一个3 x-4数组的优化变量,其中第一维由字符串索引'黄铜',,,,'stainless',,,,and“镀锌”,第二维是数值索引的。

bnames = [“黄铜”,,,,"stainless",,,,"galvanized"]; bolts = optimvar(“螺栓”,bnames,4)
bolts = 3x4 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'continuous' IndexNames: {{1x3 cell} {}} Elementwise properties: LowerBound: [3x4 double] UpperBound: [3x4 double] See variables with show. See bounds with showbounds.

创建一个优化变量命名X代表二进制变量的3乘3 x-3尺寸。

x = optimvar('X',3,3,3,'类型',,,,'integer',,,,“下界”0,“上行”,,,,1)
X= 3x3x3 OptimizationVariable array with properties: Array-wide properties: Name: 'x' Type: 'integer' IndexNames: {{} {} {}} Elementwise properties: LowerBound: [3x3x3 double] UpperBound: [3x3x3 double] See variables with show. See bounds with showbounds.

输入参数

collapse all

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

小费

To avoid confusion about which name relates to which aspect of a variable, set the workspace variable name to the variable name. For example,

truck = optimvar('卡车');

Example:"Warehouse"

Example:'卡车'

数据类型:char|细绳

Variable dimension, specified as a positive integer.

Example:4

数据类型:

索引名称,,,,specified as a string array or a cell array of character arrays.

Example:x = optimvar('x',[“仓库”,“卡车”,“城市”])

Example:x = optimvar('X',,,,{'Warehouse','Truck','City'})

数据类型:细绳|cell

名称值参数

Specify optional pairs of arguments asname1 = value1,...,namen = valuen, 在哪里姓名是参数名称和Valueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

Example:CreateX作为一个3元素的非负矢量x(2)<= 2andx(3)<= 4通过命令x = optimvar('x',3,'lowerbound',0,'upperbound',[inf,2,4])

可变类型,指定为'连续的'or'integer'

  • '连续的'- 实际价值观

  • 'integer'- 整数值

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

小费

要指定二进制变量,请使用'integer'LowerBound等于0and上行等于1

Example:'integer'

下界,指定为与相同大小的数组X或作为真正的标量。如果LowerBoundis a scalar, the value applies to all elements ofX

Example:设置一个下限0到所有要素X,指定标量值0

数据类型:

Upper bounds, specified as an array of the same size asX或作为真正的标量。如果上行is a scalar, the value applies to all elements ofX

Example:设置上层2到所有要素X,指定标量值2

数据类型:

输出参数

collapse all

优化变量,返回为优化视价array. The dimensions of the array are the same as those of the corresponding input variables, such asCSTR1-by-CSTR2

小费s

  • 优化视价objects havehandle复制行为。看Handle Object Behaviorand手柄和价值类的比较。Handle copy behavior means that a copy of an优化视价指向原始,没有独立的存在。例如,创建一个变量X,将其复制到y,然后设置一个属性y。Note thatXtakes on the new property value.

    x = optimvar('X',,,,“下界”,1);y = x;y.lower -bound = 0;展示(x)
    0 <= x

版本历史记录

在R2017b中引入