optimvar
Create optimization variables
Syntax
Description
Use optimvar to create optimization
variables.
Tip
For the full workflow, see Problem-Based Optimization Workflow or Problem-Based Workflow for Solving Equations.
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.x = optimvar(name)
Tip
To avoid confusion, set name to be the MATLAB® variable name. For example,
metal = optimvar("metal")
creates a vector of optimization variables that can use x = optimvar(name,cstr)cstr
for indexing. The number of elements of x is the same as the
length of the cstr vector. The orientation of
x is the same as the orientation of
cstr: x is a row vector when
cstr is a row vector, and x is a
column vector when cstr is a column vector.
or
x = optimvar(name,cstr1,n2,...,cstrk)
or
x = optimvar(name,{cstr1,cstr2,...,cstrk}),
for any combination of positive integers x = optimvar(name,[n1,n2,...,nk])nj and names
cstrk, creates an array of optimization variables with
dimensions equal to the integers nj and the lengths of the
entries cstr1k.
,
for any previous syntax, uses additional options specified by one or more
x = optimvar(___,Name,Value)Name,Value pair arguments. For example, to specify an
integer variable, use x =
optimvar("x",Type="integer").
Examples
Input Arguments
Name-Value Arguments
Output Arguments
More About
Tips
OptimizationVariableobjects have handle copy behavior. See Handle Object Behavior and Comparison of Handle and Value Classes. Handle copy behavior means that a copy of anOptimizationVariablepoints to the original and does not have an independent existence. For example, create a variablex, copy it toy, then set a property ofy. Note thatxtakes on the new property value.x = optimvar('x','LowerBound',1); y = x; y.LowerBound = 0; showbounds(x)
0 <= x